Skip to content

Commit

Permalink
feat: Dpo, Tsi, Vortex, Bpp, Cci, Cfo, Tr, Ui, Vc, Vov, Vr, Vs, Mfi, …
Browse files Browse the repository at this point in the history
…Nvi, Obv, Pvi, Pvo, Pvol, Pvr, Pvt, Tvi
  • Loading branch information
mihakralj committed Oct 30, 2024
1 parent 06c6875 commit 6231bab
Show file tree
Hide file tree
Showing 34 changed files with 3,151 additions and 254 deletions.
46 changes: 46 additions & 0 deletions Tests/test_updates_momentum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,21 @@ public void Dmx_Update()
Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Dpo_Update()
{
var indicator = new Dpo(period: 20);
double initialValue = indicator.Calc(new TValue(DateTime.Now, ReferenceValue, IsNew: true));

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(new TValue(DateTime.Now, GetRandomDouble(), IsNew: false));
}
double finalValue = indicator.Calc(new TValue(DateTime.Now, ReferenceValue, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Pmo_Update()
{
Expand Down Expand Up @@ -214,6 +229,21 @@ public void Trix_Update()
Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Tsi_Update()
{
var indicator = new Tsi(firstPeriod: 25, secondPeriod: 13);
double initialValue = indicator.Calc(new TValue(DateTime.Now, ReferenceValue, IsNew: true));

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(new TValue(DateTime.Now, GetRandomDouble() + 100, IsNew: false)); // Ensure positive prices
}
double finalValue = indicator.Calc(new TValue(DateTime.Now, ReferenceValue, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Vel_Update()
{
Expand All @@ -228,4 +258,20 @@ public void Vel_Update()

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Vortex_Update()
{
var indicator = new Vortex(period: 14);
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}
}
47 changes: 47 additions & 0 deletions Tests/test_updates_oscillators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,51 @@ public void Aroon_Update()

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Bop_Update()
{
var indicator = new Bop();
TBar r = new(DateTime.Now, ReferenceValue, ReferenceValue, ReferenceValue, ReferenceValue, 1000, IsNew: true);
double initialValue = indicator.Calc(r);

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(new TBar(DateTime.Now, GetRandomDouble(), GetRandomDouble(), GetRandomDouble(), GetRandomDouble(), 1000, IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Cci_Update()
{
var indicator = new Cci(period: 20);
TBar r = new(DateTime.Now, ReferenceValue, ReferenceValue, ReferenceValue, ReferenceValue, 1000, IsNew: true);
double initialValue = indicator.Calc(r);

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(new TBar(DateTime.Now, GetRandomDouble(), GetRandomDouble(), GetRandomDouble(), GetRandomDouble(), 1000, IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Cfo_Update()
{
var indicator = new Cfo(period: 14);
double initialValue = indicator.Calc(new TValue(DateTime.Now, ReferenceValue, IsNew: true));

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(new TValue(DateTime.Now, GetRandomDouble(), IsNew: false));
}
double finalValue = indicator.Calc(new TValue(DateTime.Now, ReferenceValue, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}
}
96 changes: 96 additions & 0 deletions Tests/test_updates_volatility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,100 @@ public void Rvi_Update()

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Tr_Update()
{
var indicator = new Tr();
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Ui_Update()
{
var indicator = new Ui(period: 14);
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Vc_Update()
{
var indicator = new Vc(period: 20, deviations: 2.0);
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Vov_Update()
{
var indicator = new Vov(period: 20);
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Vr_Update()
{
var indicator = new Vr(shortPeriod: 10, longPeriod: 20);
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Vs_Update()
{
var indicator = new Vs(period: 14, multiplier: 2.0);
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}
}
163 changes: 163 additions & 0 deletions Tests/test_updates_volume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,167 @@ public void Kvo_Update()

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Mfi_Update()
{
var indicator = new Mfi(period: 14);
TBar r = GetRandomBar(true);

// Generate a sequence of bars for warmup
var warmupBars = new List<TBar>();
for (int i = 0; i < indicator.WarmupPeriod; i++)
{
var bar = GetRandomBar(IsNew: true);
warmupBars.Add(bar);
indicator.Calc(bar);
}

// Calculate initial value after warmup
double initialValue = indicator.Calc(r);

// Apply random updates
for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}

// Reset and replay the same sequence
indicator.Init();
foreach (var bar in warmupBars)
{
indicator.Calc(bar);
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Nvi_Update()
{
var indicator = new Nvi();
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Obv_Update()
{
var indicator = new Obv();
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Pvi_Update()
{
var indicator = new Pvi();
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Pvol_Update()
{
var indicator = new Pvol();
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Pvo_Update()
{
var indicator = new Pvo(shortPeriod: 12, longPeriod: 26);
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Pvr_Update()
{
var indicator = new Pvr();
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Pvt_Update()
{
var indicator = new Pvt();
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Tvi_Update()
{
var indicator = new Tvi(minTick: 0.5);
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}
}
Loading

0 comments on commit 6231bab

Please sign in to comment.