mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-25 22:08:05 +00:00
Sonar changes
This commit is contained in:
@@ -30,13 +30,12 @@ public class ZLMA_chart : Indicator
|
|||||||
private int matype = 2;
|
private int matype = 2;
|
||||||
|
|
||||||
#endregion Parameters
|
#endregion Parameters
|
||||||
|
|
||||||
private TBars bars;
|
private TBars bars;
|
||||||
///////
|
///////
|
||||||
private ZL_Series zerolag;
|
|
||||||
private TSeries indicator;
|
private TSeries indicator;
|
||||||
///////
|
///////
|
||||||
|
|
||||||
public ZLMA_chart()
|
public ZLMA_chart()
|
||||||
{
|
{
|
||||||
this.SeparateWindow = false;
|
this.SeparateWindow = false;
|
||||||
|
|||||||
@@ -41,8 +41,6 @@ public class JMA_Series : Single_TSeries_Indicator
|
|||||||
this.rvolty = Math.Exp((1 / this.pow1) * Math.Log(len1));
|
this.rvolty = Math.Exp((1 / this.pow1) * Math.Log(len1));
|
||||||
this.len2 = Math.Sqrt(0.5 * (_p - 1)) * len1;
|
this.len2 = Math.Sqrt(0.5 * (_p - 1)) * len1;
|
||||||
this.beta = 0.45 * (_p - 1) / (0.45 * (_p - 1) + 2);
|
this.beta = 0.45 * (_p - 1) / (0.45 * (_p - 1) + 2);
|
||||||
this._l = (int)Math.Round(this._p - 1 * 0.5);
|
|
||||||
|
|
||||||
if (base._data.Count > 0) { base.Add(base._data); }
|
if (base._data.Count > 0) { base.Add(base._data); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,71 +1,71 @@
|
|||||||
namespace QuanTAlib;
|
namespace QuanTAlib;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
/* <summary>
|
/* <summary>
|
||||||
ZLEMA: Zero Lag Exponential Moving Average
|
ZLEMA: Zero Lag Exponential Moving Average
|
||||||
The Zero lag exponential moving average (ZLEMA) indicator was created by John
|
The Zero lag exponential moving average (ZLEMA) indicator was created by John
|
||||||
Ehlers and Ric Way.
|
Ehlers and Ric Way.
|
||||||
|
|
||||||
The formula for a given N-Day period and for a given Data series is:
|
The formula for a given N-Day period and for a given Data series is:
|
||||||
Lag = (Period-1)/2
|
Lag = (Period-1)/2
|
||||||
Ema Data = {Data+(Data-Data(Lag days ago))
|
Ema Data = {Data+(Data-Data(Lag days ago))
|
||||||
ZLEMA = EMA (EmaData,Period)
|
ZLEMA = EMA (EmaData,Period)
|
||||||
|
|
||||||
Remark:
|
Remark:
|
||||||
The idea is do a regular exponential moving average (EMA) calculation but on a
|
The idea is do a regular exponential moving average (EMA) calculation but on a
|
||||||
de-lagged data instead of doing it on the regular data. Data is de-lagged by
|
de-lagged data instead of doing it on the regular data. Data is de-lagged by
|
||||||
removing the data from "lag" days ago thus removing (or attempting to remove)
|
removing the data from "lag" days ago thus removing (or attempting to remove)
|
||||||
the cumulative lag effect of the moving average.
|
the cumulative lag effect of the moving average.
|
||||||
|
|
||||||
</summary> */
|
</summary> */
|
||||||
|
|
||||||
public class ZLEMA_Series : Single_TSeries_Indicator
|
public class ZLEMA_Series : Single_TSeries_Indicator
|
||||||
{
|
{
|
||||||
private readonly System.Collections.Generic.List<double> _buffer = new();
|
private readonly System.Collections.Generic.List<double> _buffer = new();
|
||||||
private readonly double _k, _k1m;
|
private readonly double _k, _k1m;
|
||||||
private double _lastema, _lastlastema;
|
private double _lastema, _lastlastema;
|
||||||
|
|
||||||
public ZLEMA_Series(TSeries source, int period, bool useNaN = false) : base(source, period, useNaN)
|
public ZLEMA_Series(TSeries source, int period, bool useNaN = false) : base(source, period, useNaN)
|
||||||
{
|
{
|
||||||
this._k = 2.0 / (this._p + 1);
|
this._k = 2.0 / (this._p + 1);
|
||||||
this._k1m = 1.0 - this._k;
|
this._k1m = 1.0 - this._k;
|
||||||
this._lastema = this._lastlastema = double.NaN;
|
this._lastema = this._lastlastema = double.NaN;
|
||||||
if (base._data.Count > 0)
|
if (base._data.Count > 0)
|
||||||
{ base.Add(base._data); }
|
{ base.Add(base._data); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Add((System.DateTime t, double v) TValue, bool update)
|
public override void Add((System.DateTime t, double v) TValue, bool update)
|
||||||
{
|
{
|
||||||
int _lag = (int)((_p - 1) * 0.5);
|
int _lag = (int)((_p - 1) * 0.5);
|
||||||
_lag = (this.Count - _lag < 0) ? 0 : this.Count - _lag;
|
_lag = (this.Count - _lag < 0) ? 0 : this.Count - _lag;
|
||||||
double _zl = TValue.v + (TValue.v - _data[_lag].v);
|
double _zl = TValue.v + (TValue.v - _data[_lag].v);
|
||||||
double _ema = 0;
|
double _ema = 0;
|
||||||
if (update)
|
if (update)
|
||||||
{ this._lastema = this._lastlastema; }
|
{ this._lastema = this._lastlastema; }
|
||||||
if (this.Count < this._p)
|
if (this.Count < this._p)
|
||||||
{
|
{
|
||||||
if (update)
|
if (update)
|
||||||
{ this._buffer[this._buffer.Count - 1] = _zl; }
|
{ this._buffer[this._buffer.Count - 1] = _zl; }
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this._buffer.Add(_zl);
|
this._buffer.Add(_zl);
|
||||||
}
|
}
|
||||||
if (this._buffer.Count > this._p)
|
if (this._buffer.Count > this._p)
|
||||||
{ this._buffer.RemoveAt(0); }
|
{ this._buffer.RemoveAt(0); }
|
||||||
|
|
||||||
for (int i = 0; i < this._buffer.Count; i++)
|
for (int i = 0; i < this._buffer.Count; i++)
|
||||||
{ _ema += this._buffer[i]; }
|
{ _ema += this._buffer[i]; }
|
||||||
_ema /= this._buffer.Count;
|
_ema /= this._buffer.Count;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_ema = TValue.v * this._k + this._lastema * this._k1m;
|
_ema = TValue.v * this._k + this._lastema * this._k1m;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._lastlastema = this._lastema;
|
this._lastlastema = this._lastema;
|
||||||
this._lastema = _ema;
|
this._lastema = _ema;
|
||||||
|
|
||||||
var ret = (TValue.t, this.Count < this._p - 1 && this._NaN ? double.NaN : _ema);
|
var ret = (TValue.t, this.Count < this._p - 1 && this._NaN ? double.NaN : _ema);
|
||||||
base.Add(ret, update);
|
base.Add(ret, update);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+119
-119
@@ -1,120 +1,120 @@
|
|||||||
using Xunit;
|
using Xunit;
|
||||||
using System;
|
using System;
|
||||||
using QuanTAlib;
|
using QuanTAlib;
|
||||||
using Python.Runtime;
|
using Python.Runtime;
|
||||||
using Python.Included;
|
using Python.Included;
|
||||||
|
|
||||||
namespace Validation;
|
namespace Validation;
|
||||||
public class PandasTA
|
public class PandasTA
|
||||||
{
|
{
|
||||||
private readonly RND_Feed bars;
|
private readonly RND_Feed bars;
|
||||||
private readonly Random rnd = new();
|
private readonly Random rnd = new();
|
||||||
private readonly int period;
|
private readonly int period;
|
||||||
private readonly dynamic ta;
|
private readonly dynamic ta;
|
||||||
private readonly dynamic df;
|
private readonly dynamic df;
|
||||||
|
|
||||||
public PandasTA()
|
public PandasTA()
|
||||||
{
|
{
|
||||||
this.bars = new(1000);
|
this.bars = new(1000);
|
||||||
this.period = this.rnd.Next(28) + 3;
|
this.period = this.rnd.Next(28) + 3;
|
||||||
|
|
||||||
Installer.SetupPython().Wait();
|
Installer.SetupPython().Wait();
|
||||||
Installer.TryInstallPip();
|
Installer.TryInstallPip();
|
||||||
Installer.PipInstallModule("numpy");
|
Installer.PipInstallModule("numpy");
|
||||||
Installer.PipInstallModule("pandas");
|
Installer.PipInstallModule("pandas");
|
||||||
Installer.PipInstallModule("pandas-ta");
|
Installer.PipInstallModule("pandas-ta");
|
||||||
PythonEngine.Initialize();
|
PythonEngine.Initialize();
|
||||||
this.ta = Py.Import("pandas_ta");
|
this.ta = Py.Import("pandas_ta");
|
||||||
this.df = this.ta.DataFrame(this.bars.Close.v);
|
this.df = this.ta.DataFrame(this.bars.Close.v);
|
||||||
}
|
}
|
||||||
|
|
||||||
~PandasTA()
|
~PandasTA()
|
||||||
{
|
{
|
||||||
PythonEngine.Shutdown();
|
PythonEngine.Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
void SMA()
|
void SMA()
|
||||||
{
|
{
|
||||||
SMA_Series QL = new(this.bars.Close, this.period, false);
|
SMA_Series QL = new(this.bars.Close, this.period, false);
|
||||||
var pta = this.ta.sma(close: this.df[0], length: this.period);
|
var pta = this.ta.sma(close: this.df[0], length: this.period);
|
||||||
|
|
||||||
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
[Fact]
|
[Fact]
|
||||||
void EMA()
|
void EMA()
|
||||||
{
|
{
|
||||||
EMA_Series QL = new(this.bars.Close, this.period, false);
|
EMA_Series QL = new(this.bars.Close, this.period, false);
|
||||||
var pta = this.ta.ema(close: this.df[0], length: this.period);
|
var pta = this.ta.ema(close: this.df[0], length: this.period);
|
||||||
|
|
||||||
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
void TEMA()
|
void TEMA()
|
||||||
{
|
{
|
||||||
TEMA_Series QL = new(this.bars.Close, this.period, false);
|
TEMA_Series QL = new(this.bars.Close, this.period, false);
|
||||||
var pta = this.ta.tema(close: this.df[0], length: this.period);
|
var pta = this.ta.tema(close: this.df[0], length: this.period);
|
||||||
|
|
||||||
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
void ENTP()
|
void ENTP()
|
||||||
{
|
{
|
||||||
ENTP_Series QL = new(this.bars.Close, this.period, useNaN:false);
|
ENTP_Series QL = new(this.bars.Close, this.period, useNaN:false);
|
||||||
var pta = this.ta.entropy(close: this.df[0], length: this.period);
|
var pta = this.ta.entropy(close: this.df[0], length: this.period);
|
||||||
|
|
||||||
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
void WMA()
|
void WMA()
|
||||||
{
|
{
|
||||||
WMA_Series QL = new(this.bars.Close, this.period, false);
|
WMA_Series QL = new(this.bars.Close, this.period, false);
|
||||||
var pta = this.ta.wma(close: this.df[0], length: this.period);
|
var pta = this.ta.wma(close: this.df[0], length: this.period);
|
||||||
|
|
||||||
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
void DEMA()
|
void DEMA()
|
||||||
{
|
{
|
||||||
DEMA_Series QL = new(this.bars.Close, this.period, false);
|
DEMA_Series QL = new(this.bars.Close, this.period, false);
|
||||||
var pta = this.ta.dema(close: this.df[0], length: this.period);
|
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));
|
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
void BIAS()
|
void BIAS()
|
||||||
{
|
{
|
||||||
BIAS_Series QL = new(this.bars.Close, this.period, false);
|
BIAS_Series QL = new(this.bars.Close, this.period, false);
|
||||||
var pta = this.ta.bias(close: this.df[0], length: this.period);
|
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));
|
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
void KURT()
|
void KURT()
|
||||||
{
|
{
|
||||||
KURT_Series QL = new(this.bars.Close, this.period, useNaN: false);
|
KURT_Series QL = new(this.bars.Close, this.period, useNaN: false);
|
||||||
var pta = this.ta.kurtosis(close: this.df[0], length: this.period);
|
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));
|
Assert.Equal(System.Math.Round((double)pta.tail(1), 4), Math.Round(QL.Last().v, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
void MAD()
|
void MAD()
|
||||||
{
|
{
|
||||||
MAD_Series QL = new(this.bars.Close, this.period, useNaN: false);
|
MAD_Series QL = new(this.bars.Close, this.period, useNaN: false);
|
||||||
var pta = this.ta.mad(close: this.df[0], length: this.period);
|
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));
|
Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7));
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user