mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-20 11:38:05 +00:00
style: format code with dotnet-format
This commit fixes the style issues introduced in ed45c9e according to the output
from dotnet-format.
Details: None
This commit is contained in:
@@ -7,8 +7,7 @@ using Python.Runtime;
|
||||
|
||||
namespace Validations;
|
||||
|
||||
public class PandasTA : IDisposable
|
||||
{
|
||||
public class PandasTA : IDisposable {
|
||||
private bool disposed = false;
|
||||
private readonly GBM_Feed bars;
|
||||
private readonly Random rnd = new();
|
||||
@@ -19,8 +18,7 @@ public class PandasTA : IDisposable
|
||||
private readonly dynamic pd;
|
||||
private readonly dynamic df;
|
||||
|
||||
public PandasTA()
|
||||
{
|
||||
public PandasTA() {
|
||||
bars = new GBM_Feed(5000, 0.8, 0.0);
|
||||
period = rnd.Next(28) + 3;
|
||||
skip = period + 50;
|
||||
@@ -36,8 +34,7 @@ public class PandasTA : IDisposable
|
||||
|
||||
string[] cols = { "open", "high", "low", "close", "volume" };
|
||||
var ary = new double[bars.Count, 5];
|
||||
for (var i = 0; i < bars.Count; i++)
|
||||
{
|
||||
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;
|
||||
@@ -48,33 +45,27 @@ public class PandasTA : IDisposable
|
||||
df = ta.DataFrame(data: np.array(ary), index: np.array(bars.Close.t), columns: np.array(cols));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
public void Dispose() {
|
||||
Dispose(true);
|
||||
PythonEngine.Shutdown();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
~PandasTA()
|
||||
{
|
||||
~PandasTA() {
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
protected virtual void Dispose(bool disposing) {
|
||||
if (!disposed) {
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void ADL()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -82,12 +73,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void BBANDS()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -101,12 +90,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void BIAS()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -114,12 +101,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void CCI()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -127,12 +112,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void DEMA()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -140,12 +123,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void EMA()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -153,12 +134,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void ENTROPY()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -166,11 +145,9 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void HL2()
|
||||
{
|
||||
private void HL2() {
|
||||
var pta = df.ta.hl2(high: df.high, low: df.low);
|
||||
for (var i = bars.HL2.Length - 1; i > skip; i--)
|
||||
{
|
||||
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));
|
||||
@@ -178,11 +155,9 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void HLC3()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -190,12 +165,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void HMA()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -203,12 +176,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void KURTOSIS()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -216,12 +187,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void MACD()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -232,12 +201,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void MAD()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -245,12 +212,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void MEDIAN()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -258,12 +223,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void OBV()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -271,11 +234,9 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void OHLC4()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -283,12 +244,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void SDEV()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -296,12 +255,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void SMA()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -309,12 +266,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void SSDEV()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -322,12 +277,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void SVARIANCE()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -335,12 +288,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void TEMA()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -348,12 +299,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void TR()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -361,13 +310,11 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void TRIMA()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -375,12 +322,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void VARIANCE()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -388,12 +333,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void WMA()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -401,12 +344,10 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void ZSCORE()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -414,22 +355,15 @@ public class PandasTA : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
public static class PythonLibrary
|
||||
{
|
||||
public static string Locate()
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
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)
|
||||
{
|
||||
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))
|
||||
{
|
||||
if (pythonDLLs.Length > 0) {
|
||||
foreach (string item in pythonDLLs) {
|
||||
if (!item.EndsWith("python3.dll", StringComparison.OrdinalIgnoreCase)) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -437,9 +371,7 @@ public static class PythonLibrary
|
||||
}
|
||||
}
|
||||
throw new FileNotFoundException("Python library not found in PATH");
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) {
|
||||
return "/usr/lib/x86_64-linux-gnu/libpython3.10.so";
|
||||
/*
|
||||
List<string> pythonLibraries = new List<string>();
|
||||
@@ -454,28 +386,17 @@ public static class PythonLibrary
|
||||
throw new FileNotFoundException("Python library not found");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
|
||||
throw new NotSupportedException("Not supported yet");
|
||||
}
|
||||
|
||||
else { throw new NotSupportedException("Unsupported operating system"); }
|
||||
} 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
|
||||
{
|
||||
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)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine("Error searching in directory: " + directory + " - " + e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,23 +4,20 @@ using Skender.Stock.Indicators;
|
||||
using Xunit;
|
||||
|
||||
namespace Validations;
|
||||
public class Skender
|
||||
{
|
||||
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()
|
||||
{
|
||||
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
|
||||
{
|
||||
quotes = bars.Select(q => new Quote {
|
||||
Date = q.t,
|
||||
Open = (decimal)q.o,
|
||||
High = (decimal)q.h,
|
||||
@@ -45,48 +42,40 @@ public class Skender
|
||||
}
|
||||
*/
|
||||
[Fact]
|
||||
public void ALMA()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -108,108 +97,90 @@ public class Skender
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void CCI()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
public void HL2() {
|
||||
TSeries QL = bars.HL2;
|
||||
var SK = quotes.GetBaseQuote(CandlePart.HL2).ToList();
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
public void HLC3() {
|
||||
TSeries QL = bars.HLC3;
|
||||
var SK = quotes.GetBaseQuote(CandlePart.HLC3).ToList();
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -217,25 +188,21 @@ public class Skender
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void KAMA()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -251,12 +218,10 @@ public class Skender
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void MACD()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -266,24 +231,20 @@ public class Skender
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void MAD()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -293,36 +254,30 @@ public class Skender
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void MAPE()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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!;
|
||||
@@ -330,156 +285,130 @@ public class Skender
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void OC2()
|
||||
{
|
||||
public void OC2() {
|
||||
TSeries QL = bars.OC2;
|
||||
var SK = quotes.GetBaseQuote(CandlePart.OC2).ToList();
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
public void OHL3() {
|
||||
TSeries QL = bars.OHL3;
|
||||
var SK = quotes.GetBaseQuote(CandlePart.OHL3).ToList();
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
public void OHLC4() {
|
||||
TSeries QL = bars.OHLC4;
|
||||
var SK = quotes.GetBaseQuote(CandlePart.OHLC4).ToList();
|
||||
for (int i = QL.Length; i > skip; i--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
|
||||
@@ -4,8 +4,7 @@ using TALib;
|
||||
using QuanTAlib;
|
||||
|
||||
namespace Validations;
|
||||
public class Ta_Lib
|
||||
{
|
||||
public class Ta_Lib {
|
||||
private readonly GBM_Feed bars;
|
||||
private readonly Random rnd = new();
|
||||
private readonly int period, digits, skip;
|
||||
@@ -17,8 +16,7 @@ public class Ta_Lib
|
||||
private readonly double[] inclose;
|
||||
private readonly double[] involume;
|
||||
|
||||
public Ta_Lib()
|
||||
{
|
||||
public Ta_Lib() {
|
||||
bars = new(Bars: 5000, Volatility: 0.8, Drift: 0.0, Precision: 3);
|
||||
period = rnd.Next(28) + 3;
|
||||
skip = period + 2;
|
||||
@@ -34,48 +32,40 @@ public class Ta_Lib
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ADD()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -83,15 +73,13 @@ public class Ta_Lib
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BBANDS()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -104,12 +92,10 @@ public class Ta_Lib
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void CCI()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -128,111 +114,93 @@ public class Ta_Lib
|
||||
}
|
||||
*/
|
||||
[Fact]
|
||||
public void CORR()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -256,228 +224,190 @@ public class Ta_Lib
|
||||
}
|
||||
*/
|
||||
[Fact]
|
||||
public void MAX()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
|
||||
@@ -4,8 +4,7 @@ using Tulip;
|
||||
using QuanTAlib;
|
||||
|
||||
namespace Validations;
|
||||
public class Tulip_Test
|
||||
{
|
||||
public class Tulip_Test {
|
||||
private readonly GBM_Feed bars;
|
||||
private readonly Random rnd = new();
|
||||
private readonly int period, digits, skip;
|
||||
@@ -16,8 +15,7 @@ public class Tulip_Test
|
||||
private readonly double[] inclose;
|
||||
private readonly double[] involume;
|
||||
|
||||
public Tulip_Test()
|
||||
{
|
||||
public Tulip_Test() {
|
||||
bars = new(Bars: 5000, Volatility: 0.8, Drift: 0.0, Precision: 3);
|
||||
period = rnd.Next(28) + 3;
|
||||
skip = period + 5;
|
||||
@@ -32,67 +30,58 @@ public class Tulip_Test
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ADL()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
public void BBANDS() {
|
||||
double[][] arrin = { inclose };
|
||||
double[] outmid = new double[bars.Count];
|
||||
double[] outlower = new double[bars.Count];
|
||||
@@ -100,8 +89,7 @@ public class Tulip_Test
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -129,130 +117,112 @@ public class Tulip_Test
|
||||
}
|
||||
*/
|
||||
[Fact]
|
||||
public void CMO()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -260,15 +230,13 @@ public class Tulip_Test
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HMA()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -276,14 +244,12 @@ public class Tulip_Test
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void KAMA()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -291,22 +257,19 @@ public class Tulip_Test
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LINREG()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
public void MACD() {
|
||||
|
||||
double[] outsignal = new double[bars.Count];
|
||||
double[] outhist = new double[bars.Count];
|
||||
@@ -314,205 +277,176 @@ public class Tulip_Test
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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));
|
||||
@@ -533,43 +467,37 @@ public class Tulip_Test
|
||||
}
|
||||
*/
|
||||
[Fact]
|
||||
public void VAR()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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--)
|
||||
{
|
||||
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