This commit is contained in:
Miha
2022-04-19 15:46:34 -07:00
commit 50ed6f6504
120 changed files with 16787 additions and 0 deletions
+120
View File
@@ -0,0 +1,120 @@
using Xunit;
using System;
using QuanTAlib;
using Python.Runtime;
using Python.Included;
namespace Validation;
public class PandasTA
{
private readonly RND_Feed bars;
private readonly Random rnd = new();
private readonly int period;
private readonly dynamic ta;
private readonly dynamic df;
public PandasTA()
{
this.bars = new(1000);
this.period = this.rnd.Next(28) + 3;
Installer.SetupPython().Wait();
Installer.TryInstallPip();
Installer.PipInstallModule("numpy");
Installer.PipInstallModule("pandas");
Installer.PipInstallModule("pandas-ta");
PythonEngine.Initialize();
this.ta = Py.Import("pandas_ta");
this.df = this.ta.DataFrame(this.bars.Close.v);
}
~PandasTA()
{
PythonEngine.Shutdown();
}
[Fact]
void SMA()
{
SMA_Series QL = new(this.bars.Close, this.period, false);
var pta = this.ta.sma(close: this.df[0], length: this.period);
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
}
/*
[Fact]
void EMA()
{
EMA_Series QL = new(this.bars.Close, this.period, false);
var pta = this.ta.ema(close: this.df[0], length: this.period);
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
}
[Fact]
void TEMA()
{
TEMA_Series QL = new(this.bars.Close, this.period, false);
var pta = this.ta.tema(close: this.df[0], length: this.period);
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
}
[Fact]
void ENTP()
{
ENTP_Series QL = new(this.bars.Close, this.period, useNaN:false);
var pta = this.ta.entropy(close: this.df[0], length: this.period);
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
}
[Fact]
void WMA()
{
WMA_Series QL = new(this.bars.Close, this.period, false);
var pta = this.ta.wma(close: this.df[0], length: this.period);
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
}
[Fact]
void DEMA()
{
DEMA_Series QL = new(this.bars.Close, this.period, false);
var pta = this.ta.dema(close: this.df[0], length: this.period);
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
}
[Fact]
void BIAS()
{
BIAS_Series QL = new(this.bars.Close, this.period, false);
var pta = this.ta.bias(close: this.df[0], length: this.period);
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
}
[Fact]
void KURT()
{
KURT_Series QL = new(this.bars.Close, this.period, useNaN: false);
var pta = this.ta.kurtosis(close: this.df[0], length: this.period);
Assert.Equal(System.Math.Round((double)pta.tail(1), 4), Math.Round(QL.Last().v, 4));
}
[Fact]
void MAD()
{
MAD_Series QL = new(this.bars.Close, this.period, useNaN: false);
var pta = this.ta.mad(close: this.df[0], length: this.period);
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
}
*/
}
+93
View File
@@ -0,0 +1,93 @@
using Xunit;
using System;
using Skender.Stock.Indicators;
using QuanTAlib;
namespace Validation;
public class Skender_Stock
{
private readonly RND_Feed bars;
private readonly Random rnd = new();
private readonly int period;
private readonly IEnumerable<Quote> quotes;
public Skender_Stock()
{
this.bars = new(1000);
this.period = this.rnd.Next(28) + 3;
this.quotes = this.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 SMA()
{
SMA_Series QL = new(this.bars.Close, this.period, false);
var SK = this.quotes.GetSma(this.period, CandlePart.Close);
Assert.Equal(Math.Round((double)SK.Last().Sma!, 8), Math.Round(QL.Last().v, 8));
}
[Fact]
public void EMA()
{
EMA_Series QL = new(this.bars.Close, this.period, false);
var SK = this.quotes.GetEma(this.period, CandlePart.Close);
Assert.Equal(Math.Round((double)SK.Last().Ema!, 8), Math.Round(QL.Last().v, 8));
}
[Fact]
public void WMA()
{
WMA_Series QL = new(this.bars.Close, this.period, false);
var SK = this.quotes.GetWma(this.period, CandlePart.Close);
Assert.Equal(Math.Round((double)SK.Last().Wma!, 8), Math.Round(QL.Last().v, 8));
}
[Fact]
public void DEMA()
{
DEMA_Series QL = new(this.bars.Close, this.period, false);
var SK = this.quotes.GetDema(this.period);
Assert.Equal(Math.Round((double)SK.Last().Dema!, 8), Math.Round(QL.Last().v, 8));
}
[Fact]
public void TEMA()
{
TEMA_Series QL = new(this.bars.Close, this.period, false);
var SK = this.quotes.GetTema(this.period);
Assert.Equal(Math.Round((double)SK.Last().Tema!, 8), Math.Round(QL.Last().v, 8));
}
[Fact]
public void MAD()
{
MAD_Series QL = new(this.bars.Close, this.period, false);
var SK = this.quotes.GetSmaExtended(this.period);
Assert.Equal(Math.Round((double)SK.Last().Mad!, 8), Math.Round(QL.Last().v, 8));
}
[Fact]
public void MAPE()
{
MAPE_Series QL = new(this.bars.Close, this.period, false);
var SK = this.quotes.GetSmaExtended(this.period);
Assert.Equal(Math.Round((double)SK.Last().Mape!, 8), Math.Round(QL.Last().v, 8));
}
}
+88
View File
@@ -0,0 +1,88 @@
using Xunit;
using System;
using TALib;
using QuanTAlib;
namespace Validation;
public class TA_LIB
{
private readonly RND_Feed bars;
private readonly Random rnd = new();
private readonly int period;
private readonly double[] TALIB;
private readonly double[] input;
public TA_LIB()
{
this.bars = new(1000);
this.period = this.rnd.Next(28) + 3;
this.TALIB = new double[this.bars.Count];
this.input = this.bars.Close.v.ToArray();
}
/////////////////////////////////////////
[Fact]
public void SMA()
{
SMA_Series QL = new(this.bars.Close, this.period, false);
Core.Sma(this.input, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period);
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 8), Math.Round(QL.Last().v, 8));
}
[Fact]
public void EMA()
{
EMA_Series QL = new(this.bars.Close, this.period, false);
Core.Ema(this.input, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period);
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 8), Math.Round(QL.Last().v, 8));
}
[Fact]
public void WMA()
{
WMA_Series QL = new(this.bars.Close, this.period, false);
Core.Wma(this.input, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period);
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 8), Math.Round(QL.Last().v, 8));
}
[Fact]
public void DEMA()
{
DEMA_Series QL = new(this.bars.Close, this.period, false);
Core.Dema(this.input, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period);
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 8), Math.Round(QL.Last().v, 8));
}
[Fact]
public void TEMA()
{
TEMA_Series QL = new(this.bars.Close, this.period, false);
Core.Tema(this.input, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period);
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 8), Math.Round(QL.Last().v, 8));
}
[Fact]
public void MAX()
{
MAX_Series QL = new(this.bars.Close, this.period, false);
Core.Max(this.input, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period);
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 8), Math.Round(QL.Last().v, 8));
}
[Fact]
public void MIN()
{
MIN_Series QL = new(this.bars.Close, this.period, false);
Core.Min(this.input, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period);
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 8), Math.Round(QL.Last().v, 8));
}
}