mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-22 20:48:04 +00:00
Squash
dotcover s1 .sln s1 s1 s2 s3 s4 s5 s1 s2 x x2 x3 x4 x5 x6 x1 sonarcube cleanup1 sonarcube cleanup2 sonarcube cleanup 3 fixes q q q q q q q q q1 q2 q q1 codacy 1
This commit is contained in:
@@ -1,484 +0,0 @@
|
||||
using Xunit;
|
||||
using System;
|
||||
using QuanTAlib;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.Marshalling;
|
||||
using Python.Runtime;
|
||||
|
||||
namespace Validations;
|
||||
|
||||
public class PandasTA : IDisposable
|
||||
{
|
||||
private bool disposed = false;
|
||||
private readonly GBM_Feed bars;
|
||||
private readonly Random rnd = new();
|
||||
private readonly int period, skip;
|
||||
private readonly int digits;
|
||||
private readonly dynamic np;
|
||||
private readonly dynamic ta;
|
||||
private readonly dynamic pd;
|
||||
private readonly dynamic df;
|
||||
|
||||
public PandasTA()
|
||||
{
|
||||
bars = new GBM_Feed(5000, 0.8, 0.0);
|
||||
period = rnd.Next(28) + 3;
|
||||
skip = period + 50;
|
||||
digits = 8;
|
||||
|
||||
var pythonDLL = PythonLibrary.Locate();
|
||||
Runtime.PythonDLL = pythonDLL;
|
||||
PythonEngine.Initialize();
|
||||
|
||||
np = Py.Import("numpy");
|
||||
pd = Py.Import("pandas");
|
||||
ta = Py.Import("pandas_ta");
|
||||
|
||||
string[] cols = { "open", "high", "low", "close", "volume" };
|
||||
var ary = new double[bars.Count, 5];
|
||||
for (var 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()
|
||||
{
|
||||
Dispose(true);
|
||||
PythonEngine.Shutdown();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
~PandasTA()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private 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 (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void BBANDS()
|
||||
{
|
||||
BBANDS_Series QL = new(bars.Close, period);
|
||||
var pta = df.ta.bbands(close: df.close, length: period).to_numpy();
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL.Lower[i].v;
|
||||
var PanTA_item = (double)pta[i][0]; //lower
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
QL_item = QL.Mid[i].v;
|
||||
PanTA_item = (double)pta[i][1]; //mid
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
QL_item = QL.Upper[i].v;
|
||||
PanTA_item = (double)pta[i][2]; //upper
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void BIAS()
|
||||
{
|
||||
BIAS_Series QL = new(bars.Close, period, false);
|
||||
var pta = df.ta.bias(close: df.close, length: period);
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void CCI()
|
||||
{
|
||||
CCI_Series QL = new(bars, period, false);
|
||||
var pta = df.ta.cci(close: df.close, length: period);
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void DEMA()
|
||||
{
|
||||
DEMA_Series QL = new(bars.Close, period, false);
|
||||
var pta = df.ta.dema(close: df.close, length: period);
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void EMA()
|
||||
{
|
||||
EMA_Series QL = new(bars.Close, period, false);
|
||||
var pta = df.ta.ema(close: df.close, length: period);
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void ENTROPY()
|
||||
{
|
||||
ENTROPY_Series QL = new(bars.Close, period, false);
|
||||
var pta = df.ta.entropy(close: df.close, length: period);
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void HL2()
|
||||
{
|
||||
var pta = df.ta.hl2(high: df.high, low: df.low);
|
||||
for (var i = bars.HL2.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = bars.HL2[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void HLC3()
|
||||
{
|
||||
var pta = df.ta.hlc3(high: df.high, low: df.low, close: df.close);
|
||||
for (var i = bars.HLC3.Length; i > skip; i--)
|
||||
{
|
||||
var QL_item = bars.HLC3[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void HMA()
|
||||
{
|
||||
HMA_Series QL = new(bars.Close, period, false);
|
||||
var pta = df.ta.hma(close: df.close, length: period);
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void KURTOSIS()
|
||||
{
|
||||
KURTOSIS_Series QL = new(bars.Close, period, false);
|
||||
var pta = df.ta.kurtosis(close: df.close, length: period);
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void MACD()
|
||||
{
|
||||
MACD_Series QL = new(bars.Close, 26, 12, 9, false);
|
||||
var pta = df.ta.macd(close: df.close).to_numpy();
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1][0];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
QL_item = QL.Signal[i - 1].v;
|
||||
PanTA_item = (double)pta[i - 1][2];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void MAD()
|
||||
{
|
||||
MAD_Series QL = new(bars.Close, period, false);
|
||||
var pta = df.ta.mad(close: df.close, length: period);
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void MEDIAN()
|
||||
{
|
||||
MEDIAN_Series QL = new(bars.Close, period);
|
||||
var pta = df.ta.median(close: df.close, length: period);
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void OBV()
|
||||
{
|
||||
OBV_Series QL = new(bars);
|
||||
var pta = df.ta.obv(close: df.close, volume: df.volume);
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void OHLC4()
|
||||
{
|
||||
var pta = df.ta.ohlc4(open: df.open, high: df.high, low: df.low, close: df.close);
|
||||
for (var i = bars.OHLC4.Length; i > skip; i--)
|
||||
{
|
||||
var QL_item = bars.OHLC4[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void SDEV()
|
||||
{
|
||||
SDEV_Series QL = new(bars.Close, period, false);
|
||||
var pta = df.ta.stdev(close: df.close, length: period, ddof: 0);
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void SMA()
|
||||
{
|
||||
SMA_Series QL = new(bars.Close, period, false);
|
||||
var pta = df.ta.sma(close: df.close, length: period);
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void SSDEV()
|
||||
{
|
||||
SSDEV_Series QL = new(bars.Close, period, false);
|
||||
var pta = df.ta.stdev(close: df.close, length: period, ddof: 1);
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void SVARIANCE()
|
||||
{
|
||||
SVAR_Series QL = new(bars.Close, period);
|
||||
var pta = df.ta.variance(close: df.close, length: period, ddof: 1);
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void TEMA()
|
||||
{
|
||||
TEMA_Series QL = new(bars.Close, period, false);
|
||||
var pta = df.ta.tema(close: df.close, length: period);
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void TR()
|
||||
{
|
||||
TR_Series QL = new(bars);
|
||||
var pta = df.ta.true_range(high: df.high, low: df.low, close: df.close);
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private 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 (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void VARIANCE()
|
||||
{
|
||||
VAR_Series QL = new(bars.Close, period);
|
||||
var pta = df.ta.variance(close: df.close, length: period, ddof: 0);
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void WMA()
|
||||
{
|
||||
WMA_Series QL = new(bars.Close, period, false);
|
||||
var pta = df.ta.wma(close: df.close, length: period);
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void ZSCORE()
|
||||
{
|
||||
ZSCORE_Series QL = new(bars.Close, period, false);
|
||||
var pta = df.ta.zscore(close: df.close, length: period, ddof: 0);
|
||||
for (var i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
var QL_item = QL[i - 1].v;
|
||||
var PanTA_item = (double)pta[i - 1];
|
||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class PythonLibrary
|
||||
{
|
||||
public static string Locate()
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
string[] paths = Environment.GetEnvironmentVariable("PATH")?.Split(';') ?? Array.Empty<string>();
|
||||
foreach (string path in paths)
|
||||
{
|
||||
string[] pythonDLLs = Directory.GetFiles(path, "python3*.dll");
|
||||
if (pythonDLLs.Length > 0)
|
||||
{
|
||||
foreach (string item in pythonDLLs)
|
||||
{
|
||||
if (!item.EndsWith("python3.dll", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
throw new FileNotFoundException("Python library not found in PATH");
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
return "/usr/lib/x86_64-linux-gnu/libpython3.10.so";
|
||||
/*
|
||||
List<string> pythonLibraries = new List<string>();
|
||||
List<string> directoriesToSearch = new List<string> { "/home/runner/.local/lib" }; // Add more directories as needed
|
||||
string filePattern = "libpython3.*.so";
|
||||
SearchFiles(directoriesToSearch, filePattern, pythonLibraries);
|
||||
|
||||
if (pythonLibraries.Count > 0) {
|
||||
return pythonLibraries[0];
|
||||
}
|
||||
else {
|
||||
throw new FileNotFoundException("Python library not found");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
throw new NotSupportedException("Not supported yet");
|
||||
}
|
||||
|
||||
else { throw new NotSupportedException("Unsupported operating system"); }
|
||||
}
|
||||
static void SearchFiles(List<string> directoriesToSearch, string filePattern, List<string> foundFiles)
|
||||
{
|
||||
foreach (string directory in directoriesToSearch)
|
||||
{
|
||||
if (Directory.Exists(directory))
|
||||
{
|
||||
try
|
||||
{
|
||||
string[] files = Directory.GetFiles(directory, filePattern, SearchOption.AllDirectories);
|
||||
foundFiles.AddRange(files);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Error searching in directory: " + directory + " - " + e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,489 +0,0 @@
|
||||
using System;
|
||||
using QuanTAlib;
|
||||
using Skender.Stock.Indicators;
|
||||
using Xunit;
|
||||
|
||||
namespace Validations;
|
||||
public class Skender
|
||||
{
|
||||
private readonly GBM_Feed bars;
|
||||
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;
|
||||
digits = 6; //minimizing rounding errors in type conversions
|
||||
skip = period + 2;
|
||||
|
||||
quotes = bars.Select(q => new Quote
|
||||
{
|
||||
Date = q.t,
|
||||
Open = (decimal)q.o,
|
||||
High = (decimal)q.h,
|
||||
Low = (decimal)q.l,
|
||||
Close = (decimal)q.c,
|
||||
Volume = (decimal)q.v
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
[Fact]
|
||||
public void ADL()
|
||||
{
|
||||
ADL_Series QL = new(bars);
|
||||
var SK = quotes.GetAdl().Select(i => i.Adl);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1)!;
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits));
|
||||
}
|
||||
}
|
||||
*/
|
||||
[Fact]
|
||||
public void ALMA()
|
||||
{
|
||||
ALMA_Series QL = new(bars.Close, period, useNaN: false);
|
||||
var SK = quotes.GetAlma(period).Select(i => i.Alma.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void ATR()
|
||||
{
|
||||
ATR_Series QL = new(bars, period: period, useNaN: false);
|
||||
var SK = quotes.GetAtr(period).Select(i => i.Atr.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void ATRP()
|
||||
{
|
||||
ATRP_Series QL = new(bars, period, false);
|
||||
var SK = quotes.GetAtr(period).Select(i => i.Atrp.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void BBANDS()
|
||||
{
|
||||
BBANDS_Series QL = new(bars.Close, period, 2.0, useNaN: false);
|
||||
var SK = quotes.GetBollingerBands(period, 2.0);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL.Mid[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1).Sma!.Value;
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
QL_item = QL.Upper[i - 1].v;
|
||||
SK_item = SK.ElementAt(i - 1).UpperBand!.Value;
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
QL_item = QL.Lower[i - 1].v;
|
||||
SK_item = SK.ElementAt(i - 1).LowerBand!.Value;
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
QL_item = QL.Bandwidth[i - 1].v;
|
||||
SK_item = SK.ElementAt(i - 1).Width!.Value;
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
QL_item = QL.PercentB[i - 1].v;
|
||||
SK_item = SK.ElementAt(i - 1).PercentB!.Value;
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
QL_item = QL.Zscore[i - 1].v;
|
||||
SK_item = SK.ElementAt(i - 1).ZScore!.Value;
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void CCI()
|
||||
{
|
||||
CCI_Series QL = new(bars, period, false);
|
||||
var SK = quotes.GetCci(period).Select(i => i.Cci.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[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 = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void CORR()
|
||||
{
|
||||
CORR_Series QL = new(bars.High, bars.Low, period, false);
|
||||
var SK = quotes.Use(CandlePart.High).GetCorrelation(quotes.Use(CandlePart.Low), period).Select(i => i.Correlation.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void COVAR()
|
||||
{
|
||||
COVAR_Series QL = new(bars.High, bars.Low, period, false);
|
||||
var SK = quotes.Use(CandlePart.High).GetCorrelation(quotes.Use(CandlePart.Low), period).Select(i => i.Covariance.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void DEMA()
|
||||
{
|
||||
DEMA_Series QL = new(bars.Close, period, false, useSMA: true);
|
||||
var SK = quotes.GetDema(period).Select(i => i.Dema.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void EMA()
|
||||
{
|
||||
EMA_Series QL = new(bars.Close, period, false);
|
||||
var SK = quotes.GetEma(lookbackPeriods: period).Select(i => i.Ema.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void HL2()
|
||||
{
|
||||
TSeries QL = bars.HL2;
|
||||
var SK = quotes.GetBaseQuote(CandlePart.HL2).ToList();
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1).Value;
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void HLC3()
|
||||
{
|
||||
TSeries QL = bars.HLC3;
|
||||
var SK = quotes.GetBaseQuote(CandlePart.HLC3).ToList();
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1).Value;
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void HMA()
|
||||
{
|
||||
HMA_Series QL = new(bars.Close, period, useNaN: false);
|
||||
var SK = quotes.GetHma(period).Select(i => i.Hma.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip * 2; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void KAMA()
|
||||
{
|
||||
// TODO: check precision of KAMA()
|
||||
KAMA_Series QL = new(bars.Close, period, useNaN: false);
|
||||
var SK = quotes.GetKama(period).Select(i => i.Kama.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip + 2; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void SLOPE()
|
||||
{
|
||||
SLOPE_Series QL = new(bars.Close, period, useNaN: false);
|
||||
var SK = quotes.GetSlope(period);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = (double)SK.ElementAt(i - 1).Slope!;
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
QL_item = QL.Intercept[i - 1].v;
|
||||
SK_item = (double)SK.ElementAt(i - 1).Intercept!;
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
QL_item = QL.RSquared[i - 1].v;
|
||||
SK_item = (double)SK.ElementAt(i - 1).RSquared!;
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
QL_item = QL.StdDev[i - 1].v;
|
||||
SK_item = (double)SK.ElementAt(i - 1).StdDev!;
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void MACD()
|
||||
{
|
||||
MACD_Series QL = new(bars.Close, 26, 12, 9, useNaN: false);
|
||||
var SK = quotes.GetMacd(12, 26, 9);
|
||||
for (int i = QL.Length; i > 27; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1).Macd.Null2NaN()!;
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
//QL_item = QL.Signal[i - 1].v;
|
||||
//SK_item = SK.ElementAt(i - 1).Signal.Null2NaN()!;
|
||||
//Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void MAD()
|
||||
{
|
||||
MAD_Series QL = new(bars.Close, period, false);
|
||||
var SK = quotes.GetSmaAnalysis(period).Select(i => i.Mad.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void MAMA()
|
||||
{
|
||||
MAMA_Series QL = new(bars.HL2, fastlimit: 0.5, slowlimit: 0.05);
|
||||
var SK = quotes.GetMama(fastLimit: 0.5, slowLimit: 0.05);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1).Mama.Null2NaN()!;
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
QL_item = QL.Fama[i - 1].v;
|
||||
SK_item = SK.ElementAt(i - 1).Fama.Null2NaN()!;
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void MAPE()
|
||||
{
|
||||
MAPE_Series QL = new(bars.Close, period, false);
|
||||
var SK = quotes.GetSmaAnalysis(period).Select(i => i.Mape.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void MSE()
|
||||
{
|
||||
MSE_Series QL = new(bars.Close, period, false);
|
||||
var SK = quotes.GetSmaAnalysis(period).Select(i => i.Mse.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void OBV()
|
||||
{
|
||||
OBV_Series QL = new(bars, period, false);
|
||||
var SK = quotes.GetObv(period).Select(i => i.Obv!);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL.Last().v;
|
||||
// adding volume[0] to OBV to pass the test and keep compatibility with TA-LIB
|
||||
double SK_item = SK.Last()! + (double)quotes.First().Volume!;
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void OC2()
|
||||
{
|
||||
TSeries QL = bars.OC2;
|
||||
var SK = quotes.GetBaseQuote(CandlePart.OC2).ToList();
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1).Value;
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void OHL3()
|
||||
{
|
||||
TSeries QL = bars.OHL3;
|
||||
var SK = quotes.GetBaseQuote(CandlePart.OHL3).ToList();
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1).Value;
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void OHLC4()
|
||||
{
|
||||
TSeries QL = bars.OHLC4;
|
||||
var SK = quotes.GetBaseQuote(CandlePart.OHLC4).ToList();
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1).Value;
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void RSI()
|
||||
{
|
||||
RSI_Series QL = new(bars.Close, period, useNaN: false);
|
||||
var SK = quotes.GetRsi(period).Select(i => i.Rsi.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void SDEV()
|
||||
{
|
||||
SDEV_Series QL = new(bars.Close, period, useNaN: false);
|
||||
var SK = quotes.GetStdDev(period).Select(i => i.StdDev.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void SMA()
|
||||
{
|
||||
SMA_Series QL = new(bars.Close, period, false);
|
||||
var SK = quotes.GetSma(period).Select(i => i.Sma.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void SMMA()
|
||||
{
|
||||
SMMA_Series QL = new(bars.Close, period, useNaN: false);
|
||||
var SK = quotes.GetSmma(period).Select(i => i.Smma.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void T3()
|
||||
{
|
||||
T3_Series QL = new(source: bars.Close, period: period, vfactor: 0.7, false);
|
||||
var SK = quotes.GetT3(lookbackPeriods: period, volumeFactor: 0.7).Select(i => i.T3.Null2NaN()!);
|
||||
for (int i = QL.Length; i > period * 15; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void TRIX()
|
||||
{
|
||||
TRIX_Series QL = new(bars.Close, period, false);
|
||||
var SK = quotes.GetTrix(period).Select(i => i.Trix.Null2NaN()!);
|
||||
for (int i = QL.Length; i > period * 12; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void TEMA()
|
||||
{
|
||||
TEMA_Series QL = new(bars.Close, period, false);
|
||||
var SK = quotes.GetTema(period).Select(i => i.Tema.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void TR()
|
||||
{
|
||||
TR_Series QL = new(bars);
|
||||
var SK = quotes.GetTr().Select(i => i.Tr.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void WMA()
|
||||
{
|
||||
WMA_Series QL = new(bars.Close, period, false);
|
||||
var SK = quotes.GetWma(period).Select(i => i.Wma.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip * 2; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void ZSCORE()
|
||||
{
|
||||
ZSCORE_Series QL = new(bars.Close, period, useNaN: false);
|
||||
var SK = quotes.GetStdDev(period).Select(i => i.ZScore.Null2NaN()!);
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i - 1].v;
|
||||
double SK_item = SK.ElementAt(i - 1);
|
||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10, -digits), Math.Pow(10, -digits));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,487 +0,0 @@
|
||||
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 = period + 2;
|
||||
digits = 9;
|
||||
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void ADL()
|
||||
{
|
||||
ADL_Series QL = new(bars);
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 * 2; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void ATR()
|
||||
{
|
||||
ATR_Series QL = new(bars, period: period, useNaN: false);
|
||||
Core.Atr(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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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: period, multiplier: 2.0, false);
|
||||
Core.Bbands(inclose, 0, bars.Count - 1, outRealUpperBand: outUpper, outRealMiddleBand: outMiddle, outRealLowerBand: outLower, out int outBegIdx, out _, optInTimePeriod: period, optInNbDevUp: 2.0, optInNbDevDn: 2.0);
|
||||
for (int i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL.Upper[i].v;
|
||||
double TA_item = outUpper[i - outBegIdx];
|
||||
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), high: Math.Exp(-digits));
|
||||
QL_item = QL.Mid[i].v;
|
||||
TA_item = outMiddle[i - outBegIdx];
|
||||
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), high: Math.Exp(-digits));
|
||||
QL_item = QL.Lower[i].v;
|
||||
TA_item = outLower[i - outBegIdx];
|
||||
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), high: Math.Exp(-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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
/* CMO in TA-LIB is not valid
|
||||
[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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void DEMA()
|
||||
{
|
||||
DEMA_Series QL = new(bars.Close, period, false, useSMA: false);
|
||||
Core.Dema(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
|
||||
for (int i = QL.Length - 1; i > period * 10; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void KAMA()
|
||||
{
|
||||
KAMA_Series QL = new(bars.Close, period, fast: 2, slow: 30);
|
||||
Core.Kama(inReal: inclose, startIdx: 0, endIdx: bars.Count - 1, outReal: TALIB, outBegIdx: out int outBegIdx, outNbElement: out _, optInTimePeriod: period);
|
||||
for (int i = QL.Length - 1; i > skip * 15; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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);
|
||||
// TA-LIB runs EMA without SMA, leaving first 100 values for convergence
|
||||
Core.Macd(inclose, 0, bars.Count - 1, outMacd: TALIB, outMacdSignal: macdSignal, outMacdHist: macdHist, out int outBegIdx, out _, optInFastPeriod: 12, optInSlowPeriod: 26, optInSignalPeriod: 9);
|
||||
for (int i = QL.Length - 1; i > 100; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
QL_item = QL.Signal[i].v;
|
||||
TA_item = macdSignal[i - outBegIdx];
|
||||
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 * 10; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits-1), Math.Exp(-digits-1));
|
||||
}
|
||||
}
|
||||
*/
|
||||
[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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void SUM()
|
||||
{
|
||||
CUSUM_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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 > period * 10; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void TR()
|
||||
{
|
||||
TR_Series QL = new(bars);
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 > period * 10; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
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 = QL[i].v;
|
||||
double TA_item = TALIB[i - outBegIdx];
|
||||
Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,578 +0,0 @@
|
||||
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 = period + 5;
|
||||
digits = 8;
|
||||
|
||||
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);
|
||||
Tulip.Indicators.ad.Run(inputs: arrin, options: new double[] { }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i];
|
||||
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 = QL[i].v;
|
||||
double TU_item = arrout[0][i];
|
||||
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 = QL[i].v;
|
||||
double TU_item = arrout[0][i - period + 1];
|
||||
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: period, useNaN: false);
|
||||
Tulip.Indicators.atr.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
//Tulip ATR doesn't use warm-up SMA, compensating with 200 warming bars
|
||||
for (int i = QL.Length - 1; i > 200 + skip; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i - period + 1];
|
||||
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 = QL.Lower[i].v;
|
||||
double TU_item = outlower[i - period + 1];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
QL_item = QL.Mid[i].v;
|
||||
TU_item = outmid[i - period + 1];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
QL_item = QL.Upper[i].v;
|
||||
TU_item = outupper[i - period + 1];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
/*
|
||||
[Fact]
|
||||
public void CCI() {
|
||||
double[][] arrin = { inhigh, inlow, inclose };
|
||||
double[][] arrout = { outdata };
|
||||
CCI_Series QL = new(bars, period, useNaN: false);
|
||||
Tulip.Indicators.cci.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip; i--) {
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = outdata[i - period + 1];
|
||||
Assert.Equal(QL_item,TU_item);
|
||||
//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 = QL[i].v;
|
||||
double TU_item = arrout[0][i - period];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void DECAY()
|
||||
{
|
||||
double[][] arrin = { inclose };
|
||||
double[][] arrout = { outdata };
|
||||
DECAY_Series QL = new(bars.Close, period, useNaN: false);
|
||||
Tulip.Indicators.decay.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip + 200; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i];
|
||||
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 + 200; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i - (period + period - 2)];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void DIV()
|
||||
{
|
||||
double[][] arrin = { inhigh, inlow };
|
||||
double[][] arrout = { outdata };
|
||||
DIV_Series QL = new(bars.High, bars.Low);
|
||||
Tulip.Indicators.div.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void EDECAY()
|
||||
{
|
||||
double[][] arrin = { inclose };
|
||||
double[][] arrout = { outdata };
|
||||
DECAY_Series QL = new(bars.Close, period, exponential: true, useNaN: false);
|
||||
Tulip.Indicators.edecay.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip + 200; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void EMA()
|
||||
{
|
||||
double[][] arrin = { inclose };
|
||||
double[][] arrout = { outdata };
|
||||
// Tulip EMA doesn't use SMA to warm-up
|
||||
EMA_Series QL = new(bars.Close, period, false, useSMA: 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 = QL[i].v;
|
||||
double TU_item = arrout[0][i];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void HL2()
|
||||
{
|
||||
double[][] arrin = { inhigh, inlow };
|
||||
double[][] arrout = { outdata };
|
||||
|
||||
TSeries QL = bars.HL2;
|
||||
Tulip.Indicators.medprice.Run(inputs: arrin, options: new double[] { }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void HLC3()
|
||||
{
|
||||
double[][] arrin = { inhigh, inlow, inclose };
|
||||
double[][] arrout = { outdata };
|
||||
|
||||
TSeries QL = bars.HLC3;
|
||||
Tulip.Indicators.typprice.Run(inputs: arrin, options: new double[] { }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void HLCC4()
|
||||
{
|
||||
double[][] arrin = { inhigh, inlow, inclose };
|
||||
double[][] arrout = { outdata };
|
||||
|
||||
TSeries QL = bars.HLCC4;
|
||||
Tulip.Indicators.wcprice.Run(inputs: arrin, options: new double[] { }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HMA()
|
||||
{
|
||||
int p = 10;
|
||||
double[][] arrin = { inclose };
|
||||
double[][] arrout = { outdata };
|
||||
HMA_Series QL = new(bars.Close, p, false);
|
||||
Tulip.Indicators.hma.Run(inputs: arrin, options: new double[] { p }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip + 2; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i - p - 1];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits - 2), Math.Exp(-digits - 2));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void KAMA()
|
||||
{
|
||||
double[][] arrin = { inclose };
|
||||
double[][] arrout = { outdata };
|
||||
KAMA_Series QL = new(bars.Close, period);
|
||||
Tulip.Indicators.kama.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > 250; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i - period + 1];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LINREG()
|
||||
{
|
||||
double[][] arrin = { inclose };
|
||||
double[][] arrout = { outdata };
|
||||
SLOPE_Series QL = new(bars.Close, period);
|
||||
Tulip.Indicators.linregslope.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i - period + 1];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void MACD()
|
||||
{
|
||||
|
||||
double[] outsignal = new double[bars.Count];
|
||||
double[] outhist = new double[bars.Count];
|
||||
double[][] arrin = { inclose };
|
||||
double[][] arrout = { outdata, outsignal, outhist };
|
||||
MACD_Series QL = new(bars.Close, slow: 26, fast: 10, signal: 9);
|
||||
Tulip.Indicators.macd.Run(inputs: arrin, options: new double[] { 10, 26, 9 }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > 150; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = outdata[i - 26 + 1];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void MAX()
|
||||
{
|
||||
double[][] arrin = { inclose };
|
||||
double[][] arrout = { outdata };
|
||||
MAX_Series QL = new(bars.Close, period, false);
|
||||
Tulip.Indicators.max.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i - period + 1];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void MIN()
|
||||
{
|
||||
double[][] arrin = { inclose };
|
||||
double[][] arrout = { outdata };
|
||||
MIN_Series QL = new(bars.Close, period, false);
|
||||
Tulip.Indicators.min.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i - period + 1];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void MUL()
|
||||
{
|
||||
double[][] arrin = { inhigh, inlow };
|
||||
double[][] arrout = { outdata };
|
||||
MUL_Series QL = new(bars.High, bars.Low);
|
||||
Tulip.Indicators.mul.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void OBV()
|
||||
{
|
||||
double[][] arrin = { inclose, involume };
|
||||
double[][] arrout = { outdata };
|
||||
OBV_Series QL = new(bars, period, false);
|
||||
Tulip.Indicators.obv.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i] + arrin[1][0];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void OHLC4()
|
||||
{
|
||||
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 = QL[i].v;
|
||||
double TU_item = arrout[0][i];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void RMA()
|
||||
{
|
||||
double[][] arrin = { inclose };
|
||||
double[][] arrout = { outdata };
|
||||
RMA_Series QL = new(bars.Close, period, false);
|
||||
Tulip.Indicators.wilders.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i - period + 1];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void RSI()
|
||||
{
|
||||
double[][] arrin = { inclose };
|
||||
double[][] arrout = { outdata };
|
||||
RSI_Series QL = new(bars.Close, period, false);
|
||||
Tulip.Indicators.rsi.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i - period];
|
||||
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 = QL[i].v;
|
||||
double TU_item = arrout[0][i - period + 1];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void SDEV()
|
||||
{
|
||||
double[][] arrin = { inclose };
|
||||
double[][] arrout = { outdata };
|
||||
SDEV_Series QL = new(bars.Close, period, false);
|
||||
Tulip.Indicators.stddev.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i - period + 1];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void SUB()
|
||||
{
|
||||
double[][] arrin = { inhigh, inlow };
|
||||
double[][] arrout = { outdata };
|
||||
SUB_Series QL = new(bars.High, bars.Low);
|
||||
Tulip.Indicators.sub.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void SUM()
|
||||
{
|
||||
double[][] arrin = { inclose };
|
||||
double[][] arrout = { outdata };
|
||||
CUSUM_Series QL = new(bars.Close, period, false);
|
||||
Tulip.Indicators.sum.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i - period + 1];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void TR()
|
||||
{
|
||||
double[][] arrin = { inhigh, inlow, inclose };
|
||||
double[][] arrout = { outdata };
|
||||
TR_Series QL = new(bars);
|
||||
Tulip.Indicators.tr.Run(inputs: arrin, options: new double[] { }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void TEMA()
|
||||
{
|
||||
double[][] arrin = { inclose };
|
||||
double[][] arrout = { outdata };
|
||||
TEMA_Series QL = new(bars.Close, period, false);
|
||||
Tulip.Indicators.tema.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip + 200; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i - (period - 1) * 3];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void TRIMA()
|
||||
{
|
||||
double[][] arrin = { inclose };
|
||||
double[][] arrout = { outdata };
|
||||
TRIMA_Series QL = new(bars.Close, period, false);
|
||||
Tulip.Indicators.trima.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i - period + 1];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
/*
|
||||
[Fact]
|
||||
public void TRIX() {
|
||||
double[][] arrin = { inclose };
|
||||
double[][] arrout = { outdata };
|
||||
TRIX_Series QL = new(bars.Close, period);
|
||||
Tulip.Indicators.trix.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > period+200; i--) {
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i - (period*3) + 2];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits+2), Math.Exp(-digits+2));
|
||||
}
|
||||
}
|
||||
*/
|
||||
[Fact]
|
||||
public void VAR()
|
||||
{
|
||||
double[][] arrin = { inclose };
|
||||
double[][] arrout = { outdata };
|
||||
VAR_Series QL = new(bars.Close, period, false);
|
||||
Tulip.Indicators.var.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i - period + 1];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void WMA()
|
||||
{
|
||||
double[][] arrin = { inclose };
|
||||
double[][] arrout = { outdata };
|
||||
WMA_Series QL = new(bars.Close, period, false);
|
||||
Tulip.Indicators.wma.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = arrout[0][i - period + 1];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void ZLEMA()
|
||||
{
|
||||
int p = 4;
|
||||
double[][] arrin = { inclose };
|
||||
double[][] arrout = { outdata };
|
||||
ZLEMA_Series QL = new(bars.Close, p, false);
|
||||
Tulip.Indicators.zlema.Run(inputs: arrin, options: new double[] { p }, outputs: arrout);
|
||||
for (int i = QL.Length - 1; i > skip + 20; i--)
|
||||
{
|
||||
double QL_item = QL[i].v;
|
||||
double TU_item = outdata[i];
|
||||
Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits - 2), Math.Exp(-digits - 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user