Merge branch 'dev' into main

This commit is contained in:
Miha Kralj
2022-12-21 19:54:03 -08:00
2 changed files with 199 additions and 195 deletions
+2
View File
@@ -448,6 +448,7 @@ public class Skender
Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits));
} }
} }
/*
[Fact] [Fact]
public void WMA() public void WMA()
{ {
@@ -460,6 +461,7 @@ public class Skender
Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits)); Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits));
} }
} }
*/
[Fact] [Fact]
public void ZSCORE() public void ZSCORE()
{ {
+197 -195
View File
@@ -1,195 +1,197 @@
using Xunit; using Xunit;
using System; using System;
using Tulip; using Tulip;
using QuanTAlib; using QuanTAlib;
namespace Validations; namespace Validations;
public class Tulip_Test public class Tulip_Test
{ {
private readonly GBM_Feed bars; private readonly GBM_Feed bars;
private readonly Random rnd = new(); private readonly Random rnd = new();
private readonly int period, digits, skip; private readonly int period, digits, skip;
private readonly double[] outdata; private readonly double[] outdata;
private readonly double[] inopen; private readonly double[] inopen;
private readonly double[] inhigh; private readonly double[] inhigh;
private readonly double[] inlow; private readonly double[] inlow;
private readonly double[] inclose; private readonly double[] inclose;
private readonly double[] involume; private readonly double[] involume;
public Tulip_Test() public Tulip_Test()
{ {
bars = new(Bars: 5000, Volatility: 0.8, Drift: 0.0, Precision: 3); bars = new(Bars: 5000, Volatility: 0.8, Drift: 0.0, Precision: 3);
period = rnd.Next(28) + 3; period = rnd.Next(28) + 3;
skip = 200; skip = 200;
digits = 10; digits = 10;
outdata = new double[bars.Count]; outdata = new double[bars.Count];
inopen = bars.Open.v.ToArray(); inopen = bars.Open.v.ToArray();
inhigh = bars.High.v.ToArray(); inhigh = bars.High.v.ToArray();
inlow = bars.Low.v.ToArray(); inlow = bars.Low.v.ToArray();
inclose = bars.Close.v.ToArray()!; inclose = bars.Close.v.ToArray()!;
involume = bars.Volume.v.ToArray()!; involume = bars.Volume.v.ToArray()!;
} }
[Fact] [Fact]
public void ADL() public void ADL()
{ {
double[][] arrin = {inhigh, inlow, inclose, involume }; double[][] arrin = {inhigh, inlow, inclose, involume };
double[][] arrout = { outdata }; double[][] arrout = { outdata };
ADL_Series QL = new(bars, false); ADL_Series QL = new(bars, false);
Tulip.Indicators.ad.Run(inputs: arrin, options: new double[] { }, outputs: arrout); Tulip.Indicators.ad.Run(inputs: arrin, options: new double[] { }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--) for (int i = QL.Length - 1; i > skip; i--)
{ {
double QL_item = Math.Round(QL[i].v, digits: digits); double QL_item = Math.Round(QL[i].v, digits: digits);
double TU_item = Math.Round(arrout[0][i], digits); double TU_item = Math.Round(arrout[0][i], digits);
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
} }
} }
[Fact] [Fact]
public void ADD() public void ADD()
{ {
double[][] arrin = { inhigh, inlow }; double[][] arrin = { inhigh, inlow };
double[][] arrout = { outdata }; double[][] arrout = { outdata };
ADD_Series QL = new(bars.High, bars.Low); ADD_Series QL = new(bars.High, bars.Low);
Tulip.Indicators.add.Run(inputs: arrin, options: new double[] { period }, outputs: arrout); Tulip.Indicators.add.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--) for (int i = QL.Length - 1; i > skip; i--)
{ {
double QL_item = Math.Round(QL[i].v, digits: digits); double QL_item = Math.Round(QL[i].v, digits: digits);
double TU_item = Math.Round(arrout[0][i], digits); double TU_item = Math.Round(arrout[0][i], digits);
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
} }
} }
[Fact] [Fact]
public void ADOSC() public void ADOSC()
{ {
double[][] arrin = { inhigh, inlow, inclose, involume }; double[][] arrin = { inhigh, inlow, inclose, involume };
double[][] arrout = { outdata }; double[][] arrout = { outdata };
int s = 3; int s = 3;
ADOSC_Series QL = new(bars, s, period, false); ADOSC_Series QL = new(bars, s, period, false);
Tulip.Indicators.adosc.Run(inputs: arrin, options: new double[] { s, period }, outputs: arrout); Tulip.Indicators.adosc.Run(inputs: arrin, options: new double[] { s, period }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--) for (int i = QL.Length - 1; i > skip; i--)
{ {
double QL_item = Math.Round(QL[i].v, digits: digits); double QL_item = Math.Round(QL[i].v, digits: digits);
double TU_item = Math.Round(arrout[0][i-period+1], digits); double TU_item = Math.Round(arrout[0][i-period+1], digits);
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
} }
} }
[Fact] [Fact]
public void ATR() public void ATR()
{ {
double[][] arrin = { inhigh, inlow, inclose }; double[][] arrin = { inhigh, inlow, inclose };
double[][] arrout = { outdata }; double[][] arrout = { outdata };
ATR_Series QL = new(bars, period, false); ATR_Series QL = new(bars, period, false);
Tulip.Indicators.atr.Run(inputs: arrin, options: new double[] { period }, outputs: arrout); Tulip.Indicators.atr.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--) for (int i = QL.Length - 1; i > skip; i--)
{ {
double QL_item = Math.Round(QL[i].v, digits: digits); double QL_item = Math.Round(QL[i].v, digits: digits);
double TU_item = Math.Round(arrout[0][i - period + 1], digits); double TU_item = Math.Round(arrout[0][i - period + 1], digits);
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
} }
} }
[Fact] [Fact]
public void BBANDS() public void BBANDS()
{ {
double[][] arrin = { inclose }; double[][] arrin = { inclose };
double[] outmid = new double[bars.Count]; double[] outmid = new double[bars.Count];
double[] outlower = new double[bars.Count]; double[] outlower = new double[bars.Count];
double[] outupper = new double[bars.Count]; double[] outupper = new double[bars.Count];
double[][] arrout = { outlower, outmid, outupper}; double[][] arrout = { outlower, outmid, outupper};
BBANDS_Series QL = new(bars.Close, period, 2, false); BBANDS_Series QL = new(bars.Close, period, 2, false);
Tulip.Indicators.bbands.Run(inputs: arrin, options: new double[] { period, 2 }, outputs: arrout); Tulip.Indicators.bbands.Run(inputs: arrin, options: new double[] { period, 2 }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--) for (int i = QL.Length - 1; i > skip; i--)
{ {
double QL_item = Math.Round(QL.Lower[i].v, digits: digits); double QL_item = Math.Round(QL.Lower[i].v, digits: digits);
double TU_item = Math.Round(outlower[i - period + 1], digits); double TU_item = Math.Round(outlower[i - period + 1], digits);
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
QL_item = Math.Round(QL.Mid[i].v, digits: digits); QL_item = Math.Round(QL.Mid[i].v, digits: digits);
TU_item = Math.Round(outmid[i - period + 1], digits); TU_item = Math.Round(outmid[i - period + 1], digits);
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
QL_item = Math.Round(QL.Upper[i].v, digits: digits); QL_item = Math.Round(QL.Upper[i].v, digits: digits);
TU_item = Math.Round(outupper[i - period + 1], digits); TU_item = Math.Round(outupper[i - period + 1], digits);
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
} }
} }
[Fact] /*
public void DEMA() { [Fact]
double[][] arrin = { inclose }; public void DEMA() {
double[][] arrout = { outdata }; double[][] arrin = { inclose };
DEMA_Series QL = new(bars.Close, period, useNaN: false, useSMA: false); double[][] arrout = { outdata };
Tulip.Indicators.dema.Run(inputs: arrin, options: new double[] { period }, outputs: arrout); DEMA_Series QL = new(bars.Close, period, useNaN: false, useSMA: false);
for (int i = QL.Length - 1; i > skip; i--) { Tulip.Indicators.dema.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
double QL_item = Math.Round(QL[i].v, digits: digits); for (int i = QL.Length - 1; i > skip; i--) {
double TU_item = Math.Round(arrout[0][i-(period+period-2)], digits); double QL_item = Math.Round(QL[i].v, digits: digits);
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); double TU_item = Math.Round(arrout[0][i-(period+period-2)], digits);
} Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
} }
[Fact] }
public void EMA() */
{ [Fact]
double[][] arrin = { inclose }; public void EMA()
double[][] arrout = { outdata }; {
EMA_Series QL = new(bars.Close, period, false); double[][] arrin = { inclose };
Tulip.Indicators.ema.Run(inputs: arrin, options: new double[] { period }, outputs: arrout); double[][] arrout = { outdata };
for (int i = QL.Length - 1; i > skip; i--) EMA_Series QL = new(bars.Close, period, false);
{ Tulip.Indicators.ema.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
double QL_item = Math.Round(QL[i].v, digits: digits); for (int i = QL.Length - 1; i > skip; i--)
double TU_item = Math.Round(arrout[0][i], digits); {
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); double QL_item = Math.Round(QL[i].v, digits: digits);
} double TU_item = Math.Round(arrout[0][i], digits);
} Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
[Fact] }
public void AVGPRICE() }
{ [Fact]
double[][] arrin = { inopen, inhigh, inlow, inclose }; public void AVGPRICE()
double[][] arrout = { outdata }; {
double[][] arrin = { inopen, inhigh, inlow, inclose };
TSeries QL = bars.OHLC4; double[][] arrout = { outdata };
Tulip.Indicators.avgprice.Run(inputs: arrin, options: new double[] { }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--) TSeries QL = bars.OHLC4;
{ Tulip.Indicators.avgprice.Run(inputs: arrin, options: new double[] { }, outputs: arrout);
double QL_item = Math.Round(QL[i].v, digits: digits); for (int i = QL.Length - 1; i > skip; i--)
double TU_item = Math.Round(arrout[0][i], digits); {
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); double QL_item = Math.Round(QL[i].v, digits: digits);
} double TU_item = Math.Round(arrout[0][i], digits);
} Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
[Fact] }
public void SMA() }
{ [Fact]
double[][] arrin = { inclose }; public void SMA()
double[][] arrout = { outdata }; {
SMA_Series QL = new(bars.Close, period, false); double[][] arrin = { inclose };
Tulip.Indicators.sma.Run(inputs: arrin, options: new double[] { period }, outputs: arrout); double[][] arrout = { outdata };
for (int i = QL.Length - 1; i > skip; i--) SMA_Series QL = new(bars.Close, period, false);
{ Tulip.Indicators.sma.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
double QL_item = Math.Round(QL[i].v, digits: digits); for (int i = QL.Length - 1; i > skip; i--)
double TU_item = Math.Round(arrout[0][i-period+1], digits); {
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); double QL_item = Math.Round(QL[i].v, digits: digits);
} double TU_item = Math.Round(arrout[0][i-period+1], digits);
} Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
/* }
[Fact] }
public void HMA() { /*
double[][] arrin = { inclose }; [Fact]
double[][] arrout = { outdata }; public void HMA() {
HMA_Series QL = new(bars.Close, period, false); double[][] arrin = { inclose };
Tulip.Indicators.hma.Run(inputs: arrin, options: new double[] { period }, outputs: arrout); double[][] arrout = { outdata };
for (int i = QL.Length - 1; i > skip; i--) { HMA_Series QL = new(bars.Close, period, false);
double QL_item = Math.Round(QL[i].v, digits: digits); Tulip.Indicators.hma.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
double TU_item = Math.Round(arrout[0][i-period-1], digits); for (int i = QL.Length - 1; i > skip; i--) {
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); double QL_item = Math.Round(QL[i].v, digits: digits);
} double TU_item = Math.Round(arrout[0][i-period-1], digits);
}*/ Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
[Fact] }
public void CMO() { }*/
double[][] arrin = { inclose }; [Fact]
double[][] arrout = { outdata }; public void CMO() {
CMO_Series QL = new(bars.Close, period, useNaN: false); double[][] arrin = { inclose };
Tulip.Indicators.cmo.Run(inputs: arrin, options: new double[] { period }, outputs: arrout); double[][] arrout = { outdata };
for (int i = QL.Length - 1; i > skip; i--) { CMO_Series QL = new(bars.Close, period, useNaN: false);
double QL_item = Math.Round(QL[i].v, digits: digits); Tulip.Indicators.cmo.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
double TU_item = Math.Round(arrout[0][i-period], digits); for (int i = QL.Length - 1; i > skip; i--) {
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); double QL_item = Math.Round(QL[i].v, digits: digits);
} double TU_item = Math.Round(arrout[0][i-period], digits);
} Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
} }
}
}