mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-21 03:58:04 +00:00
feat: add new indicators (Decay, Edecay, MinusDi, MinusDm, PlusDi, PlusDm, Maxindex, Minindex, Sarext) and update pine scripts, core libs, validation tests, and python bindings
This commit is contained in:
@@ -322,6 +322,33 @@ public class DwtValidationTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Dwt_Correction_Recomputes()
|
||||
{
|
||||
var ind = new Dwt(levels: 4);
|
||||
var t0 = DateTime.MinValue;
|
||||
|
||||
// Build state well past warmup (WarmupPeriod = 2^4 = 16)
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
ind.Update(new TValue(t0.AddSeconds(i), 100.0 + i * 0.5));
|
||||
}
|
||||
|
||||
// Anchor bar
|
||||
var anchorTime = t0.AddSeconds(50);
|
||||
const double anchorPrice = 125.0;
|
||||
ind.Update(new TValue(anchorTime, anchorPrice), isNew: true);
|
||||
double anchorResult = ind.Last.Value;
|
||||
|
||||
// Correction with dramatically different value — DWT uses anchor at lag 0
|
||||
ind.Update(new TValue(anchorTime, anchorPrice * 10), isNew: false);
|
||||
Assert.NotEqual(anchorResult, ind.Last.Value);
|
||||
|
||||
// Correction back to original — must exactly restore
|
||||
ind.Update(new TValue(anchorTime, anchorPrice), isNew: false);
|
||||
Assert.Equal(anchorResult, ind.Last.Value, 1e-9);
|
||||
}
|
||||
|
||||
// ─── Helper ──────────────────────────────────────────────────────────────
|
||||
|
||||
private static double Variance(List<double> vals)
|
||||
|
||||
@@ -313,6 +313,14 @@ public sealed class Dwt : AbstractBase
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Primes the indicator with historical values.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Synthetic timestamps are generated by subtracting <c>step × source.Length</c>
|
||||
/// from <see cref="DateTime.UtcNow"/>. For deterministic or replay-safe pipelines
|
||||
/// use <see cref="Update(TValue, bool)"/> directly with explicit timestamps.
|
||||
/// </remarks>
|
||||
public override void Prime(ReadOnlySpan<double> source, TimeSpan? step = null)
|
||||
{
|
||||
TimeSpan interval = step ?? TimeSpan.FromSeconds(1);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// The MIT License (MIT)
|
||||
// Licensed under the Apache License, Version 2.0
|
||||
// © mihakralj
|
||||
//@version=6
|
||||
indicator("Discrete Wavelet Transform (DWT)", "DWT", overlay=false, precision=6)
|
||||
|
||||
Reference in New Issue
Block a user