mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-01 19:27:44 +00:00
Pandas-TA tests
This commit is contained in:
@@ -64,8 +64,8 @@
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Text.Json" Version="6.0.6" />
|
||||
<PackageReference Include="GitVersion.MsBuild" Version="5.6.10*">
|
||||
<PackageReference Include="System.Text.Json" Version="7.0.0" />
|
||||
<PackageReference Include="GitVersion.MsBuild" Version="5.11.1">
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Python.Included" Version="3.10.0-preview5" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
@@ -21,10 +22,15 @@
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0-preview-20221003-04" />
|
||||
<PackageReference Include="TALib.NETCore" Version="0.4.4" />
|
||||
<PackageReference Include="Skender.Stock.Indicators" Version="2.4.0" />
|
||||
<PackageReference Include="pythonnet" Version="3.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Source\QuanTAlib.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Python.Included" />
|
||||
<None Remove="pythonnet" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
+111
-105
@@ -1,122 +1,128 @@
|
||||
/*
|
||||
using Xunit;
|
||||
using System;
|
||||
using QuanTAlib;
|
||||
using Python.Runtime;
|
||||
using Python.Included;
|
||||
using Xunit;
|
||||
using System;
|
||||
using QuanTAlib;
|
||||
using Python.Runtime;
|
||||
using Python.Included;
|
||||
|
||||
namespace Validation;
|
||||
public class PandasTA
|
||||
namespace Validations;
|
||||
public class PandasTA : IDisposable
|
||||
{
|
||||
private readonly RND_Feed bars;
|
||||
private readonly Random rnd = new();
|
||||
private readonly int period;
|
||||
private readonly dynamic ta;
|
||||
private readonly dynamic df;
|
||||
private GBM_Feed bars;
|
||||
private Random rnd = new();
|
||||
private int period;
|
||||
private string OStype;
|
||||
private dynamic np;
|
||||
private dynamic ta;
|
||||
private dynamic df;
|
||||
|
||||
public PandasTA()
|
||||
{
|
||||
this.bars = new(1000);
|
||||
this.period = this.rnd.Next(28) + 3;
|
||||
public PandasTA()
|
||||
{
|
||||
bars = new(5000);
|
||||
period = rnd.Next(28) + 3;
|
||||
|
||||
Runtime.PythonDLL = @"python310.dll";
|
||||
Installer.InstallPath = Path.GetFullPath(".");
|
||||
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);
|
||||
}
|
||||
// Checking the host OS and setting PythonDLL accordingly
|
||||
OStype = Environment.OSVersion.ToString();
|
||||
if (OStype == "Unix 13.1.0")
|
||||
OStype = @"/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/libpython3.10.dylib";
|
||||
else OStype = Path.GetFullPath(".") + @"\python-3.10.0-embed-amd64\python310.dll";
|
||||
|
||||
~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);
|
||||
Installer.InstallPath = Path.GetFullPath(".");
|
||||
Installer.SetupPython().Wait();
|
||||
Installer.TryInstallPip();
|
||||
Installer.PipInstallModule("pandas-ta");
|
||||
|
||||
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
||||
}
|
||||
Runtime.PythonDLL = OStype;
|
||||
PythonEngine.Initialize();
|
||||
np = Py.Import("numpy");
|
||||
ta = Py.Import("pandas_ta");
|
||||
|
||||
[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);
|
||||
string[] cols = { "open", "high", "low", "close", "volume" };
|
||||
double[,] ary = new double[bars.Count, 5];
|
||||
for (int i = 0; i < bars.Count; i++)
|
||||
{
|
||||
ary[i, 0] = bars.Open[i].v;
|
||||
ary[i, 1] = bars.High[i].v;
|
||||
ary[i, 2] = bars.Low[i].v;
|
||||
ary[i, 3] = bars.Close[i].v;
|
||||
ary[i, 4] = bars.Volume[i].v;
|
||||
}
|
||||
df = ta.DataFrame(data: np.array(ary), index: np.array(bars.Close.t), columns: np.array(cols));
|
||||
}
|
||||
|
||||
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
PythonEngine.Shutdown();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
void SMA()
|
||||
{
|
||||
SMA_Series QL = new(bars.Close, period, false);
|
||||
var pta = df.ta.sma(close: df.close, length: period);
|
||||
Assert.Equal(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);
|
||||
[Fact]
|
||||
void EMA()
|
||||
{
|
||||
EMA_Series QL = new(bars.Close, period, false);
|
||||
var pta = df.ta.ema(close: df.close, length: period);
|
||||
Assert.Equal(Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
||||
}
|
||||
|
||||
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
||||
}
|
||||
[Fact]
|
||||
void TEMA()
|
||||
{
|
||||
TEMA_Series QL = new(bars.Close, period, false);
|
||||
var pta = df.ta.tema(close: df.close, length: period);
|
||||
Assert.Equal(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);
|
||||
[Fact]
|
||||
void ENTP()
|
||||
{
|
||||
ENTP_Series QL = new(bars.Close, period, useNaN: false);
|
||||
var pta = df.ta.entropy(close: df.close, length: period);
|
||||
Assert.Equal(Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
||||
}
|
||||
|
||||
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
||||
}
|
||||
[Fact]
|
||||
void WMA()
|
||||
{
|
||||
WMA_Series QL = new(bars.Close, period, false);
|
||||
var pta = df.ta.wma(close: df.close, length: period);
|
||||
Assert.Equal(Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
void DEMA()
|
||||
{
|
||||
DEMA_Series QL = new(bars.Close, period, false);
|
||||
var pta = df.ta.dema(close: df.close, length: period);
|
||||
Assert.Equal(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);
|
||||
[Fact]
|
||||
void BIAS()
|
||||
{
|
||||
BIAS_Series QL = new(bars.Close, period, false);
|
||||
var pta = df.ta.bias(close: df.close, length: period);
|
||||
Assert.Equal(Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
||||
}
|
||||
|
||||
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
||||
}
|
||||
[Fact]
|
||||
void KURT()
|
||||
{
|
||||
KURT_Series QL = new(bars.Close, period, useNaN: false);
|
||||
var pta = df.ta.kurtosis(close: df.close, length: period);
|
||||
Assert.Equal(Math.Round((double)pta.tail(1), 4), Math.Round(QL.Last().v, 4));
|
||||
}
|
||||
|
||||
[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));
|
||||
}
|
||||
}
|
||||
*/
|
||||
[Fact]
|
||||
void MAD()
|
||||
{
|
||||
MAD_Series QL = new(bars.Close, period, useNaN: false);
|
||||
var pta = df.ta.mad(close: df.close, length: period);
|
||||
Assert.Equal(Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
||||
}
|
||||
}
|
||||
+165
-165
@@ -3,144 +3,144 @@ using QuanTAlib;
|
||||
using Skender.Stock.Indicators;
|
||||
using Xunit;
|
||||
|
||||
namespace Validation;
|
||||
namespace Validations;
|
||||
public class Skender_Stock
|
||||
{
|
||||
private readonly GBM_Feed bars;
|
||||
private readonly Random rnd = new();
|
||||
private readonly int period;
|
||||
private readonly IEnumerable<Quote> quotes;
|
||||
private readonly GBM_Feed bars;
|
||||
private readonly Random rnd = new();
|
||||
private readonly int period;
|
||||
private readonly IEnumerable<Quote> quotes;
|
||||
|
||||
public Skender_Stock()
|
||||
{
|
||||
this.bars = new(Bars: 5000, Volatility:0.7, Drift:0.0);
|
||||
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
|
||||
});
|
||||
}
|
||||
public Skender_Stock()
|
||||
{
|
||||
bars = new(Bars: 5000, Volatility: 0.7, Drift: 0.0);
|
||||
period = rnd.Next(28) + 3;
|
||||
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 SMA()
|
||||
{
|
||||
SMA_Series QL = new(this.bars.Close, this.period, false);
|
||||
var SK = this.quotes.GetSma(this.period);
|
||||
[Fact]
|
||||
public void SMA()
|
||||
{
|
||||
SMA_Series QL = new(bars.Close, period, false);
|
||||
var SK = quotes.GetSma(period);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Sma!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
Assert.Equal(Math.Round((double)SK.Last().Sma!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EMA()
|
||||
{
|
||||
EMA_Series QL = new(this.bars.Close, this.period, false);
|
||||
var SK = this.quotes.GetEma(this.period);
|
||||
[Fact]
|
||||
public void EMA()
|
||||
{
|
||||
EMA_Series QL = new(bars.Close, period, false);
|
||||
var SK = quotes.GetEma(period);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Ema!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
[Fact]
|
||||
public void WMA()
|
||||
{
|
||||
WMA_Series QL = new(this.bars.Close, this.period, false);
|
||||
var SK = this.quotes.GetWma(this.period);
|
||||
Assert.Equal(Math.Round((double)SK.Last().Ema!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
[Fact]
|
||||
public void WMA()
|
||||
{
|
||||
WMA_Series QL = new(bars.Close, period, false);
|
||||
var SK = quotes.GetWma(period);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Wma!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
Assert.Equal(Math.Round((double)SK.Last().Wma!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DEMA()
|
||||
{
|
||||
DEMA_Series QL = new(this.bars.Close, this.period, false);
|
||||
var SK = this.quotes.GetDema(this.period);
|
||||
[Fact]
|
||||
public void DEMA()
|
||||
{
|
||||
DEMA_Series QL = new(bars.Close, period, false);
|
||||
var SK = quotes.GetDema(period);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Dema!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
Assert.Equal(Math.Round((double)SK.Last().Dema!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TEMA()
|
||||
{
|
||||
TEMA_Series QL = new(this.bars.Close, this.period, false);
|
||||
var SK = this.quotes.GetTema(this.period);
|
||||
[Fact]
|
||||
public void TEMA()
|
||||
{
|
||||
TEMA_Series QL = new(bars.Close, period, false);
|
||||
var SK = quotes.GetTema(period);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Tema!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
Assert.Equal(Math.Round((double)SK.Last().Tema!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MAD()
|
||||
{
|
||||
MAD_Series QL = new(this.bars.Close, this.period, false);
|
||||
var SK = this.quotes.GetSmaAnalysis(this.period);
|
||||
[Fact]
|
||||
public void MAD()
|
||||
{
|
||||
MAD_Series QL = new(bars.Close, period, false);
|
||||
var SK = quotes.GetSmaAnalysis(period);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Mad!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
Assert.Equal(Math.Round((double)SK.Last().Mad!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MAPE()
|
||||
{
|
||||
MAPE_Series QL = new(this.bars.Close, this.period, false);
|
||||
var SK = this.quotes.GetSmaAnalysis(this.period);
|
||||
[Fact]
|
||||
public void MAPE()
|
||||
{
|
||||
MAPE_Series QL = new(bars.Close, period, false);
|
||||
var SK = quotes.GetSmaAnalysis(period);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Mape!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
Assert.Equal(Math.Round((double)SK.Last().Mape!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ATR()
|
||||
{
|
||||
ATR_Series QL = new(this.bars, this.period, false);
|
||||
var SK = this.quotes.GetAtr(this.period);
|
||||
[Fact]
|
||||
public void ATR()
|
||||
{
|
||||
ATR_Series QL = new(bars, period, false);
|
||||
var SK = quotes.GetAtr(period);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Atr!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
Assert.Equal(Math.Round((double)SK.Last().Atr!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OBV()
|
||||
{
|
||||
OBV_Series QL = new(this.bars, this.period, false);
|
||||
var SK = this.quotes.GetObv(this.period);
|
||||
[Fact]
|
||||
public void OBV()
|
||||
{
|
||||
OBV_Series QL = new(bars, period, false);
|
||||
var SK = quotes.GetObv(period);
|
||||
|
||||
// adding volume[0] to OBV to pass the test and keep compatibility with TA-LIB
|
||||
Assert.Equal(Math.Round(SK.Last().Obv! + (double)this.quotes.First().Volume!, 5),
|
||||
Math.Round(QL.Last().v, 5));
|
||||
}
|
||||
// adding volume[0] to OBV to pass the test and keep compatibility with TA-LIB
|
||||
Assert.Equal(Math.Round(SK.Last().Obv! + (double)quotes.First().Volume!, 5),
|
||||
Math.Round(QL.Last().v, 5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ADL()
|
||||
{
|
||||
ADL_Series QL = new(this.bars, false);
|
||||
var SK = this.quotes.GetAdl();
|
||||
[Fact]
|
||||
public void ADL()
|
||||
{
|
||||
ADL_Series QL = new(bars, false);
|
||||
var SK = quotes.GetAdl();
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Adl!, 5), Math.Round(QL.Last().v, 5));
|
||||
}
|
||||
Assert.Equal(Math.Round((double)SK.Last().Adl!, 5), Math.Round(QL.Last().v, 5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CCI()
|
||||
{
|
||||
CCI_Series QL = new(this.bars, this.period, false);
|
||||
var SK = this.quotes.GetCci(this.period);
|
||||
[Fact]
|
||||
public void CCI()
|
||||
{
|
||||
CCI_Series QL = new(bars, period, false);
|
||||
var SK = quotes.GetCci(period);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Cci!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
Assert.Equal(Math.Round((double)SK.Last().Cci!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ATRP()
|
||||
{
|
||||
ATRP_Series QL = new(this.bars, this.period, false);
|
||||
var SK = this.quotes.GetAtr(this.period);
|
||||
[Fact]
|
||||
public void ATRP()
|
||||
{
|
||||
ATRP_Series QL = new(bars, period, false);
|
||||
var SK = quotes.GetAtr(period);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Atrp!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
Assert.Equal(Math.Round((double)SK.Last().Atrp!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void KAMA()
|
||||
{
|
||||
KAMA_Series QL = new(this.bars.Close, this.period, useNaN: false);
|
||||
var SK = this.quotes.GetKama(this.period);
|
||||
KAMA_Series QL = new(bars.Close, period, useNaN: false);
|
||||
var SK = quotes.GetKama(period);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Kama!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
@@ -148,135 +148,135 @@ public class Skender_Stock
|
||||
[Fact]
|
||||
public void HMA()
|
||||
{
|
||||
HMA_Series QL = new(this.bars.Close, this.period, useNaN: false);
|
||||
var SK = this.quotes.GetHma(this.period);
|
||||
HMA_Series QL = new(bars.Close, period, useNaN: false);
|
||||
var SK = quotes.GetHma(period);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Hma!, 6), Math.Round(QL.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().Hma!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact]
|
||||
public void SMMA()
|
||||
{
|
||||
SMMA_Series QL = new(this.bars.Close, this.period, useNaN: false);
|
||||
var SK = this.quotes.GetSmma(this.period);
|
||||
SMMA_Series QL = new(bars.Close, period, useNaN: false);
|
||||
var SK = quotes.GetSmma(period);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Smma!, 6), Math.Round(QL.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().Smma!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MACD()
|
||||
{
|
||||
MACD_Series QL = new(this.bars.Close, 26,12,9, useNaN: false);
|
||||
var SK = this.quotes.GetMacd(12,26,9);
|
||||
MACD_Series QL = new(bars.Close, 26, 12, 9, useNaN: false);
|
||||
var SK = quotes.GetMacd(12, 26, 9);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Macd!, 6), Math.Round(QL.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().Signal!, 6), Math.Round(QL.Signal.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().Macd!, 6), Math.Round(QL.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().Signal!, 6), Math.Round(QL.Signal.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BBANDS()
|
||||
{
|
||||
BBANDS_Series QL = new(this.bars.Close, this.period, 2.0, useNaN: false);
|
||||
var SK = this.quotes.GetBollingerBands(this.period, 2.0);
|
||||
BBANDS_Series QL = new(bars.Close, period, 2.0, useNaN: false);
|
||||
var SK = quotes.GetBollingerBands(period, 2.0);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Sma!, 6), Math.Round(QL.Mid.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().UpperBand!, 6), Math.Round(QL.Upper.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().LowerBand!, 6), Math.Round(QL.Lower.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().Width!, 6), Math.Round(QL.Bandwidth.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().PercentB!, 6), Math.Round(QL.PercentB.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().ZScore!, 6), Math.Round(QL.Zscore.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().Sma!, 6), Math.Round(QL.Mid.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().UpperBand!, 6), Math.Round(QL.Upper.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().LowerBand!, 6), Math.Round(QL.Lower.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().Width!, 6), Math.Round(QL.Bandwidth.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().PercentB!, 6), Math.Round(QL.PercentB.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().ZScore!, 6), Math.Round(QL.Zscore.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact]
|
||||
public void RSI()
|
||||
{
|
||||
RSI_Series QL = new(this.bars.Close, this.period, useNaN: false);
|
||||
var SK = this.quotes.GetRsi(this.period);
|
||||
RSI_Series QL = new(bars.Close, period, useNaN: false);
|
||||
var SK = quotes.GetRsi(period);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Rsi!, 6), Math.Round(QL.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().Rsi!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ALMA()
|
||||
{
|
||||
ALMA_Series QL = new(this.bars.Close, this.period, useNaN: false);
|
||||
var SK = this.quotes.GetAlma(this.period);
|
||||
ALMA_Series QL = new(bars.Close, period, useNaN: false);
|
||||
var SK = quotes.GetAlma(period);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Alma!, 6), Math.Round(QL.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().Alma!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SDEV()
|
||||
{
|
||||
SDEV_Series QL = new(this.bars.Close, this.period, useNaN: false);
|
||||
var SK = this.quotes.GetStdDev(this.period);
|
||||
SDEV_Series QL = new(bars.Close, period, useNaN: false);
|
||||
var SK = quotes.GetStdDev(period);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().StdDev!, 6), Math.Round(QL.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().StdDev!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact]
|
||||
public void LINREG()
|
||||
{
|
||||
LINREG_Series QL = new(this.bars.Close, this.period, useNaN: false);
|
||||
var SK = this.quotes.GetSlope(this.period);
|
||||
LINREG_Series QL = new(bars.Close, period, useNaN: false);
|
||||
var SK = quotes.GetSlope(period);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Slope!, 6), Math.Round(QL.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().Intercept!, 6), Math.Round(QL.Intercept.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().RSquared!, 6), Math.Round(QL.RSquared.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().StdDev!, 6), Math.Round(QL.StdDev.Last().v, 6));
|
||||
}
|
||||
Assert.Equal(Math.Round((double)SK.Last().Slope!, 6), Math.Round(QL.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().Intercept!, 6), Math.Round(QL.Intercept.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().RSquared!, 6), Math.Round(QL.RSquared.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().StdDev!, 6), Math.Round(QL.StdDev.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TR()
|
||||
{
|
||||
TR_Series QL = new(this.bars, useNaN: false);
|
||||
var SK = this.quotes.GetTr();
|
||||
TR_Series QL = new(bars, useNaN: false);
|
||||
var SK = quotes.GetTr();
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Tr!, 6), Math.Round(QL.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().Tr!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact]
|
||||
public void HL2()
|
||||
{
|
||||
TSeries QL = this.bars.HL2;
|
||||
var SK = this.quotes.GetBaseQuote(CandlePart.HL2);
|
||||
TSeries QL = bars.HL2;
|
||||
var SK = quotes.GetBaseQuote(CandlePart.HL2);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Value!, 6), Math.Round(QL.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().Value!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OC2()
|
||||
{
|
||||
TSeries QL = this.bars.OC2;
|
||||
var SK = this.quotes.GetBaseQuote(CandlePart.OC2);
|
||||
TSeries QL = bars.OC2;
|
||||
var SK = quotes.GetBaseQuote(CandlePart.OC2);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Value!, 6), Math.Round(QL.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().Value!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact]
|
||||
public void HLC3()
|
||||
{
|
||||
TSeries QL = this.bars.HLC3;
|
||||
var SK = this.quotes.GetBaseQuote(CandlePart.HLC3);
|
||||
TSeries QL = bars.HLC3;
|
||||
var SK = quotes.GetBaseQuote(CandlePart.HLC3);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Value!, 6), Math.Round(QL.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().Value!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OHL3()
|
||||
{
|
||||
TSeries QL = this.bars.OHL3;
|
||||
var SK = this.quotes.GetBaseQuote(CandlePart.OHL3);
|
||||
TSeries QL = bars.OHL3;
|
||||
var SK = quotes.GetBaseQuote(CandlePart.OHL3);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Value!, 6), Math.Round(QL.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().Value!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OHLC4()
|
||||
{
|
||||
TSeries QL = this.bars.OHLC4;
|
||||
var SK = this.quotes.GetBaseQuote(CandlePart.OHLC4);
|
||||
TSeries QL = bars.OHLC4;
|
||||
var SK = quotes.GetBaseQuote(CandlePart.OHLC4);
|
||||
|
||||
Assert.Equal(Math.Round((double)SK.Last().Value!, 6), Math.Round(QL.Last().v, 6));
|
||||
Assert.Equal(Math.Round((double)SK.Last().Value!, 6), Math.Round(QL.Last().v, 6));
|
||||
}
|
||||
}
|
||||
|
||||
+213
-213
@@ -3,270 +3,270 @@ using System;
|
||||
using TALib;
|
||||
using QuanTAlib;
|
||||
|
||||
namespace Validation;
|
||||
namespace Validations;
|
||||
public class TA_LIB
|
||||
{
|
||||
private readonly GBM_Feed bars;
|
||||
private readonly Random rnd = new();
|
||||
private readonly int period;
|
||||
private readonly double[] TALIB;
|
||||
private readonly double[] inopen;
|
||||
private readonly double[] inhigh;
|
||||
private readonly double[] inlow;
|
||||
private readonly double[] inclose;
|
||||
private readonly double[] involume;
|
||||
private readonly GBM_Feed bars;
|
||||
private readonly Random rnd = new();
|
||||
private readonly int period;
|
||||
private readonly double[] TALIB;
|
||||
private readonly double[] inopen;
|
||||
private readonly double[] inhigh;
|
||||
private readonly double[] inlow;
|
||||
private readonly double[] inclose;
|
||||
private readonly double[] involume;
|
||||
|
||||
public TA_LIB()
|
||||
{
|
||||
this.bars = new(5000);
|
||||
this.period = this.rnd.Next(28) + 3;
|
||||
this.TALIB = new double[this.bars.Count];
|
||||
this.inopen = this.bars.Open.v.ToArray();
|
||||
this.inhigh = this.bars.High.v.ToArray();
|
||||
this.inlow = this.bars.Low.v.ToArray();
|
||||
this.inclose = this.bars.Close.v.ToArray();
|
||||
this.involume = this.bars.Volume.v.ToArray();
|
||||
}
|
||||
public TA_LIB()
|
||||
{
|
||||
bars = new(5000);
|
||||
period = rnd.Next(28) + 3;
|
||||
TALIB = 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(this.bars.Open, this.bars.Close);
|
||||
Core.Add(this.inopen, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _);
|
||||
[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 _);
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SUB()
|
||||
{
|
||||
SUB_Series QL = new(this.bars.Open, this.bars.Close);
|
||||
Core.Sub(this.inopen, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _);
|
||||
[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 _);
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MUL()
|
||||
{
|
||||
MUL_Series QL = new(this.bars.Open, this.bars.Close);
|
||||
Core.Mult(this.inopen, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _);
|
||||
[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 _);
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DIV()
|
||||
{
|
||||
DIV_Series QL = new(this.bars.Open, this.bars.Close);
|
||||
Core.Div(this.inopen, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _);
|
||||
[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 _);
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SDEV()
|
||||
{
|
||||
SDEV_Series QL = new(this.bars.Close, this.period, false);
|
||||
Core.StdDev(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period);
|
||||
[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);
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SMA()
|
||||
{
|
||||
SMA_Series QL = new(this.bars.Close, this.period, false);
|
||||
Core.Sma(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period);
|
||||
[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);
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TRIMA()
|
||||
{
|
||||
TRIMA_Series QL = new(this.bars.Close, this.period, false);
|
||||
Core.Trima(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period);
|
||||
[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);
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EMA()
|
||||
{
|
||||
EMA_Series QL = new(this.bars.Close, this.period, false);
|
||||
Core.Ema(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period);
|
||||
[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);
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WMA()
|
||||
{
|
||||
WMA_Series QL = new(this.bars.Close, this.period, false);
|
||||
Core.Wma(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period);
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
[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);
|
||||
|
||||
[Fact]
|
||||
public void DEMA()
|
||||
{
|
||||
DEMA_Series QL = new(this.bars.Close, this.period, false);
|
||||
Core.Dema(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period);
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
[Fact]
|
||||
public void DEMA()
|
||||
{
|
||||
DEMA_Series QL = new(bars.Close, period, false);
|
||||
Core.Dema(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
|
||||
|
||||
[Fact]
|
||||
public void TEMA()
|
||||
{
|
||||
TEMA_Series QL = new(this.bars.Close, this.period, false);
|
||||
Core.Tema(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period);
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
[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);
|
||||
|
||||
[Fact]
|
||||
public void MAX()
|
||||
{
|
||||
MAX_Series QL = new(this.bars.Close, this.period, false);
|
||||
Core.Max(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period);
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
[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);
|
||||
|
||||
[Fact]
|
||||
public void MIN()
|
||||
{
|
||||
MIN_Series QL = new(this.bars.Close, this.period, false);
|
||||
Core.Min(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period);
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
[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);
|
||||
|
||||
[Fact]
|
||||
public void ADL()
|
||||
{
|
||||
ADL_Series QL = new(this.bars, false);
|
||||
Core.Ad(this.inhigh, this.inlow, this.inclose, this.involume, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _);
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
[Fact]
|
||||
public void ADL()
|
||||
{
|
||||
ADL_Series QL = new(bars, false);
|
||||
Core.Ad(inhigh, inlow, inclose, involume, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
|
||||
|
||||
[Fact]
|
||||
public void OBV()
|
||||
{
|
||||
OBV_Series QL = new(this.bars, this.period, false);
|
||||
Core.Obv(this.inclose, this.involume, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _);
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
[Fact]
|
||||
public void OBV()
|
||||
{
|
||||
OBV_Series QL = new(bars, period, false);
|
||||
Core.Obv(inclose, involume, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
|
||||
|
||||
[Fact]
|
||||
public void ADOSC()
|
||||
{
|
||||
ADOSC_Series QL = new(this.bars, false);
|
||||
Core.AdOsc(this.inhigh, this.inlow, this.inclose, this.involume, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _);
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
[Fact]
|
||||
public void ADOSC()
|
||||
{
|
||||
ADOSC_Series QL = new(bars, false);
|
||||
Core.AdOsc(inhigh, inlow, inclose, involume, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
|
||||
|
||||
[Fact]
|
||||
public void ATR()
|
||||
{
|
||||
ATR_Series QL = new(this.bars, this.period, false);
|
||||
Core.Atr(this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period);
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
[Fact]
|
||||
public void ATR()
|
||||
{
|
||||
ATR_Series QL = new(bars, period, false);
|
||||
Core.Atr(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
|
||||
|
||||
[Fact]
|
||||
public void CCI()
|
||||
{
|
||||
CCI_Series QL = new(this.bars, this.period, false);
|
||||
Core.Cci(this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period);
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
[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);
|
||||
|
||||
[Fact]
|
||||
public void RSI()
|
||||
{
|
||||
RSI_Series QL = new(this.bars.Close, this.period, false);
|
||||
Core.Rsi(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period);
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
[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);
|
||||
|
||||
[Fact]
|
||||
public void TR()
|
||||
{
|
||||
TR_Series QL = new(this.bars, false);
|
||||
Core.TRange(this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _);
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
[Fact]
|
||||
public void TR()
|
||||
{
|
||||
TR_Series QL = new(bars, false);
|
||||
Core.TRange(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
|
||||
|
||||
[Fact]
|
||||
public void MACD()
|
||||
{
|
||||
double[] macdSignal = new double[this.bars.Count];
|
||||
double[] macdHist = new double[this.bars.Count];
|
||||
MACD_Series QL = new(this.bars.Close, slow: 26, fast: 12, signal: 9, false);
|
||||
Core.Macd(this.inclose, 0, this.bars.Count - 1, outMacd: this.TALIB, outMacdSignal: macdSignal, outMacdHist: macdHist, out int outBegIdx, out _);
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
Assert.Equal(Math.Round(macdSignal[macdSignal.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Signal.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BBANDS()
|
||||
{
|
||||
double[] outMiddle = new double[this.bars.Count];
|
||||
double[] outUpper = new double[this.bars.Count];
|
||||
double[] outLower = new double[this.bars.Count];
|
||||
BBANDS_Series QL = new(this.bars.Close, period:26, multiplier:2.0, false);
|
||||
Core.Bbands(this.inclose, 0, this.bars.Count - 1, outRealUpperBand: outUpper, outRealMiddleBand: outMiddle, outRealLowerBand: outLower, out int outBegIdx, out _, optInTimePeriod:26, optInNbDevUp:2.0, optInNbDevDn:2.0);
|
||||
Assert.Equal(Math.Round(outUpper[outUpper.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Upper.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
Assert.Equal(Math.Round(outMiddle[outMiddle.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Mid.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
Assert.Equal(Math.Round(outLower[outLower.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Lower.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
[Fact]
|
||||
public void MACD()
|
||||
{
|
||||
double[] macdSignal = new double[bars.Count];
|
||||
double[] macdHist = new double[bars.Count];
|
||||
MACD_Series QL = new(bars.Close, slow: 26, fast: 12, signal: 9, false);
|
||||
Core.Macd(inclose, 0, bars.Count - 1, outMacd: TALIB, outMacdSignal: macdSignal, outMacdHist: macdHist, out int outBegIdx, out _);
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
Assert.Equal(Math.Round(macdSignal[macdSignal.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Signal.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HL2()
|
||||
{
|
||||
TSeries QL = this.bars.HL2;
|
||||
Core.MedPrice(this.inhigh, this.inlow, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _);
|
||||
[Fact]
|
||||
public void BBANDS()
|
||||
{
|
||||
double[] outMiddle = new double[bars.Count];
|
||||
double[] outUpper = new double[bars.Count];
|
||||
double[] outLower = new double[bars.Count];
|
||||
BBANDS_Series QL = new(bars.Close, period: 26, multiplier: 2.0, false);
|
||||
Core.Bbands(inclose, 0, bars.Count - 1, outRealUpperBand: outUpper, outRealMiddleBand: outMiddle, outRealLowerBand: outLower, out int outBegIdx, out _, optInTimePeriod: 26, optInNbDevUp: 2.0, optInNbDevDn: 2.0);
|
||||
Assert.Equal(Math.Round(outUpper[outUpper.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Upper.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
Assert.Equal(Math.Round(outMiddle[outMiddle.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Mid.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
Assert.Equal(Math.Round(outLower[outLower.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Lower.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
[Fact]
|
||||
public void HL2()
|
||||
{
|
||||
TSeries QL = bars.HL2;
|
||||
Core.MedPrice(inhigh, inlow, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
|
||||
|
||||
[Fact]
|
||||
public void HLC3()
|
||||
{
|
||||
TSeries QL = this.bars.HLC3;
|
||||
Core.TypPrice(this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _);
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
[Fact]
|
||||
public void HLC3()
|
||||
{
|
||||
TSeries QL = bars.HLC3;
|
||||
Core.TypPrice(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
|
||||
|
||||
[Fact]
|
||||
public void OHLC4()
|
||||
{
|
||||
TSeries QL = this.bars.OHLC4;
|
||||
Core.AvgPrice(this.inopen, this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _);
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
[Fact]
|
||||
public void OHLC4()
|
||||
{
|
||||
TSeries QL = bars.OHLC4;
|
||||
Core.AvgPrice(inopen, inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
|
||||
|
||||
[Fact]
|
||||
public void HLCC4()
|
||||
{
|
||||
TSeries QL = this.bars.HLCC4;
|
||||
Core.WclPrice( this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _);
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
[Fact]
|
||||
public void HLCC4()
|
||||
{
|
||||
TSeries QL = bars.HLCC4;
|
||||
Core.WclPrice(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _);
|
||||
|
||||
Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], 6, MidpointRounding.AwayFromZero), Math.Round(QL.Last().v, 6, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user