Quantower adaptation

This commit is contained in:
Miha Kralj
2022-12-21 07:24:21 -08:00
parent 9f01df0e65
commit 9ad467cd5a
28 changed files with 3493 additions and 3204 deletions
+512 -512
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -17,7 +17,7 @@
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0-preview-20221003-04" />
<PackageReference Include="TALib.NETCore" Version="0.4.4" />
<PackageReference Include="Skender.Stock.Indicators" Version="2.4.0" />
<PackageReference Include="Skender.Stock.Indicators" Version="2.4.2" />
<PackageReference Include="pythonnet" Version="3.0.1" />
<PackageReference Include="Tulip.NETCore" Version="0.8.0.1" />
<PackageReference Include="System.Text.Json" Version="7.0.0" />
+381 -360
View File
@@ -1,361 +1,382 @@
using Xunit;
using System;
using QuanTAlib;
using Python.Runtime;
using Python.Included;
namespace Validations;
public class PandasTA : IDisposable
{
private readonly GBM_Feed bars;
private readonly Random rnd = new();
private readonly int period, sample;
private int digits;
private readonly string OStype;
private readonly dynamic np;
private readonly dynamic ta;
private readonly dynamic df;
public PandasTA() {
bars = new(Bars: 5000, Volatility: 0.8, Drift: 0.0);
period = rnd.Next(maxValue: 28) + 3;
sample = 200;
digits = 10;
// Checking the host OS and setting PythonDLL accordingly
OStype = Environment.OSVersion.ToString();
if (OStype == "Unix 13.1.0")
OStype = @"/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/libpython3.10.dylib";
else OStype = Path.GetFullPath(".") + @"\python-3.10.0-embed-amd64\python310.dll";
Installer.InstallPath = Path.GetFullPath(path: ".");
Installer.SetupPython().Wait();
Installer.TryInstallPip();
Installer.PipInstallModule(module_name: "pandas-ta");
Runtime.PythonDLL = OStype;
PythonEngine.Initialize();
np = Py.Import(name: "numpy");
ta = Py.Import(name: "pandas_ta");
string[] cols = { "open", "high", "low", "close", "volume" };
double[,] ary = new double[bars.Count, 5];
for (int i = 0; i < bars.Count; i++) {
ary[i, 0] = bars.Open[i].v;
ary[i, 1] = bars.High[i].v;
ary[i, 2] = bars.Low[i].v;
ary[i, 3] = bars.Close[i].v;
ary[i, 4] = bars.Volume[i].v;
}
df = ta.DataFrame(data: np.array(ary), index: np.array(bars.Close.t), columns: np.array(cols));
}
public void Dispose()
{
PythonEngine.Shutdown();
GC.SuppressFinalize(this);
}
[Fact] void ADL() {
ADL_Series QL = new(bars);
var pta = df.ta.ad(high: df.high, low: df.low, close:df.close, volume:df.volume);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i-1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i-1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void ADOSC() {
ADOSC_Series QL = new(bars);
var pta = df.ta.adosc(high: df.high, low: df.low, close: df.close, volume: df.volume);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void ATR() {
ATR_Series QL = new(bars, period);
var pta = df.ta.atr(high: df.high, low: df.low, close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void BIAS() {
BIAS_Series QL = new(bars.Close, period, false);
var pta = df.ta.bias(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void DEMA() {
DEMA_Series QL = new(bars.Close, period, false);
var pta = df.ta.dema(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void EMA() {
EMA_Series QL = new(bars.Close, period, false);
var pta = df.ta.ema(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void ENTROPY() {
ENTROPY_Series QL = new(bars.Close, period, useNaN: false);
var pta = df.ta.entropy(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void HL2() {
var pta = df.ta.hl2(high: df.high, low: df.low);
for (int i = bars.HL2.Length; i > bars.HL2.Length-sample; i--)
{
double QL_item = Math.Round(bars.HL2[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void HLC3() {
var pta = df.ta.hlc3(high: df.high, low: df.low, close: df.close);
for (int i = bars.HLC3.Length; i > bars.HLC3.Length-sample; i--)
{
double QL_item = Math.Round(bars.HLC3[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void HMA() {
HMA_Series QL = new(bars.Close, period, false);
var pta = df.ta.hma(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void KAMA() {
KAMA_Series QL = new(bars.Close, period);
var pta = df.ta.kama(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void KURTOSIS() {
KURTOSIS_Series QL = new(bars.Close, period, useNaN: false);
var pta = df.ta.kurtosis(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void MAD()
{
MAD_Series QL = new(bars.Close, period, useNaN: false);
var pta = df.ta.mad(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void MEDIAN() {
MEDIAN_Series QL = new(bars.Close, period);
var pta = df.ta.median(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void OBV() {
OBV_Series QL = new(bars);
var pta = df.ta.obv(close: df.close, volume: df.volume);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void OHLC4() {
var pta = df.ta.ohlc4(open: df.open, high: df.high, low: df.low, close: df.close);
for (int i = bars.OHLC4.Length; i > bars.OHLC4.Length-sample; i--)
{
double QL_item = Math.Round(bars.OHLC4[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void RMA() {
RMA_Series QL = new(bars.Close, period, false);
var pta = df.ta.rma(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void RSI() {
RSI_Series QL = new(bars.Close, period);
var pta = df.ta.rsi(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void SDEV() {
SDEV_Series QL = new(bars.Close, period, useNaN: false);
var pta = df.ta.stdev(close: df.close, length: period, ddof: 0);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void SMA() {
SMA_Series QL = new(bars.Close, period, false);
var pta = df.ta.sma(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void SSDEV() {
SSDEV_Series QL = new(bars.Close, period, useNaN: false);
var pta = df.ta.stdev(close: df.close, length: period, ddof: 1);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
/*
[Fact] void SVARIANCE() {
SVAR_Series QL = new(bars.Close, period);
var pta = df.ta.variance(close: df.close, length: period, ddof: 1);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
*/
[Fact] void T3() {
T3_Series QL = new(source: bars.Close, period: period, vfactor: 0.7, useNaN: false);
var pta = df.ta.t3(close: df.close, length: period, a: 0.7);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void TEMA() {
TEMA_Series QL = new(bars.Close, period, false);
var pta = df.ta.tema(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void TR() {
TR_Series QL = new(bars);
var pta = df.ta.true_range(high: df.high, low: df.low, close: df.close);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void TRIMA() {
// TODO: return length to variable length (period) when Pandas-TA fixes trima to calculate even periods right
TRIMA_Series QL = new(bars.Close, 11);
var pta = df.ta.trima(close: df.close, length: 11);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void VARIANCE() {
VAR_Series QL = new(bars.Close, period);
var pta = df.ta.variance(close: df.close, length: period, ddof:0);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void WMA() {
WMA_Series QL = new(bars.Close, period, false);
var pta = df.ta.wma(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void ZLEMA() {
ZLEMA_Series QL = new(bars.Close, period, false);
var pta = df.ta.zlma(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void ZSCORE() {
ZSCORE_Series QL = new(bars.Close, period, useNaN: false);
var pta = df.ta.zscore(close: df.close, length: period, ddof: 0);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
using Xunit;
using System;
using QuanTAlib;
using Python.Runtime;
using Python.Included;
namespace Validations;
public class PandasTA : IDisposable
{
private readonly GBM_Feed bars;
private readonly Random rnd = new();
private readonly int period, sample;
private int digits;
private readonly string OStype;
private readonly dynamic np;
private readonly dynamic ta;
private readonly dynamic df;
public PandasTA() {
bars = new(Bars: 5000, Volatility: 0.8, Drift: 0.0);
period = rnd.Next(maxValue: 28) + 3;
sample = 200;
digits = 10;
// Checking the host OS and setting PythonDLL accordingly
OStype = Environment.OSVersion.ToString();
if (OStype == "Unix 13.1.0")
OStype = @"/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/libpython3.10.dylib";
else OStype = Path.GetFullPath(".") + @"\python-3.10.0-embed-amd64\python310.dll";
Installer.InstallPath = Path.GetFullPath(path: ".");
Installer.SetupPython().Wait();
Installer.TryInstallPip();
Installer.PipInstallModule(module_name: "pandas-ta");
Runtime.PythonDLL = OStype;
PythonEngine.Initialize();
np = Py.Import(name: "numpy");
ta = Py.Import(name: "pandas_ta");
string[] cols = { "open", "high", "low", "close", "volume" };
double[,] ary = new double[bars.Count, 5];
for (int i = 0; i < bars.Count; i++) {
ary[i, 0] = bars.Open[i].v;
ary[i, 1] = bars.High[i].v;
ary[i, 2] = bars.Low[i].v;
ary[i, 3] = bars.Close[i].v;
ary[i, 4] = bars.Volume[i].v;
}
df = ta.DataFrame(data: np.array(ary), index: np.array(bars.Close.t), columns: np.array(cols));
}
public void Dispose()
{
PythonEngine.Shutdown();
GC.SuppressFinalize(this);
}
[Fact] void ADL() {
ADL_Series QL = new(bars);
var pta = df.ta.ad(high: df.high, low: df.low, close:df.close, volume:df.volume);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i-1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i-1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void ADOSC() {
ADOSC_Series QL = new(bars);
var pta = df.ta.adosc(high: df.high, low: df.low, close: df.close, volume: df.volume);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void ATR() {
ATR_Series QL = new(bars, period);
var pta = df.ta.atr(high: df.high, low: df.low, close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void BIAS() {
BIAS_Series QL = new(bars.Close, period, false);
var pta = df.ta.bias(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
/*
[Fact]
void CMO() {
CMO_Series QL = new(bars.Close, period, false);
var pta = df.ta.cmo(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length - sample; i--) {
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
*/
[Fact] void DEMA() {
DEMA_Series QL = new(bars.Close, period, false);
var pta = df.ta.dema(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void EMA() {
EMA_Series QL = new(bars.Close, period, false);
var pta = df.ta.ema(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void ENTROPY() {
ENTROPY_Series QL = new(bars.Close, period, useNaN: false);
var pta = df.ta.entropy(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void HL2() {
var pta = df.ta.hl2(high: df.high, low: df.low);
for (int i = bars.HL2.Length; i > bars.HL2.Length-sample; i--)
{
double QL_item = Math.Round(bars.HL2[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void HLC3() {
var pta = df.ta.hlc3(high: df.high, low: df.low, close: df.close);
for (int i = bars.HLC3.Length; i > bars.HLC3.Length-sample; i--)
{
double QL_item = Math.Round(bars.HLC3[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void HMA() {
HMA_Series QL = new(bars.Close, period, false);
var pta = df.ta.hma(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void KAMA() {
KAMA_Series QL = new(bars.Close, period);
var pta = df.ta.kama(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void KURTOSIS() {
KURTOSIS_Series QL = new(bars.Close, period, useNaN: false);
var pta = df.ta.kurtosis(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void MAD()
{
MAD_Series QL = new(bars.Close, period, useNaN: false);
var pta = df.ta.mad(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void MEDIAN() {
MEDIAN_Series QL = new(bars.Close, period);
var pta = df.ta.median(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void OBV() {
OBV_Series QL = new(bars);
var pta = df.ta.obv(close: df.close, volume: df.volume);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void OHLC4() {
var pta = df.ta.ohlc4(open: df.open, high: df.high, low: df.low, close: df.close);
for (int i = bars.OHLC4.Length; i > bars.OHLC4.Length-sample; i--)
{
double QL_item = Math.Round(bars.OHLC4[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void RMA() {
RMA_Series QL = new(bars.Close, period, false);
var pta = df.ta.rma(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void RSI() {
RSI_Series QL = new(bars.Close, period);
var pta = df.ta.rsi(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void SDEV() {
SDEV_Series QL = new(bars.Close, period, useNaN: false);
var pta = df.ta.stdev(close: df.close, length: period, ddof: 0);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void SMA() {
SMA_Series QL = new(bars.Close, period, false);
var pta = df.ta.sma(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void SSDEV() {
SSDEV_Series QL = new(bars.Close, period, useNaN: false);
var pta = df.ta.stdev(close: df.close, length: period, ddof: 1);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
/*
[Fact] void SVARIANCE() {
SVAR_Series QL = new(bars.Close, period);
var pta = df.ta.variance(close: df.close, length: period, ddof: 1);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
*/
[Fact] void T3() {
T3_Series QL = new(source: bars.Close, period: period, vfactor: 0.7, useNaN: false);
var pta = df.ta.t3(close: df.close, length: period, a: 0.7);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void TEMA() {
TEMA_Series QL = new(bars.Close, period, false);
var pta = df.ta.tema(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void TR() {
TR_Series QL = new(bars);
var pta = df.ta.true_range(high: df.high, low: df.low, close: df.close);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void TRIMA() {
// TODO: return length to variable length (period) when Pandas-TA fixes trima to calculate even periods right
TRIMA_Series QL = new(bars.Close, 11);
var pta = df.ta.trima(close: df.close, length: 11);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void TRIX() {
TRIX_Series QL = new(bars.Close, period);
var pta = df.ta.trix(close: df.close, length: period).to_numpy();
for (int i = QL.Length; i > QL.Length - sample; i--) {
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1][0], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void VARIANCE() {
VAR_Series QL = new(bars.Close, period);
var pta = df.ta.variance(close: df.close, length: period, ddof:0);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void WMA() {
WMA_Series QL = new(bars.Close, period, false);
var pta = df.ta.wma(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void ZLEMA() {
ZLEMA_Series QL = new(bars.Close, period, false);
var pta = df.ta.zlma(close: df.close, length: period);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact] void ZSCORE() {
ZSCORE_Series QL = new(bars.Close, period, useNaN: false);
var pta = df.ta.zscore(close: df.close, length: period, ddof: 0);
for (int i = QL.Length; i > QL.Length-sample; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double PanTA_item = Math.Round((double)pta[i - 1], digits: digits);
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
}
+61 -54
View File
@@ -10,16 +10,16 @@ public class Skender
private readonly Random rnd = new();
private readonly int period, digits, skip;
private readonly IEnumerable<Quote> quotes;
public Skender()
{
bars = new(Bars: 10000, Volatility: 0.5, Drift: 0.0, Precision: 2);
period = rnd.Next(30) + 5;
skip = 200;
digits = 10;
digits = 2; //minimizing rounding errors in type conversions
skip = 300;
quotes = bars.Select(q => new Quote
quotes = bars.Select(q => new Quote
{
Date = q.t,
Open = (decimal)q.o,
@@ -33,14 +33,15 @@ public class Skender
[Fact]
public void ADL()
{
// TODO: check precision of ADL()
ADL_Series QL = new(bars, false);
var SK = quotes.GetAdl().Select(i => i.Adl);
for (int i = QL.Length; i > skip; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round(SK.ElementAt(i - 1)!, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
public void ALMA()
@@ -51,7 +52,7 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -63,7 +64,7 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -75,7 +76,7 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -87,22 +88,22 @@ public class Skender
{
double QL_item = Math.Round(QL.Mid[i - 1].v, digits: digits);
double SK_item = Math.Round((double)SK.ElementAt(i - 1).Sma!.Value, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
QL_item = Math.Round(QL.Upper[i - 1].v, digits: digits);
SK_item = Math.Round((double)SK.ElementAt(i - 1).UpperBand!.Value, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
QL_item = Math.Round(QL.Lower[i - 1].v, digits: digits);
SK_item = Math.Round((double)SK.ElementAt(i - 1).LowerBand!.Value, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
QL_item = Math.Round(QL.Bandwidth[i - 1].v, digits: digits);
SK_item = Math.Round((double)SK.ElementAt(i - 1).Width!.Value, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
QL_item = Math.Round(QL.PercentB[i - 1].v, digits: digits);
SK_item = Math.Round((double)SK.ElementAt(i - 1).PercentB!.Value, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
QL_item = Math.Round(QL.Zscore[i - 1].v, digits: digits);
SK_item = Math.Round((double)SK.ElementAt(i - 1).ZScore!.Value, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -114,7 +115,19 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
public void CMO()
{
CMO_Series QL = new(bars.Close, period, false);
var SK = quotes.GetCmo(period).Select(i => i.Cmo.Null2NaN()!);
for (int i = QL.Length; i > skip; i--)
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits);
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -126,7 +139,7 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -138,10 +151,9 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
/*
[Fact]
public void DEMA()
{
@@ -151,10 +163,9 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
*/
[Fact]
public void EMA()
{
@@ -164,7 +175,7 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
/*
@@ -177,7 +188,7 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round((double)SK.ElementAt(i - 1)!, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -189,7 +200,7 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round((double)SK.ElementAt(i - 1)!, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
*/
@@ -202,10 +213,9 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
/*
[Fact]
public void KAMA()
{
@@ -216,10 +226,9 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits/2), Math.Exp(-digits/2));
Assert.Equal(SK_item!, QL_item);
}
}
*/
[Fact]
public void LINREG()
{
@@ -229,16 +238,16 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round((double)SK.ElementAt(i - 1).Slope!, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
QL_item = Math.Round(QL.Intercept[i - 1].v, digits: digits);
SK_item = Math.Round((double)SK.ElementAt(i - 1).Intercept!, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
QL_item = Math.Round(QL.RSquared[i - 1].v, digits: digits);
SK_item = Math.Round((double)SK.ElementAt(i - 1).RSquared!, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
QL_item = Math.Round(QL.StdDev[i - 1].v, digits: digits);
SK_item = Math.Round((double)SK.ElementAt(i - 1).StdDev!, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -250,10 +259,10 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round(SK.ElementAt(i - 1).Macd.Null2NaN()!, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
QL_item = Math.Round(QL.Signal[i - 1].v, digits: digits);
SK_item = Math.Round(SK.ElementAt(i - 1).Signal.Null2NaN()!, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -265,7 +274,7 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -277,10 +286,10 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round(SK.ElementAt(i - 1).Mama.Null2NaN()!, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
QL_item = Math.Round(QL.Fama[i - 1].v, digits: digits);
SK_item = Math.Round(SK.ElementAt(i - 1).Fama.Null2NaN()!, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -292,7 +301,7 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -304,7 +313,7 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -317,7 +326,7 @@ public class Skender
{
double QL_item = Math.Round(QL.Last().v, digits: digits);
double SK_item = Math.Round(SK.Last()! + (double)quotes.First().Volume!, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
/*
@@ -330,7 +339,7 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round((double)SK.ElementAt(i - 1)!, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -342,7 +351,7 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round((double)SK.ElementAt(i - 1)!, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -354,7 +363,7 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round((double)SK.ElementAt(i - 1)!, digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
*/
@@ -367,7 +376,7 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -379,7 +388,7 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -391,7 +400,7 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -403,10 +412,9 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
/*
[Fact]
public void T3()
{
@@ -416,10 +424,9 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
*/
[Fact]
public void TEMA()
{
@@ -429,7 +436,7 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -441,7 +448,7 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -453,7 +460,7 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
[Fact]
@@ -465,7 +472,7 @@ public class Skender
{
double QL_item = Math.Round(QL[i - 1].v, digits: digits);
double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits);
Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
Assert.Equal(SK_item!, QL_item);
}
}
+474 -452
View File
@@ -1,452 +1,474 @@
using Xunit;
using System;
using TALib;
using QuanTAlib;
namespace Validations;
public class Ta_Lib
{
private readonly GBM_Feed bars;
private readonly Random rnd = new();
private readonly int period, digits, skip;
private readonly double[] TALIB;
private readonly double[] TALIB2;
private readonly double[] inopen;
private readonly double[] inhigh;
private readonly double[] inlow;
private readonly double[] inclose;
private readonly double[] involume;
public Ta_Lib()
{
bars = new(Bars: 5000, Volatility: 0.8, Drift: 0.0, Precision: 3);
period = rnd.Next(28) + 3;
skip = 500;
digits = 10;
TALIB = new double[bars.Count];
TALIB2 = new double[bars.Count];
inopen = bars.Open.v.ToArray();
inhigh = bars.High.v.ToArray();
inlow = bars.Low.v.ToArray();
inclose = bars.Close.v.ToArray();
involume = bars.Volume.v.ToArray();
}
[Fact]
public void ADD()
{
ADD_Series QL = new(bars.Open, bars.Close);
Core.Add(inopen, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void ADL()
{
ADL_Series QL = new(bars, false);
Core.Ad(inhigh, inlow, inclose, involume, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > 0; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void ADOSC()
{
ADOSC_Series QL = new(bars, 3, 10, false);
Core.AdOsc(inhigh, inlow, inclose, involume, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void ATR()
{
ATR_Series QL = new(bars, period, false);
Core.Atr(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip * 15; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
/*
[Fact]
public void BBANDS()
{
double[] outMiddle = new double[bars.Count];
double[] outUpper = new double[bars.Count];
double[] outLower = new double[bars.Count];
BBANDS_Series QL = new(bars.Close, period: 26, multiplier: 2.0, false);
Core.Bbands(inclose, 0, bars.Count - 1, outRealUpperBand: outUpper, outRealMiddleBand: outMiddle, outRealLowerBand: outLower, out int outBegIdx, out _, optInTimePeriod: 26, optInNbDevUp: 2.0, optInNbDevDn: 2.0);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL.Upper[i].v, digits: digits);
double TA_item = Math.Round(outUpper[i - outBegIdx], digits: digits);
Assert.Equal(TA_item!, QL_item);
QL_item = Math.Round(QL.Mid[i].v, digits: digits);
TA_item = Math.Round(outMiddle[i - outBegIdx], digits: digits);
Assert.Equal(TA_item!, QL_item);
QL_item = Math.Round(QL.Lower[i].v, digits: digits);
TA_item = Math.Round(outLower[i - outBegIdx], digits: digits);
Assert.Equal(TA_item!, QL_item);
}
Assert.Equal(Math.Round(outUpper[outUpper.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Upper.Last().v, digits: digits));
Assert.Equal(Math.Round(outMiddle[outMiddle.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Mid.Last().v, digits: digits));
Assert.Equal(Math.Round(outLower[outLower.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Lower.Last().v, digits: digits));
}
*/
[Fact]
public void CCI()
{
CCI_Series QL = new(bars, period, false);
Core.Cci(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void CORR()
{
CORR_Series QL = new(bars.Open, bars.Close, period);
Core.Correl(inopen, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, optInTimePeriod: period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void DEMA()
{
DEMA_Series QL = new(bars.Close, period, false);
Core.Dema(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void DIV()
{
DIV_Series QL = new(bars.Open, bars.Close);
Core.Div(inopen, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void EMA()
{
EMA_Series QL = new(bars.Close, period, false);
Core.Ema(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void HL2()
{
TSeries QL = bars.HL2;
Core.MedPrice(inhigh, inlow, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void HLC3()
{
TSeries QL = bars.HLC3;
Core.TypPrice(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void HLCC4()
{
TSeries QL = bars.HLCC4;
Core.WclPrice(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void MACD()
{
double[] macdSignal = new double[bars.Count];
double[] macdHist = new double[bars.Count];
MACD_Series QL = new(bars.Close, slow: 26, fast: 12, signal: 9, false);
Core.Macd(inclose, 0, bars.Count - 1, outMacd: TALIB, outMacdSignal: macdSignal, outMacdHist: macdHist, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip * 10; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.Equal(TA_item!, QL_item);
QL_item = Math.Round(QL.Signal[i].v, digits: digits);
TA_item = Math.Round(macdSignal[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void MAMA()
{
MAMA_Series QL = new(bars.Close, fastlimit: 0.5, slowlimit: 0.05);
Core.Mama(inReal: inclose, startIdx: 0, endIdx: bars.Count - 1, outMama: TALIB, outFama: TALIB2, outBegIdx: out int outBegIdx, outNbElement: out _, optInFastLimit: 0.5, optInSlowLimit: 0.05);
for (int i = QL.Length - 1; i > skip * 15; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void MAX()
{
MAX_Series QL = new(bars.Close, period, false);
Core.Max(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void MIDPOINT()
{
MIDPOINT_Series QL = new(bars.Close, period, false);
Core.MidPoint(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void MIDPRICE()
{
MIDPRICE_Series QL = new(bars, period, false);
Core.MidPrice(inhigh, inlow, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void MIN()
{
MIN_Series QL = new(bars.Close, period, false);
Core.Min(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void MUL()
{
MUL_Series QL = new(bars.Open, bars.Close);
Core.Mult(inopen, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void OBV()
{
OBV_Series QL = new(bars, period, false);
Core.Obv(inclose, involume, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void OHLC4()
{
TSeries QL = bars.OHLC4;
Core.AvgPrice(inopen, inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void RSI()
{
RSI_Series QL = new(bars.Close, period, false);
Core.Rsi(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void SDEV()
{
SDEV_Series QL = new(bars.Close, period, false);
Core.StdDev(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void SMA()
{
SMA_Series QL = new(bars.Close, period, false);
Core.Sma(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void SUB()
{
SUB_Series QL = new(bars.Open, bars.Close);
Core.Sub(inopen, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void SUM()
{
SUM_Series QL = new(bars.Close, period, false);
Core.Sum(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void T3()
{
T3_Series QL = new(source: bars.Close, period: period, vfactor: 0.7, useNaN: false);
Core.T3(inReal: inclose, startIdx: 0, endIdx: bars.Count - 1, outReal: TALIB, outBegIdx: out int outBegIdx, outNbElement: out _, optInTimePeriod: period, optInVFactor: 0.7);
for (int i = QL.Length - 1; i > skip * 15; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void TEMA()
{
TEMA_Series QL = new(bars.Close, period, false);
Core.Tema(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip * 15; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void TR()
{
TR_Series QL = new(bars, false);
Core.TRange(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void TRIMA()
{
TRIMA_Series QL = new(bars.Close, period, false);
Core.Trima(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void VAR()
{
VAR_Series QL = new(bars.Close, period, false);
Core.Var(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip * 15; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void WMA()
{
WMA_Series QL = new(bars.Close, period, false);
Core.Wma(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
}
using Xunit;
using System;
using TALib;
using QuanTAlib;
namespace Validations;
public class Ta_Lib
{
private readonly GBM_Feed bars;
private readonly Random rnd = new();
private readonly int period, digits, skip;
private readonly double[] TALIB;
private readonly double[] TALIB2;
private readonly double[] inopen;
private readonly double[] inhigh;
private readonly double[] inlow;
private readonly double[] inclose;
private readonly double[] involume;
public Ta_Lib()
{
bars = new(Bars: 5000, Volatility: 0.8, Drift: 0.0, Precision: 3);
period = rnd.Next(28) + 3;
skip = 500;
digits = 10;
TALIB = new double[bars.Count];
TALIB2 = new double[bars.Count];
inopen = bars.Open.v.ToArray();
inhigh = bars.High.v.ToArray();
inlow = bars.Low.v.ToArray();
inclose = bars.Close.v.ToArray();
involume = bars.Volume.v.ToArray();
}
[Fact]
public void ADD()
{
ADD_Series QL = new(bars.Open, bars.Close);
Core.Add(inopen, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void ADL()
{
ADL_Series QL = new(bars, false);
Core.Ad(inhigh, inlow, inclose, involume, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > 0; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void ADOSC()
{
ADOSC_Series QL = new(bars, 3, 10, false);
Core.AdOsc(inhigh, inlow, inclose, involume, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void ATR()
{
ATR_Series QL = new(bars, period, false);
Core.Atr(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip * 15; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
/*
[Fact]
public void BBANDS()
{
double[] outMiddle = new double[bars.Count];
double[] outUpper = new double[bars.Count];
double[] outLower = new double[bars.Count];
BBANDS_Series QL = new(bars.Close, period: 26, multiplier: 2.0, false);
Core.Bbands(inclose, 0, bars.Count - 1, outRealUpperBand: outUpper, outRealMiddleBand: outMiddle, outRealLowerBand: outLower, out int outBegIdx, out _, optInTimePeriod: 26, optInNbDevUp: 2.0, optInNbDevDn: 2.0);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL.Upper[i].v, digits: digits);
double TA_item = Math.Round(outUpper[i - outBegIdx], digits: digits);
Assert.Equal(TA_item!, QL_item);
QL_item = Math.Round(QL.Mid[i].v, digits: digits);
TA_item = Math.Round(outMiddle[i - outBegIdx], digits: digits);
Assert.Equal(TA_item!, QL_item);
QL_item = Math.Round(QL.Lower[i].v, digits: digits);
TA_item = Math.Round(outLower[i - outBegIdx], digits: digits);
Assert.Equal(TA_item!, QL_item);
}
Assert.Equal(Math.Round(outUpper[outUpper.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Upper.Last().v, digits: digits));
Assert.Equal(Math.Round(outMiddle[outMiddle.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Mid.Last().v, digits: digits));
Assert.Equal(Math.Round(outLower[outLower.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Lower.Last().v, digits: digits));
}
*/
[Fact]
public void CCI()
{
CCI_Series QL = new(bars, period, false);
Core.Cci(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
/*
[Fact]
public void CMO() {
CMO_Series QL = new(bars.Close, period, false);
Core.Cmo(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--) {
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
*/
[Fact]
public void CORR()
{
CORR_Series QL = new(bars.Open, bars.Close, period);
Core.Correl(inopen, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, optInTimePeriod: period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void DEMA()
{
DEMA_Series QL = new(bars.Close, period, false);
Core.Dema(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void DIV()
{
DIV_Series QL = new(bars.Open, bars.Close);
Core.Div(inopen, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void EMA()
{
EMA_Series QL = new(bars.Close, period, false);
Core.Ema(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void HL2()
{
TSeries QL = bars.HL2;
Core.MedPrice(inhigh, inlow, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void HLC3()
{
TSeries QL = bars.HLC3;
Core.TypPrice(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void HLCC4()
{
TSeries QL = bars.HLCC4;
Core.WclPrice(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void MACD()
{
double[] macdSignal = new double[bars.Count];
double[] macdHist = new double[bars.Count];
MACD_Series QL = new(bars.Close, slow: 26, fast: 12, signal: 9, false);
Core.Macd(inclose, 0, bars.Count - 1, outMacd: TALIB, outMacdSignal: macdSignal, outMacdHist: macdHist, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip * 10; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.Equal(TA_item!, QL_item);
QL_item = Math.Round(QL.Signal[i].v, digits: digits);
TA_item = Math.Round(macdSignal[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void MAMA()
{
MAMA_Series QL = new(bars.Close, fastlimit: 0.5, slowlimit: 0.05);
Core.Mama(inReal: inclose, startIdx: 0, endIdx: bars.Count - 1, outMama: TALIB, outFama: TALIB2, outBegIdx: out int outBegIdx, outNbElement: out _, optInFastLimit: 0.5, optInSlowLimit: 0.05);
for (int i = QL.Length - 1; i > skip * 15; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void MAX()
{
MAX_Series QL = new(bars.Close, period, false);
Core.Max(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void MIDPOINT()
{
MIDPOINT_Series QL = new(bars.Close, period, false);
Core.MidPoint(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void MIDPRICE()
{
MIDPRICE_Series QL = new(bars, period, false);
Core.MidPrice(inhigh, inlow, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void MIN()
{
MIN_Series QL = new(bars.Close, period, false);
Core.Min(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void MUL()
{
MUL_Series QL = new(bars.Open, bars.Close);
Core.Mult(inopen, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void OBV()
{
OBV_Series QL = new(bars, period, false);
Core.Obv(inclose, involume, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void OHLC4()
{
TSeries QL = bars.OHLC4;
Core.AvgPrice(inopen, inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void RSI()
{
RSI_Series QL = new(bars.Close, period, false);
Core.Rsi(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void SDEV()
{
SDEV_Series QL = new(bars.Close, period, false);
Core.StdDev(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void SMA()
{
SMA_Series QL = new(bars.Close, period, false);
Core.Sma(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void SUB()
{
SUB_Series QL = new(bars.Open, bars.Close);
Core.Sub(inopen, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void SUM()
{
SUM_Series QL = new(bars.Close, period, false);
Core.Sum(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void T3()
{
T3_Series QL = new(source: bars.Close, period: period, vfactor: 0.7, useNaN: false);
Core.T3(inReal: inclose, startIdx: 0, endIdx: bars.Count - 1, outReal: TALIB, outBegIdx: out int outBegIdx, outNbElement: out _, optInTimePeriod: period, optInVFactor: 0.7);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void TEMA()
{
TEMA_Series QL = new(bars.Close, period, false);
Core.Tema(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip * 15; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void TR()
{
TR_Series QL = new(bars, false);
Core.TRange(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void TRIMA()
{
TRIMA_Series QL = new(bars.Close, period, false);
Core.Trima(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void TRIX() {
TRIX_Series QL = new(bars.Close, period, useNaN: false, useSMA: true);
Core.Trix(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--) {
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void VAR()
{
VAR_Series QL = new(bars.Close, period, false);
Core.Var(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip * 15; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void WMA()
{
WMA_Series QL = new(bars.Close, period, false);
Core.Wma(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL[i].v, digits: digits);
double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits);
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
}
+194 -158
View File
@@ -1,158 +1,194 @@
using Xunit;
using System;
using Tulip;
using QuanTAlib;
namespace Validations;
public class Tulip_Test
{
private readonly GBM_Feed bars;
private readonly Random rnd = new();
private readonly int period, digits, skip;
private readonly double[] outdata;
private readonly double[] inopen;
private readonly double[] inhigh;
private readonly double[] inlow;
private readonly double[] inclose;
private readonly double[] involume;
public Tulip_Test()
{
bars = new(Bars: 5000, Volatility: 0.8, Drift: 0.0, Precision: 3);
period = rnd.Next(28) + 3;
skip = 200;
digits = 10;
outdata = new double[bars.Count];
inopen = bars.Open.v.ToArray();
inhigh = bars.High.v.ToArray();
inlow = bars.Low.v.ToArray();
inclose = bars.Close.v.ToArray()!;
involume = bars.Volume.v.ToArray()!;
}
[Fact]
public void AD()
{
double[][] arrin = {inhigh, inlow, inclose, involume };
double[][] arrout = { outdata };
ADL_Series QL = new(bars, false);
Tulip.Indicators.ad.Run(inputs: arrin, options: new double[] { }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--)
{
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 ADD()
{
double[][] arrin = { inhigh, inlow };
double[][] arrout = { outdata };
ADD_Series QL = new(bars.High, bars.Low);
Tulip.Indicators.add.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--)
{
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 ADOSC()
{
double[][] arrin = { inhigh, inlow, inclose, involume };
double[][] arrout = { outdata };
int s = 3;
ADOSC_Series QL = new(bars, s, period, false);
Tulip.Indicators.adosc.Run(inputs: arrin, options: new double[] { s, period }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--)
{
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 ATR()
{
double[][] arrin = { inhigh, inlow, inclose };
double[][] arrout = { outdata };
ATR_Series QL = new(bars, period, false);
Tulip.Indicators.atr.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--)
{
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 BBANDS()
{
double[][] arrin = { inclose };
double[] outmid = new double[bars.Count];
double[] outlower = new double[bars.Count];
double[] outupper = new double[bars.Count];
double[][] arrout = { outlower, outmid, outupper};
BBANDS_Series QL = new(bars.Close, period, 2, false);
Tulip.Indicators.bbands.Run(inputs: arrin, options: new double[] { period, 2 }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL.Lower[i].v, digits: digits);
double TU_item = Math.Round(outlower[i - period + 1], digits);
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
QL_item = Math.Round(QL.Mid[i].v, digits: digits);
TU_item = Math.Round(outmid[i - period + 1], digits);
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
QL_item = Math.Round(QL.Upper[i].v, digits: digits);
TU_item = Math.Round(outupper[i - period + 1], digits);
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void EMA()
{
double[][] arrin = { inclose };
double[][] arrout = { outdata };
EMA_Series QL = new(bars.Close, period, false);
Tulip.Indicators.ema.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--)
{
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()
{
double[][] arrin = { inopen, inhigh, inlow, inclose };
double[][] arrout = { outdata };
TSeries QL = bars.OHLC4;
Tulip.Indicators.avgprice.Run(inputs: arrin, options: new double[] { }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--)
{
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()
{
double[][] arrin = { inclose };
double[][] arrout = { outdata };
SMA_Series QL = new(bars.Close, period, false);
Tulip.Indicators.sma.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--)
{
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));
}
}
}
using Xunit;
using System;
using Tulip;
using QuanTAlib;
namespace Validations;
public class Tulip_Test
{
private readonly GBM_Feed bars;
private readonly Random rnd = new();
private readonly int period, digits, skip;
private readonly double[] outdata;
private readonly double[] inopen;
private readonly double[] inhigh;
private readonly double[] inlow;
private readonly double[] inclose;
private readonly double[] involume;
public Tulip_Test()
{
bars = new(Bars: 5000, Volatility: 0.8, Drift: 0.0, Precision: 3);
period = rnd.Next(28) + 3;
skip = 200;
digits = 10;
outdata = new double[bars.Count];
inopen = bars.Open.v.ToArray();
inhigh = bars.High.v.ToArray();
inlow = bars.Low.v.ToArray();
inclose = bars.Close.v.ToArray()!;
involume = bars.Volume.v.ToArray()!;
}
[Fact]
public void ADL()
{
double[][] arrin = {inhigh, inlow, inclose, involume };
double[][] arrout = { outdata };
ADL_Series QL = new(bars, false);
Tulip.Indicators.ad.Run(inputs: arrin, options: new double[] { }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--)
{
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 ADD()
{
double[][] arrin = { inhigh, inlow };
double[][] arrout = { outdata };
ADD_Series QL = new(bars.High, bars.Low);
Tulip.Indicators.add.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--)
{
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 ADOSC()
{
double[][] arrin = { inhigh, inlow, inclose, involume };
double[][] arrout = { outdata };
int s = 3;
ADOSC_Series QL = new(bars, s, period, false);
Tulip.Indicators.adosc.Run(inputs: arrin, options: new double[] { s, period }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--)
{
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 ATR()
{
double[][] arrin = { inhigh, inlow, inclose };
double[][] arrout = { outdata };
ATR_Series QL = new(bars, period, false);
Tulip.Indicators.atr.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--)
{
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 BBANDS()
{
double[][] arrin = { inclose };
double[] outmid = new double[bars.Count];
double[] outlower = new double[bars.Count];
double[] outupper = new double[bars.Count];
double[][] arrout = { outlower, outmid, outupper};
BBANDS_Series QL = new(bars.Close, period, 2, false);
Tulip.Indicators.bbands.Run(inputs: arrin, options: new double[] { period, 2 }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = Math.Round(QL.Lower[i].v, digits: digits);
double TU_item = Math.Round(outlower[i - period + 1], digits);
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
QL_item = Math.Round(QL.Mid[i].v, digits: digits);
TU_item = Math.Round(outmid[i - period + 1], digits);
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
QL_item = Math.Round(QL.Upper[i].v, digits: digits);
TU_item = Math.Round(outupper[i - period + 1], digits);
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
}
}
[Fact]
public void DEMA() {
double[][] arrin = { inclose };
double[][] arrout = { outdata };
DEMA_Series QL = new(bars.Close, period, useNaN: false, useSMA: false);
Tulip.Indicators.dema.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--) {
double QL_item = Math.Round(QL[i].v, digits: 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()
{
double[][] arrin = { inclose };
double[][] arrout = { outdata };
EMA_Series QL = new(bars.Close, period, false);
Tulip.Indicators.ema.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--)
{
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()
{
double[][] arrin = { inopen, inhigh, inlow, inclose };
double[][] arrout = { outdata };
TSeries QL = bars.OHLC4;
Tulip.Indicators.avgprice.Run(inputs: arrin, options: new double[] { }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--)
{
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()
{
double[][] arrin = { inclose };
double[][] arrout = { outdata };
SMA_Series QL = new(bars.Close, period, false);
Tulip.Indicators.sma.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--)
{
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 };
double[][] arrout = { outdata };
HMA_Series QL = new(bars.Close, period, false);
Tulip.Indicators.hma.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--) {
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 };
double[][] arrout = { outdata };
CMO_Series QL = new(bars.Close, period, useNaN: false);
Tulip.Indicators.cmo.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
for (int i = QL.Length - 1; i > skip; i--) {
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));
}
}
}