mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-22 12:38:06 +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,156 +0,0 @@
|
||||
using Xunit;
|
||||
using System;
|
||||
using QuanTAlib;
|
||||
|
||||
namespace Basics;
|
||||
#nullable disable
|
||||
public class Indicators
|
||||
{
|
||||
private static Type[] maSeriesTypes = new Type[]
|
||||
{
|
||||
typeof(SMA_Series),
|
||||
typeof(EMA_Series),
|
||||
typeof(DEMA_Series),
|
||||
typeof(TEMA_Series),
|
||||
typeof(WMA_Series),
|
||||
typeof(ALMA_Series),
|
||||
typeof(DWMA_Series),
|
||||
typeof(FWMA_Series),
|
||||
typeof(HMA_Series),
|
||||
typeof(ZLEMA_Series),
|
||||
typeof(RMA_Series),
|
||||
typeof(HEMA_Series),
|
||||
typeof(JMA_Series),
|
||||
typeof(CUSUM_Series),
|
||||
typeof(SMMA_Series),
|
||||
typeof(T3_Series),
|
||||
typeof(KAMA_Series),
|
||||
typeof(TRIMA_Series),
|
||||
typeof(MAMA_Series),
|
||||
typeof(HWMA_Series),
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Name_exists(Type classType)
|
||||
{
|
||||
TSeries data = new("Data") { 1, 2, 3 };
|
||||
|
||||
var MA_Series = Activator.CreateInstance(classType, data, 5, false) as TSeries;
|
||||
Assert.NotEmpty(MA_Series.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Series_Length(Type classType)
|
||||
{
|
||||
GBM_Feed feed = new(1000);
|
||||
TSeries data = feed.OHLC4;
|
||||
|
||||
var MA_Series = Activator.CreateInstance(classType, data, 5, false) as TSeries;
|
||||
Assert.Equal(1000, MA_Series.Count);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Return_data(Type classType)
|
||||
{
|
||||
TSeries data = new() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
||||
|
||||
var MA_Series = Activator.CreateInstance(classType, data, 5, false) as TSeries;
|
||||
var result = MA_Series.Add(20);
|
||||
Assert.Equal(result.v, MA_Series.Last.v);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Update(Type classType)
|
||||
{
|
||||
TSeries data = new() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
||||
|
||||
var MA_Series = Activator.CreateInstance(classType, data, 5, false) as TSeries;
|
||||
var pre_update = MA_Series.Last.v;
|
||||
|
||||
double pre_data = data.Last.v;
|
||||
data.Add(20, true);
|
||||
data.Add(pre_data, true);
|
||||
|
||||
Assert.Equal(pre_update, MA_Series.Last.v);
|
||||
Assert.Equal(data.Count, MA_Series.Count);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Period_zero(Type classType)
|
||||
{
|
||||
GBM_Feed feed = new(100);
|
||||
TSeries data = feed.OHLC4;
|
||||
|
||||
var MA_Series = Activator.CreateInstance(classType, data, 0, false) as TSeries;
|
||||
Assert.Equal(data.Count, MA_Series.Count);
|
||||
Assert.False(double.IsNaN(MA_Series.Last.v));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Reset(Type classType)
|
||||
{
|
||||
GBM_Feed feed = new(10);
|
||||
TSeries data = feed.OHLC4;
|
||||
var MA_Series = Activator.CreateInstance(classType, data, 10, false) as TSeries;
|
||||
MA_Series.Reset();
|
||||
data.Add(0);
|
||||
Assert.Equal(data.Last.v, MA_Series.Last.v);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Period_one(Type classType)
|
||||
{
|
||||
GBM_Feed feed = new(100);
|
||||
TSeries data = feed.OHLC4;
|
||||
|
||||
var MA_Series = Activator.CreateInstance(classType, data, 1, false) as TSeries;
|
||||
Assert.InRange(MA_Series.Last.v - data.Last.v, -10e-6, 10e-6);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void NaN_test(Type classType)
|
||||
{
|
||||
GBM_Feed feed = new(100);
|
||||
TSeries data = feed.OHLC4;
|
||||
|
||||
var MA_Series = Activator.CreateInstance(classType, data, 10, true) as TSeries;
|
||||
Assert.True(double.IsNaN(MA_Series[0].v));
|
||||
Assert.True(double.IsNaN(MA_Series[8].v));
|
||||
Assert.False(double.IsNaN(MA_Series[9].v));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Edge_numbers(Type classType)
|
||||
{
|
||||
TSeries data = new() { double.Epsilon, double.PositiveInfinity, double.MaxValue, double.NegativeInfinity };
|
||||
var MA_Series = Activator.CreateInstance(classType, data, 10, true) as TSeries;
|
||||
Assert.Equal(4, MA_Series.Count);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void handling_NaN(Type classType)
|
||||
{
|
||||
TSeries data = new("Name") { 1, 2, 3, 4, 5, 6, double.NaN, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
|
||||
var MA_Series = Activator.CreateInstance(classType, data, 10, true) as TSeries;
|
||||
Assert.False(double.IsNaN(MA_Series.Last.v));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> MASeriesData()
|
||||
{
|
||||
foreach (var type in maSeriesTypes)
|
||||
{
|
||||
yield return new object[] { type };
|
||||
}
|
||||
}
|
||||
}
|
||||
#nullable restore
|
||||
@@ -1,161 +0,0 @@
|
||||
using Xunit;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using QuanTAlib;
|
||||
|
||||
namespace Basics;
|
||||
#nullable disable
|
||||
public class Oscillators
|
||||
{
|
||||
private static Type[] maSeriesTypes = new[]
|
||||
{
|
||||
typeof(BIAS_Series),
|
||||
typeof(MAX_Series),
|
||||
typeof(MIN_Series),
|
||||
typeof(MIDPOINT_Series),
|
||||
typeof(ZL_Series),
|
||||
typeof(DECAY_Series),
|
||||
typeof(ENTROPY_Series),
|
||||
typeof(KURTOSIS_Series),
|
||||
typeof(MAD_Series),
|
||||
typeof(MAPE_Series),
|
||||
typeof(MAE_Series),
|
||||
typeof(MSE_Series),
|
||||
typeof(SDEV_Series),
|
||||
typeof(SMAPE_Series),
|
||||
typeof(WMAPE_Series),
|
||||
typeof(SSDEV_Series),
|
||||
typeof(VAR_Series),
|
||||
typeof(SVAR_Series),
|
||||
typeof(MEDIAN_Series),
|
||||
typeof(ZSCORE_Series),
|
||||
typeof(CMO_Series),
|
||||
typeof(RSI_Series),
|
||||
typeof(TRIX_Series),
|
||||
typeof(BBANDS_Series),
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Name_exists(Type classType)
|
||||
{
|
||||
TSeries data = new("Data") { 1, 2, 3 };
|
||||
|
||||
var MA_Series = Activator.CreateInstance(classType, data, 5, false) as TSeries;
|
||||
Assert.NotEmpty(MA_Series.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Series_Length(Type classType)
|
||||
{
|
||||
GBM_Feed feed = new(1000);
|
||||
TSeries data = feed.OHLC4;
|
||||
|
||||
var MA_Series = Activator.CreateInstance(classType, data, 5, false) as TSeries;
|
||||
Assert.Equal(1000, MA_Series.Count);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Return_data(Type classType)
|
||||
{
|
||||
TSeries data = new() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
||||
|
||||
var MA_Series = Activator.CreateInstance(classType, data, 5, false) as TSeries;
|
||||
var result = MA_Series.Add(20);
|
||||
Assert.Equal(result.v, MA_Series.Last.v);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Update(Type classType)
|
||||
{
|
||||
TSeries data = new() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
||||
|
||||
var MA_Series = Activator.CreateInstance(classType, data, 5, false) as TSeries;
|
||||
var pre_update = MA_Series.Last.v;
|
||||
|
||||
double pre_data = data.Last.v;
|
||||
data.Add(20, true);
|
||||
data.Add(pre_data, true);
|
||||
|
||||
Assert.Equal(pre_update, MA_Series.Last.v);
|
||||
Assert.Equal(data.Count, MA_Series.Count);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Period_zero(Type classType)
|
||||
{
|
||||
GBM_Feed feed = new(100);
|
||||
TSeries data = feed.OHLC4;
|
||||
|
||||
var MA_Series = Activator.CreateInstance(classType, data, 0, false) as TSeries;
|
||||
Assert.Equal(data.Count, MA_Series.Count);
|
||||
Assert.False(double.IsNaN(MA_Series.Last.v));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Reset(Type classType)
|
||||
{
|
||||
GBM_Feed feed = new(10);
|
||||
TSeries data = feed.OHLC4;
|
||||
var MA_Series = Activator.CreateInstance(classType, data, 10, false) as TSeries;
|
||||
MA_Series.Reset();
|
||||
data.Add(1);
|
||||
Assert.False(double.IsNaN(MA_Series.Last.v));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Period_one(Type classType)
|
||||
{
|
||||
GBM_Feed feed = new(100);
|
||||
TSeries data = feed.OHLC4;
|
||||
|
||||
var MA_Series = Activator.CreateInstance(classType, data, 1, false) as TSeries;
|
||||
Assert.False(double.IsNaN(MA_Series[^1].v));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void NaN_test(Type classType)
|
||||
{
|
||||
GBM_Feed feed = new(100);
|
||||
TSeries data = feed.OHLC4;
|
||||
|
||||
var MA_Series = Activator.CreateInstance(classType, data, 10, true) as TSeries;
|
||||
Assert.True(double.IsNaN(MA_Series[0].v));
|
||||
Assert.True(double.IsNaN(MA_Series[8].v));
|
||||
Assert.False(double.IsNaN(MA_Series[9].v));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Edge_numbers(Type classType)
|
||||
{
|
||||
TSeries data = new() { double.Epsilon, double.PositiveInfinity, double.MaxValue, double.NegativeInfinity };
|
||||
var MA_Series = Activator.CreateInstance(classType, data, 10, true) as TSeries;
|
||||
Assert.Equal(4, MA_Series.Count);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void handling_NaN(Type classType)
|
||||
{
|
||||
TSeries data = new("Name") { 1, 2, 3, 4, 5, 6, double.NaN, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
|
||||
var MA_Series = Activator.CreateInstance(classType, data, 10, true) as TSeries;
|
||||
Assert.False(double.IsNaN(MA_Series.Last.v));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> MASeriesData()
|
||||
{
|
||||
foreach (var type in maSeriesTypes)
|
||||
{
|
||||
yield return new object[] { type };
|
||||
}
|
||||
}
|
||||
}
|
||||
#nullable restore
|
||||
@@ -1,97 +0,0 @@
|
||||
using Xunit;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using QuanTAlib;
|
||||
|
||||
namespace Basics;
|
||||
#nullable disable
|
||||
public class TBars
|
||||
{
|
||||
private static Type[] maSeriesTypes = new Type[]
|
||||
{
|
||||
typeof(ATR_Series),
|
||||
typeof(ATRP_Series),
|
||||
typeof(TR_Series),
|
||||
typeof(ADL_Series),
|
||||
typeof(CCI_Series),
|
||||
typeof(OBV_Series),
|
||||
typeof(ADOSC_Series),
|
||||
typeof(MIDPRICE_Series),
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Name_exists(Type classType)
|
||||
{
|
||||
GBM_Feed data = new(10);
|
||||
|
||||
var MA_Series = Activator.CreateInstance(classType, data) as TSeries;
|
||||
Assert.NotEmpty(MA_Series.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Series_Length(Type classType)
|
||||
{
|
||||
GBM_Feed data = new(1000);
|
||||
|
||||
var MA_Series = Activator.CreateInstance(classType, data) as TSeries;
|
||||
Assert.Equal(1000, MA_Series.Count);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Return_data(Type classType)
|
||||
{
|
||||
GBM_Feed data = new(10);
|
||||
var MA_Series = Activator.CreateInstance(classType, data) as TSeries;
|
||||
var result = MA_Series.Add((DateTime.Today, 1, 2, 3, 4, 5));
|
||||
Assert.Equal(result.v, MA_Series.Last.v);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Update(Type classType)
|
||||
{
|
||||
GBM_Feed data = new(10);
|
||||
var MA_Series = Activator.CreateInstance(classType, data) as TSeries;
|
||||
var pre_update = MA_Series.Last;
|
||||
|
||||
var pre_data = data.Last;
|
||||
data.Add((DateTime.Today, 1, 2, 3, 4, 5), true);
|
||||
data.Add(pre_data, true);
|
||||
|
||||
Assert.Equal(pre_update.v, MA_Series.Last.v);
|
||||
Assert.Equal(data.Count, MA_Series.Count);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Reset(Type classType)
|
||||
{
|
||||
GBM_Feed data = new(10);
|
||||
var MA_Series = Activator.CreateInstance(classType, data) as TSeries;
|
||||
MA_Series.Reset();
|
||||
data.Add();
|
||||
Assert.False(double.IsNaN(MA_Series.Last.v));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MASeriesData))]
|
||||
public void Period_default(Type classType)
|
||||
{
|
||||
GBM_Feed data = new(100);
|
||||
|
||||
var MA_Series = Activator.CreateInstance(classType, data) as TSeries;
|
||||
Assert.False(double.IsNaN(MA_Series.Last.v));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> MASeriesData()
|
||||
{
|
||||
foreach (var type in maSeriesTypes)
|
||||
{
|
||||
yield return new object[] { type };
|
||||
}
|
||||
}
|
||||
}
|
||||
#nullable restore
|
||||
@@ -1,64 +0,0 @@
|
||||
using Xunit;
|
||||
using System;
|
||||
using QuanTAlib;
|
||||
|
||||
namespace Pairs;
|
||||
public class ADD_Test
|
||||
{
|
||||
[Fact]
|
||||
public void ADDSeriesSeries_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 5 };
|
||||
TSeries b = new() { 5, 4, 3, 2, 1, 0 };
|
||||
ADD_Series c = new(a, b);
|
||||
Assert.Equal(5, c.Last().v);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ADDSeriesDouble_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 5 };
|
||||
ADD_Series c = new(a, 10.0);
|
||||
Assert.Equal(15, c.Last().v);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ADDDoubleSeries_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 5 };
|
||||
ADD_Series c = new(10.0, a);
|
||||
Assert.Equal(15, c.Last().v);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ADDEventing_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 5 };
|
||||
TSeries b = new() { 5, 4, 3, 2, 1, 0 };
|
||||
ADD_Series c = new(a, b);
|
||||
a.Add(2);
|
||||
b.Add(2);
|
||||
Assert.Equal(4, c.Last().v);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ADDUpdateDouble_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 5 };
|
||||
double b = 10;
|
||||
ADD_Series c = new(a, b);
|
||||
a.Add(0, true);
|
||||
Assert.Equal(10, c.Last().v);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ADDUpdating_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 5 };
|
||||
TSeries b = new() { 5, 4, 3, 2, 1, 0 };
|
||||
ADD_Series c = new(a, b);
|
||||
a.Add(10, true);
|
||||
b.Add(10, true);
|
||||
Assert.Equal(20, c.Last().v);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
using Xunit;
|
||||
using System;
|
||||
using QuanTAlib;
|
||||
|
||||
namespace Pairs;
|
||||
public class DIV_Test
|
||||
{
|
||||
[Fact]
|
||||
public void DIVSeriesSeries_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 15 };
|
||||
TSeries b = new() { 5, 4, 3, 2, 1, 3 };
|
||||
DIV_Series c = new(a, b);
|
||||
Assert.Equal(5, c.Last().v);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DIVSeriesDouble_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 15.0 };
|
||||
DIV_Series c = new(a, 0);
|
||||
Assert.Equal(double.PositiveInfinity, c.Last().v);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DIVDoubleSeries_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 3.0 };
|
||||
DIV_Series c = new(12.0, a);
|
||||
Assert.Equal(4.0, c.Last().v);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DIVEventing_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 5 };
|
||||
TSeries b = new() { 5, 4, 3, 2, 1, 0 };
|
||||
DIV_Series c = new(a, b);
|
||||
a.Add(12.0);
|
||||
b.Add(2);
|
||||
Assert.Equal(6.0, c.Last().v);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DIVUpdatewDouble_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 15 };
|
||||
double b = 2;
|
||||
DIV_Series c = new(a, b);
|
||||
a.Add(10, true);
|
||||
Assert.Equal(5, c.Last().v);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DIVUpdating_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 5 };
|
||||
TSeries b = new() { 5, 4, 3, 2, 1, 1 };
|
||||
DIV_Series c = new(a, b);
|
||||
a.Add(10, true);
|
||||
b.Add(2, true);
|
||||
Assert.Equal(5, c.Last().v);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
using Xunit;
|
||||
using System;
|
||||
using QuanTAlib;
|
||||
|
||||
namespace Pairs;
|
||||
public class MUL_Test
|
||||
{
|
||||
[Fact]
|
||||
public void MULSeriesSeries_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 5 };
|
||||
TSeries b = new() { 5, 4, 3, 2, 1, 1 };
|
||||
MUL_Series c = new(a, b);
|
||||
Assert.Equal(5, c.Last().v);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MULSeriesDouble_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 5 };
|
||||
MUL_Series c = new(a, 10.0);
|
||||
Assert.Equal(50, c.Last().v);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MULDoubleSeries_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 5 };
|
||||
MUL_Series c = new(5.0, a);
|
||||
Assert.Equal(25, c.Last().v);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MULEventing_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 5 };
|
||||
TSeries b = new() { 5, 4, 3, 2, 1, 0 };
|
||||
MUL_Series c = new(a, b);
|
||||
a.Add(2);
|
||||
b.Add(5);
|
||||
Assert.Equal(10, c.Last().v);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MULUpdateDouble_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 5 };
|
||||
double b = 10;
|
||||
MUL_Series c = new(a, b);
|
||||
a.Add(2, true);
|
||||
Assert.Equal(20, c.Last().v);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MULUpdating_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 5 };
|
||||
TSeries b = new() { 5, 4, 3, 2, 1, 0 };
|
||||
MUL_Series c = new(a, b);
|
||||
a.Add(10, true);
|
||||
b.Add(10, true);
|
||||
Assert.Equal(100, c.Last().v);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
using Xunit;
|
||||
using System;
|
||||
using QuanTAlib;
|
||||
|
||||
namespace Pairs;
|
||||
public class SUB_Test
|
||||
{
|
||||
[Fact]
|
||||
public void SUBSeriesSeries_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 5 };
|
||||
TSeries b = new() { 5, 4, 3, 2, 1, 1 };
|
||||
SUB_Series c = new(a, b);
|
||||
Assert.Equal(4, c.Last().v);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SUBSeriesDouble_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 15.0 };
|
||||
SUB_Series c = new(a, 10.0);
|
||||
Assert.Equal(5.0, c.Last().v);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SUBDoubleSeries_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 15.0 };
|
||||
SUB_Series c = new(10.0, a);
|
||||
Assert.Equal(-5.0, c.Last().v);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SUBEventing_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 5 };
|
||||
TSeries b = new() { 5, 4, 3, 2, 1, 0 };
|
||||
SUB_Series c = new(a, b);
|
||||
a.Add(7.0);
|
||||
b.Add(2);
|
||||
Assert.Equal(5.0, c.Last().v);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SUBUpdatewDouble_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 15 };
|
||||
double b = 10;
|
||||
SUB_Series c = new(a, b);
|
||||
a.Add(1, true);
|
||||
Assert.Equal(-9, c.Last().v);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SUBUpdating_Test()
|
||||
{
|
||||
TSeries a = new() { 0, 1, 2, 3, 4, 5 };
|
||||
TSeries b = new() { 5, 4, 3, 2, 1, 1 };
|
||||
SUB_Series c = new(a, b);
|
||||
a.Add(10, true);
|
||||
b.Add(0, true);
|
||||
Assert.Equal(10, c.Last().v);
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
using Xunit;
|
||||
using System;
|
||||
using QuanTAlib;
|
||||
|
||||
namespace Bars;
|
||||
public class TBars_Test
|
||||
{
|
||||
[Fact]
|
||||
public void InsertingTuple()
|
||||
{
|
||||
TBars s = new() { (t: DateTime.Today, o: double.Epsilon, h: double.NaN, l: Double.MaxValue, c: Double.NegativeInfinity, v: Double.PositiveInfinity) };
|
||||
var tup = (t: DateTime.Today, o: double.Epsilon, h: double.NaN, l: Double.MaxValue,
|
||||
c: Double.NegativeInfinity, v: Double.PositiveInfinity);
|
||||
Assert.Equal(tup, s[^1]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Casting_Parameters()
|
||||
{
|
||||
TBars s = new()
|
||||
{
|
||||
{ DateTime.Today, 0.1, 1.1, 2.1, 3.1, 4.1, false }
|
||||
};
|
||||
Assert.Equal(0.1, s[^1].o);
|
||||
Assert.Equal(1.1, s[^1].h);
|
||||
Assert.Equal(2.1, s[^1].l);
|
||||
Assert.Equal(3.1, s[^1].c);
|
||||
Assert.Equal(4.1, s[^1].v);
|
||||
Assert.Equal(DateTime.Today, s[^1].t);
|
||||
Assert.Single(s);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Updating_Value()
|
||||
{
|
||||
TBars s = new()
|
||||
{
|
||||
{ DateTime.Today, 0.1, 1.1, 2.1, 3.1, 4.1 }
|
||||
};
|
||||
s.Add(DateTime.Today, 1.0, 1.0, 1.0, 1.0, 1.0, update: false);
|
||||
s.Add(DateTime.Today, 0.0, 0.0, 0.0, 0.0, 0.0, update: true);
|
||||
Assert.Equal(0.0, s[^1].o);
|
||||
Assert.Equal(0.0, s[^1].h);
|
||||
Assert.Equal(0.0, s[^1].l);
|
||||
Assert.Equal(0.0, s[^1].c);
|
||||
Assert.Equal(0.0, s[^1].v);
|
||||
Assert.Equal(2, s.Count);
|
||||
}
|
||||
[Fact]
|
||||
public void Extracting_TSeries()
|
||||
{
|
||||
TBars s = new()
|
||||
{
|
||||
{ DateTime.Today, 0.1, 1.1, 2.1, 3.1, 4.1 },
|
||||
{ DateTime.Today, 2.1, 3.1, 4.1, 5.1, 6.1 }
|
||||
};
|
||||
|
||||
TSeries t = s.Open;
|
||||
Assert.Equal(t.t, s.Open.t);
|
||||
Assert.Equal(t.v, s.Open.v);
|
||||
|
||||
t = s.High;
|
||||
Assert.Equal(t.t, s.High.t);
|
||||
Assert.Equal(t.v, s.High.v);
|
||||
|
||||
t = s.Low;
|
||||
Assert.Equal(t.t, s.Low.t);
|
||||
Assert.Equal(t.v, s.Low.v);
|
||||
|
||||
t = s.Close;
|
||||
Assert.Equal(t.t, s.Close.t);
|
||||
Assert.Equal(t.v, s.Close.v);
|
||||
|
||||
t = s.Volume;
|
||||
Assert.Equal(t.t, s.Volume.t);
|
||||
Assert.Equal(t.v, s.Volume.v);
|
||||
|
||||
t = s.HL2;
|
||||
Assert.Equal(t.t, s.HL2.t);
|
||||
Assert.Equal(t.v, s.HL2.v);
|
||||
|
||||
t = s.OC2;
|
||||
Assert.Equal(t.t, s.OC2.t);
|
||||
Assert.Equal(t.v, s.OC2.v);
|
||||
|
||||
t = s.OHL3;
|
||||
Assert.Equal(t.t, s.OHL3.t);
|
||||
Assert.Equal(t.v, s.OHL3.v);
|
||||
|
||||
t = s.HLC3;
|
||||
Assert.Equal(t.t, s.HLC3.t);
|
||||
Assert.Equal(t.v, s.HLC3.v);
|
||||
|
||||
t = s.OHLC4;
|
||||
Assert.Equal(t.t, s.OHLC4.t);
|
||||
Assert.Equal(t.v, s.OHLC4.v);
|
||||
|
||||
t = s.HLCC4;
|
||||
Assert.Equal(t.t, s.HLCC4.t);
|
||||
Assert.Equal(t.v, s.HLCC4.v);
|
||||
}
|
||||
[Fact]
|
||||
public void Broadcasting_Events()
|
||||
{
|
||||
TBars s = new() { (DateTime.Today, 2.1, 3.1, 4.1, 5.1, 6.1) };
|
||||
TSeries t = new();
|
||||
s.Close.Pub += t.Sub;
|
||||
s.Add(DateTime.Today, 0.1, 1.1, 2.1, 3.1, 4.1, false);
|
||||
Assert.Equal(s.Close.v, t.v);
|
||||
Assert.Equal(s.Close.Count, t.Count);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net7.0</TargetFrameworks>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<AssemblyVersion>0.2.1.0</AssemblyVersion>
|
||||
<FileVersion>0.2.1.0</FileVersion>
|
||||
<InformationalVersion>0.2.1-dev.2+Branch.dev.Sha.cb5fe2dc86a78fe9358da810d17952c82299ed3d</InformationalVersion>
|
||||
<Version>0.2.1-dev.2</Version>
|
||||
<NoWarn>$(NoWarn);NETSDK1057</NoWarn>
|
||||
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="3.2.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="pythonnet" Version="3.0.1" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0-preview-20230223-05" />
|
||||
<PackageReference Include="TALib.NETCore" Version="0.4.4" />
|
||||
<PackageReference Include="Skender.Stock.Indicators" Version="3.0.0-preview1014-0015" />
|
||||
<PackageReference Include="Tulip.NETCore" Version="0.8.0.1" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.0-preview.3.23174.8" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Calculations\Calculations.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="Python.Included" />
|
||||
<None Remove="pythonnet" />
|
||||
<None Remove="Tulip.NETCore" />
|
||||
<None Remove="System.Text.Json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Statistics\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
pytz
|
||||
six
|
||||
python-dateutil
|
||||
numpy
|
||||
pandas
|
||||
pandas-ta
|
||||
Reference in New Issue
Block a user