mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-23 04:58:08 +00:00
. (#22)
This commit is contained in:
@@ -45,6 +45,19 @@ jobs:
|
|||||||
#configFilePath: GitVersion.yml
|
#configFilePath: GitVersion.yml
|
||||||
updateAssemblyInfo: true
|
updateAssemblyInfo: true
|
||||||
|
|
||||||
|
############## Install Python
|
||||||
|
|
||||||
|
- name: Install pandas-ta
|
||||||
|
run: |
|
||||||
|
sudo apt install python3.10
|
||||||
|
sudo apt install python3.10-dev
|
||||||
|
pip3 install numpy
|
||||||
|
pip3 install pandas
|
||||||
|
pip3 install pandas-ta
|
||||||
|
python --version
|
||||||
|
|
||||||
|
############## Install more tools
|
||||||
|
|
||||||
- name: Install JDK11 for Sonar Scanner
|
- name: Install JDK11 for Sonar Scanner
|
||||||
uses: actions/setup-java@v3
|
uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
@@ -158,3 +171,4 @@ jobs:
|
|||||||
--api-key ${{ secrets.NUGET_DEPLOY_KEY_QUANTLIB }}
|
--api-key ${{ secrets.NUGET_DEPLOY_KEY_QUANTLIB }}
|
||||||
--source https://api.nuget.org/v3/index.json
|
--source https://api.nuget.org/v3/index.json
|
||||||
--skip-duplicate
|
--skip-duplicate
|
||||||
|
|
||||||
|
|||||||
@@ -372,6 +372,7 @@
|
|||||||
<Rule Id="S5547" Action="Warning" />
|
<Rule Id="S5547" Action="Warning" />
|
||||||
<Rule Id="S5659" Action="Warning" />
|
<Rule Id="S5659" Action="Warning" />
|
||||||
<Rule Id="S5773" Action="Warning" />
|
<Rule Id="S5773" Action="Warning" />
|
||||||
|
<Rule Id="S5856" Action="None" />
|
||||||
<Rule Id="S6354" Action="None" />
|
<Rule Id="S6354" Action="None" />
|
||||||
<Rule Id="S6419" Action="None" />
|
<Rule Id="S6419" Action="None" />
|
||||||
<Rule Id="S6420" Action="None" />
|
<Rule Id="S6420" Action="None" />
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Title>QuanTAlib</Title>
|
<Title>QuanTAlib</Title>
|
||||||
<Version>0.2.0</Version>
|
<Version>0.2.5</Version>
|
||||||
|
<AssemblyVersion>0.2.5</AssemblyVersion>
|
||||||
|
<FileVersion>0.2.5</FileVersion>
|
||||||
<Product>Library of TA Calculations, Charts and Strategies for Quantower</Product>
|
<Product>Library of TA Calculations, Charts and Strategies for Quantower</Product>
|
||||||
<Description>Quantitative Technical Analysis Library in C# for Quantower</Description>
|
<Description>Quantitative Technical Analysis Library in C# for Quantower</Description>
|
||||||
<RepositoryType>git</RepositoryType>
|
<RepositoryType>git</RepositoryType>
|
||||||
@@ -33,9 +35,6 @@
|
|||||||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||||
<PackageLicenseFile>
|
<PackageLicenseFile>
|
||||||
</PackageLicenseFile>
|
</PackageLicenseFile>
|
||||||
<AssemblyVersion>0.2.1.0</AssemblyVersion>
|
|
||||||
<FileVersion>0.2.1.0</FileVersion>
|
|
||||||
<InformationalVersion>0.2.1-dev.2+Branch.dev.Sha.cb5fe2dc86a78fe9358da810d17952c82299ed3d</InformationalVersion>
|
|
||||||
<SuppressNETSdkWarningProperty>NETSDK1057</SuppressNETSdkWarningProperty>
|
<SuppressNETSdkWarningProperty>NETSDK1057</SuppressNETSdkWarningProperty>
|
||||||
<SuppressNETSdkWarningProperty>IDE1006</SuppressNETSdkWarningProperty>
|
<SuppressNETSdkWarningProperty>IDE1006</SuppressNETSdkWarningProperty>
|
||||||
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
|
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ public class CROSS_Series : Pair_TSeries_Indicator {
|
|||||||
val = TValue1.v == TValue2.v ? 0 : val;
|
val = TValue1.v == TValue2.v ? 0 : val;
|
||||||
double over = TValue1.v > TValue2.v ? 1 : val;
|
double over = TValue1.v > TValue2.v ? 1 : val;
|
||||||
|
|
||||||
val = (this._previous < over) ? 1 : -1;
|
val = (_previous < over) ? 1 : -1;
|
||||||
(System.DateTime t, double v) result = ((TValue1.t > TValue2.t) ? TValue1.t : TValue2.t,
|
val = ((_previous == over) || Double.IsNaN(this._previous) || (this._previous == 0)) ? 0 : val;
|
||||||
((this._previous == over) || Double.IsNaN(this._previous) || (this._previous == 0)) ? 0 : val);
|
(System.DateTime t, double v) result = ((TValue1.t > TValue2.t) ? TValue1.t : TValue2.t,val);
|
||||||
|
|
||||||
this._previous = over;
|
this._previous = over;
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,9 @@
|
|||||||
<Link>QuanTAlib\%(RecursiveDir)%(Filename)%(Extension)</Link>
|
<Link>QuanTAlib\%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<AdditionalFiles Include="..\.sonarlint\mihakralj_quantalib\CSharp\SonarLint.xml" Link="SonarLint.xml" />
|
||||||
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="TradingPlatform.BusinessLayer">
|
<Reference Include="TradingPlatform.BusinessLayer">
|
||||||
<HintPath>..\.github\TradingPlatform.BusinessLayer.dll</HintPath>
|
<HintPath>..\.github\TradingPlatform.BusinessLayer.dll</HintPath>
|
||||||
|
|||||||
+3
-4
@@ -1,6 +1,6 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net8.0</TargetFrameworks>
|
<TargetFrameworks>net7.0</TargetFrameworks>
|
||||||
<LangVersion>preview</LangVersion>
|
<LangVersion>preview</LangVersion>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
@@ -18,8 +18,7 @@
|
|||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Python.Included" Version="3.11.2" />
|
<PackageReference Include="pythonnet" Version="3.0.1" />
|
||||||
<PackageReference Include="pythonnet" Version="3.1.0-preview2023-03-04" />
|
|
||||||
<PackageReference Include="xunit" Version="2.4.2" />
|
<PackageReference Include="xunit" Version="2.4.2" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
@@ -29,7 +28,7 @@
|
|||||||
<PackageReference Include="TALib.NETCore" Version="0.4.4" />
|
<PackageReference Include="TALib.NETCore" Version="0.4.4" />
|
||||||
<PackageReference Include="Skender.Stock.Indicators" Version="3.0.0-preview1014-0015" />
|
<PackageReference Include="Skender.Stock.Indicators" Version="3.0.0-preview1014-0015" />
|
||||||
<PackageReference Include="Tulip.NETCore" Version="0.8.0.1" />
|
<PackageReference Include="Tulip.NETCore" Version="0.8.0.1" />
|
||||||
<PackageReference Include="System.Text.Json" Version="8.0.0-preview.2.23128.3" />
|
<PackageReference Include="System.Text.Json" Version="8.0.0-preview.3.23174.8" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Calculations\Calculations.csproj" />
|
<ProjectReference Include="..\Calculations\Calculations.csproj" />
|
||||||
|
|||||||
@@ -1,439 +1,416 @@
|
|||||||
using Xunit;
|
using Xunit;
|
||||||
using System;
|
using System;
|
||||||
using QuanTAlib;
|
using QuanTAlib;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Runtime.InteropServices.Marshalling;
|
||||||
using Python.Runtime;
|
using Python.Runtime;
|
||||||
using Python.Included;
|
|
||||||
|
|
||||||
namespace Validations;
|
namespace Validations;
|
||||||
|
|
||||||
/*
|
public class PandasTA : IDisposable {
|
||||||
public class PandasTA : IDisposable
|
private bool disposed = false;
|
||||||
{
|
|
||||||
private readonly GBM_Feed bars;
|
private readonly GBM_Feed bars;
|
||||||
private readonly Random rnd = new();
|
private readonly Random rnd = new();
|
||||||
private readonly int period, skip;
|
private readonly int period, skip;
|
||||||
private int digits;
|
private readonly int digits;
|
||||||
private readonly string dllpath;
|
|
||||||
private readonly dynamic np;
|
private readonly dynamic np;
|
||||||
private readonly dynamic ta;
|
private readonly dynamic ta;
|
||||||
private readonly dynamic pd;
|
private readonly dynamic pd;
|
||||||
private readonly dynamic df;
|
private readonly dynamic df;
|
||||||
|
|
||||||
public PandasTA() {
|
public PandasTA() {
|
||||||
bars = new(Bars: 5000, Volatility: 0.8, Drift: 0.0);
|
bars = new GBM_Feed(5000, 0.8, 0.0);
|
||||||
period = rnd.Next(maxValue: 28) + 3;
|
period = rnd.Next(28) + 3;
|
||||||
skip = period+10;
|
skip = period + 50;
|
||||||
digits = 8;
|
digits = 8;
|
||||||
|
|
||||||
Installer.InstallPath = Path.GetFullPath(path: ".");
|
var pythonDLL = PythonLibrary.Locate();
|
||||||
Installer.SetupPython().Wait();
|
Runtime.PythonDLL = pythonDLL;
|
||||||
Installer.TryInstallPip();
|
|
||||||
Installer.PipInstallModule(module_name: "numpy");
|
|
||||||
Installer.PipInstallModule(module_name: "pandas");
|
|
||||||
Installer.PipInstallModule(module_name: "pandas-ta");
|
|
||||||
dllpath = Installer.InstallPath + "\\" + Installer.InstallDirectory + "\\" + Runtime.PythonDLL;
|
|
||||||
Runtime.PythonDLL = dllpath;
|
|
||||||
PythonEngine.Initialize();
|
PythonEngine.Initialize();
|
||||||
|
|
||||||
np = Py.Import(name: "numpy");
|
np = Py.Import("numpy");
|
||||||
pd = Py.Import(name: "pandas");
|
pd = Py.Import("pandas");
|
||||||
ta = Py.Import(name: "pandas_ta");
|
ta = Py.Import("pandas_ta");
|
||||||
|
|
||||||
string[] cols = { "open", "high", "low", "close", "volume" };
|
string[] cols = {"open", "high", "low", "close", "volume"};
|
||||||
double[,] ary = new double[bars.Count, 5];
|
var ary = new double[bars.Count, 5];
|
||||||
for (int i = 0; i < bars.Count; i++) {
|
for (var i = 0; i < bars.Count; i++) {
|
||||||
ary[i, 0] = bars.Open[i].v;
|
ary[i, 0] = bars.Open[i].v;
|
||||||
ary[i, 1] = bars.High[i].v;
|
ary[i, 1] = bars.High[i].v;
|
||||||
ary[i, 2] = bars.Low[i].v;
|
ary[i, 2] = bars.Low[i].v;
|
||||||
ary[i, 3] = bars.Close[i].v;
|
ary[i, 3] = bars.Close[i].v;
|
||||||
ary[i, 4] = bars.Volume[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));
|
df = ta.DataFrame(data: np.array(ary), index: np.array(bars.Close.t), columns: np.array(cols));
|
||||||
}
|
}
|
||||||
public void Dispose()
|
|
||||||
{
|
public void Dispose() {
|
||||||
PythonEngine.Shutdown();
|
Dispose(true);
|
||||||
GC.SuppressFinalize(this);
|
PythonEngine.Shutdown();
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact] void ADL() {
|
~PandasTA() {
|
||||||
ADL_Series QL = new(bars);
|
Dispose(false);
|
||||||
var pta = df.ta.ad(high: df.high, low: df.low, close:df.close, volume:df.volume);
|
}
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = QL[i-1].v;
|
|
||||||
double PanTA_item = (double)pta[i-1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
|
|
||||||
|
protected virtual void Dispose(bool disposing) {
|
||||||
|
if (!disposed) {
|
||||||
|
disposed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
[Fact] void ADOSC() {
|
|
||||||
ADOSC_Series QL = new(bars);
|
|
||||||
var pta = df.ta.adosc(high: df.high, low: df.low, close: df.close, volume: df.volume);
|
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[Fact] void ATR() {
|
|
||||||
ATR_Series QL = new(bars, period);
|
|
||||||
var pta = df.ta.atr(high: df.high, low: df.low, close: df.close, length: period);
|
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[Fact]
|
[Fact]
|
||||||
void BBANDS() {
|
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);
|
BBANDS_Series QL = new(bars.Close, period);
|
||||||
var pta = df.ta.bbands(close: df.close, length: period).to_numpy();
|
var pta = df.ta.bbands(close: df.close, length: period).to_numpy();
|
||||||
for (int i = QL.Length-1; i > skip; i--) {
|
for (var i = QL.Length - 1; i > skip; i--) {
|
||||||
double QL_item = QL.Lower[i].v;
|
var QL_item = QL.Lower[i].v;
|
||||||
double PanTA_item = (double)pta[i][0]; //lower
|
var PanTA_item = (double) pta[i][0]; //lower
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||||
QL_item = QL.Mid[i].v;
|
QL_item = QL.Mid[i].v;
|
||||||
PanTA_item = (double)pta[i][1]; //mid
|
PanTA_item = (double) pta[i][1]; //mid
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||||
QL_item = QL.Upper[i].v;
|
QL_item = QL.Upper[i].v;
|
||||||
PanTA_item = (double)pta[i][2]; //upper
|
PanTA_item = (double) pta[i][2]; //upper
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[Fact] void BIAS() {
|
|
||||||
|
[Fact]
|
||||||
|
private void BIAS() {
|
||||||
BIAS_Series QL = new(bars.Close, period, false);
|
BIAS_Series QL = new(bars.Close, period, false);
|
||||||
var pta = df.ta.bias(close: df.close, length: period);
|
var pta = df.ta.bias(close: df.close, length: period);
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
for (var i = QL.Length - 1; i > skip; i--) {
|
||||||
{
|
var QL_item = QL[i - 1].v;
|
||||||
double QL_item = QL[i - 1].v;
|
var PanTA_item = (double) pta[i - 1];
|
||||||
double PanTA_item = (double)pta[i - 1];
|
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
[Fact]
|
[Fact]
|
||||||
void CCI() {
|
private void CCI() {
|
||||||
CCI_Series QL = new(bars, period, false);
|
CCI_Series QL = new(bars, period, false);
|
||||||
var pta = df.ta.cci(close: df.close, length: period);
|
var pta = df.ta.cci(close: df.close, length: period);
|
||||||
for (int i = QL.Length-1; i > skip; i--) {
|
for (var i = QL.Length - 1; i > skip; i--) {
|
||||||
double QL_item = QL[i - 1].v;
|
var QL_item = QL[i - 1].v;
|
||||||
double PanTA_item = (double)pta[i - 1];
|
var PanTA_item = (double) pta[i - 1];
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
void CMO() {
|
private void DEMA() {
|
||||||
CMO_Series QL = new(bars.Close, period, false);
|
|
||||||
var pta = df.ta.cmo(close: df.close, length: period);
|
|
||||||
for (int i = QL.Length-1; i > skip; i--) {
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact] void DEMA() {
|
|
||||||
DEMA_Series QL = new(bars.Close, period, false);
|
DEMA_Series QL = new(bars.Close, period, false);
|
||||||
var pta = df.ta.dema(close: df.close, length: period);
|
var pta = df.ta.dema(close: df.close, length: period);
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
for (var i = QL.Length - 1; i > skip; i--) {
|
||||||
{
|
var QL_item = QL[i - 1].v;
|
||||||
double QL_item = QL[i - 1].v;
|
var PanTA_item = (double) pta[i - 1];
|
||||||
double PanTA_item = (double)pta[i - 1];
|
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[Fact] void EMA() {
|
[Fact]
|
||||||
|
private void EMA() {
|
||||||
EMA_Series QL = new(bars.Close, period, false);
|
EMA_Series QL = new(bars.Close, period, false);
|
||||||
var pta = df.ta.ema(close: df.close, length: period);
|
var pta = df.ta.ema(close: df.close, length: period);
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
for (var i = QL.Length - 1; i > skip; i--) {
|
||||||
{
|
var QL_item = QL[i - 1].v;
|
||||||
double QL_item = QL[i - 1].v;
|
var PanTA_item = (double) pta[i - 1];
|
||||||
double PanTA_item = (double)pta[i - 1];
|
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact] void ENTROPY() {
|
|
||||||
ENTROPY_Series QL = new(bars.Close, period, useNaN: false);
|
|
||||||
var pta = df.ta.entropy(close: df.close, length: period);
|
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[Fact] void HL2() {
|
|
||||||
var pta = df.ta.hl2(high: df.high, low: df.low);
|
|
||||||
for (int i = bars.HL2.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = bars.HL2[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
[Fact] void HLC3() {
|
|
||||||
|
[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);
|
var pta = df.ta.hlc3(high: df.high, low: df.low, close: df.close);
|
||||||
for (int i = bars.HLC3.Length; i > skip; i--)
|
for (var i = bars.HLC3.Length; i > skip; i--) {
|
||||||
{
|
var QL_item = bars.HLC3[i - 1].v;
|
||||||
double QL_item = bars.HLC3[i - 1].v;
|
var PanTA_item = (double) pta[i - 1];
|
||||||
double PanTA_item = (double)pta[i - 1];
|
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
[Fact] void HMA() {
|
[Fact]
|
||||||
|
private void HMA() {
|
||||||
HMA_Series QL = new(bars.Close, period, false);
|
HMA_Series QL = new(bars.Close, period, false);
|
||||||
var pta = df.ta.hma(close: df.close, length: period);
|
var pta = df.ta.hma(close: df.close, length: period);
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
for (var i = QL.Length - 1; i > skip; i--) {
|
||||||
{
|
var QL_item = QL[i - 1].v;
|
||||||
double QL_item = QL[i - 1].v;
|
var PanTA_item = (double) pta[i - 1];
|
||||||
double PanTA_item = (double)pta[i - 1];
|
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
[Fact] void HWMA() {
|
|
||||||
HWMA_Series QL = new(bars.Close, useNaN: false);
|
|
||||||
var pta = df.ta.hwma(close: df.close);
|
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
[Fact] void KAMA() {
|
|
||||||
KAMA_Series QL = new(bars.Close, period);
|
|
||||||
var pta = df.ta.kama(close: df.close, length: period);
|
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[Fact] void KURTOSIS() {
|
|
||||||
KURTOSIS_Series QL = new(bars.Close, period, useNaN: false);
|
|
||||||
var pta = df.ta.kurtosis(close: df.close, length: period);
|
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[Fact]
|
[Fact]
|
||||||
void MACD() {
|
private void KURTOSIS() {
|
||||||
MACD_Series QL = new(bars.Close, 26,fast: 12,signal:9);
|
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();
|
var pta = df.ta.macd(close: df.close).to_numpy();
|
||||||
for (int i = QL.Length-1; i > skip; i--) {
|
for (var i = QL.Length - 1; i > skip; i--) {
|
||||||
double QL_item = QL[i - 1].v;
|
var QL_item = QL[i - 1].v;
|
||||||
double PanTA_item = (double)pta[i - 1][0];
|
var PanTA_item = (double) pta[i - 1][0];
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||||
QL_item = QL.Signal[i - 1].v;
|
QL_item = QL.Signal[i - 1].v;
|
||||||
PanTA_item = (double)pta[i - 1][2];
|
PanTA_item = (double) pta[i - 1][2];
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[Fact] void MAD()
|
|
||||||
{
|
[Fact]
|
||||||
MAD_Series QL = new(bars.Close, period, useNaN: false);
|
private void MAD() {
|
||||||
|
MAD_Series QL = new(bars.Close, period, false);
|
||||||
var pta = df.ta.mad(close: df.close, length: period);
|
var pta = df.ta.mad(close: df.close, length: period);
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
for (var i = QL.Length - 1; i > skip; i--) {
|
||||||
{
|
var QL_item = QL[i - 1].v;
|
||||||
double QL_item = QL[i - 1].v;
|
var PanTA_item = (double) pta[i - 1];
|
||||||
double PanTA_item = (double)pta[i - 1];
|
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
[Fact] void MEDIAN() {
|
[Fact]
|
||||||
|
private void MEDIAN() {
|
||||||
MEDIAN_Series QL = new(bars.Close, period);
|
MEDIAN_Series QL = new(bars.Close, period);
|
||||||
var pta = df.ta.median(close: df.close, length: period);
|
var pta = df.ta.median(close: df.close, length: period);
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
for (var i = QL.Length - 1; i > skip; i--) {
|
||||||
{
|
var QL_item = QL[i - 1].v;
|
||||||
double QL_item = QL[i - 1].v;
|
var PanTA_item = (double) pta[i - 1];
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[Fact] void OBV() {
|
|
||||||
OBV_Series QL = new(bars);
|
|
||||||
var pta = df.ta.obv(close: df.close, volume: df.volume);
|
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[Fact] void OHLC4() {
|
|
||||||
var pta = df.ta.ohlc4(open: df.open, high: df.high, low: df.low, close: df.close);
|
|
||||||
for (int i = bars.OHLC4.Length; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = bars.OHLC4[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[Fact] void RMA() {
|
|
||||||
RMA_Series QL = new(bars.Close, period, false);
|
|
||||||
var pta = df.ta.rma(close: df.close, length: period);
|
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[Fact] void RSI() {
|
|
||||||
RSI_Series QL = new(bars.Close, period);
|
|
||||||
var pta = df.ta.rsi(close: df.close, length: period);
|
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[Fact] void SDEV() {
|
|
||||||
SDEV_Series QL = new(bars.Close, period, useNaN: false);
|
|
||||||
var pta = df.ta.stdev(close: df.close, length: period, ddof: 0);
|
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact] void SMA() {
|
|
||||||
SMA_Series QL = new(bars.Close, period, false);
|
|
||||||
var pta = df.ta.sma(close: df.close, length: period);
|
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact] void SSDEV() {
|
|
||||||
SSDEV_Series QL = new(bars.Close, period, useNaN: false);
|
|
||||||
var pta = df.ta.stdev(close: df.close, length: period, ddof: 1);
|
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[Fact] void SVARIANCE() {
|
|
||||||
SVAR_Series QL = new(bars.Close, period);
|
|
||||||
var pta = df.ta.variance(close: df.close, length: period, ddof: 1);
|
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact] void T3() {
|
|
||||||
T3_Series QL = new(source: bars.Close, period: period, vfactor: 0.7, useNaN: false);
|
|
||||||
var pta = df.ta.t3(close: df.close, length: period, a: 0.7);
|
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[Fact] void TEMA() {
|
|
||||||
TEMA_Series QL = new(bars.Close, period, false);
|
|
||||||
var pta = df.ta.tema(close: df.close, length: period);
|
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[Fact] void TR() {
|
|
||||||
TR_Series QL = new(bars);
|
|
||||||
var pta = df.ta.true_range(high: df.high, low: df.low, close: df.close);
|
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[Fact] 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 (int i = QL.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[Fact] void TRIX() {
|
|
||||||
TRIX_Series QL = new(bars.Close, period);
|
|
||||||
var pta = df.ta.trix(close: df.close, length: period).to_numpy();
|
|
||||||
for (int i = QL.Length-1; i > skip; i--) {
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1][0];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[Fact] void VARIANCE() {
|
|
||||||
|
[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_Series QL = new(bars.Close, period);
|
||||||
var pta = df.ta.variance(close: df.close, length: period, ddof:0);
|
var pta = df.ta.variance(close: df.close, length: period, ddof: 0);
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
for (var i = QL.Length - 1; i > skip; i--) {
|
||||||
{
|
var QL_item = QL[i - 1].v;
|
||||||
double QL_item = QL[i - 1].v;
|
var PanTA_item = (double) pta[i - 1];
|
||||||
double PanTA_item = (double)pta[i - 1];
|
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
[Fact] void WMA() {
|
[Fact]
|
||||||
|
private void WMA() {
|
||||||
WMA_Series QL = new(bars.Close, period, false);
|
WMA_Series QL = new(bars.Close, period, false);
|
||||||
var pta = df.ta.wma(close: df.close, length: period);
|
var pta = df.ta.wma(close: df.close, length: period);
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
for (var i = QL.Length - 1; i > skip; i--) {
|
||||||
{
|
var QL_item = QL[i - 1].v;
|
||||||
double QL_item = QL[i - 1].v;
|
var PanTA_item = (double) pta[i - 1];
|
||||||
double PanTA_item = (double)pta[i - 1];
|
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
[Fact] void ZLEMA() {
|
|
||||||
ZLEMA_Series QL = new(bars.Close, period, false);
|
|
||||||
var pta = df.ta.zlma(close: df.close, length: period);
|
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double PanTA_item = (double)pta[i - 1];
|
|
||||||
Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[Fact] void ZSCORE() {
|
|
||||||
ZSCORE_Series QL = new(bars.Close, period, useNaN: false);
|
|
||||||
var pta = df.ta.zscore(close: df.close, length: period, ddof: 0);
|
|
||||||
for (int i = QL.Length-1; i > skip; i--)
|
|
||||||
{
|
|
||||||
double QL_item = QL[i - 1].v;
|
|
||||||
double 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,6 +30,7 @@ public class Skender
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ADL()
|
public void ADL()
|
||||||
{
|
{
|
||||||
@@ -42,6 +43,7 @@ public class Skender
|
|||||||
Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits));
|
Assert.InRange(SK_item! - QL_item, -Math.Pow(10,-digits), Math.Pow(10,-digits));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ALMA()
|
public void ALMA()
|
||||||
{
|
{
|
||||||
@@ -57,7 +59,7 @@ public class Skender
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ATR()
|
public void ATR()
|
||||||
{
|
{
|
||||||
ATR_Series QL = new(bars, period, false);
|
ATR_Series QL = new(bars, period:period,useNaN: false);
|
||||||
var SK = quotes.GetAtr(period).Select(i => i.Atr.Null2NaN()!);
|
var SK = quotes.GetAtr(period).Select(i => i.Atr.Null2NaN()!);
|
||||||
for (int i = QL.Length; i > skip; i--)
|
for (int i = QL.Length; i > skip; i--)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public class Ta_Lib
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ATR()
|
public void ATR()
|
||||||
{
|
{
|
||||||
ATR_Series QL = new(bars, period, false);
|
ATR_Series QL = new(bars, period:period, useNaN: false);
|
||||||
Core.Atr(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
|
Core.Atr(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period);
|
||||||
for (int i = QL.Length - 1; i > skip; i--)
|
for (int i = QL.Length - 1; i > skip; i--)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public class Tulip_Test
|
|||||||
double[][] arrin = { inhigh, inlow, inclose };
|
double[][] arrin = { inhigh, inlow, inclose };
|
||||||
double[][] arrout = { outdata };
|
double[][] arrout = { outdata };
|
||||||
|
|
||||||
ATR_Series QL = new(bars, period, false);
|
ATR_Series QL = new(bars, period:period, useNaN:false);
|
||||||
Tulip.Indicators.atr.Run(inputs: arrin, options: new double[] { period }, outputs: arrout);
|
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
|
//Tulip ATR doesn't use warm-up SMA, compensating with 200 warming bars
|
||||||
for (int i = QL.Length - 1; i > 200+skip; i--)
|
for (int i = QL.Length - 1; i > 200+skip; i--)
|
||||||
|
|||||||
Reference in New Issue
Block a user