mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-19 11:08:05 +00:00
Afirma + documentation +semver: patch
This commit is contained in:
@@ -17,15 +17,15 @@ public class Alma : AbstractBase
|
||||
private readonly int _period;
|
||||
private readonly double _offset;
|
||||
private readonly double _sigma;
|
||||
private readonly CircularBuffer? _buffer;
|
||||
private readonly CircularBuffer? _weight;
|
||||
private CircularBuffer? _buffer;
|
||||
private CircularBuffer? _weight;
|
||||
private double _norm;
|
||||
|
||||
/// <param name="period">The number of data points used in the ALMA calculation.</param>
|
||||
/// <param name="offset">Controls the smoothness and high-frequency filtering. Default is 0.85.</param>
|
||||
/// <param name="sigma">Controls the shape of the Gaussian distribution. Default is 6.</param>
|
||||
/// <exception cref="ArgumentException">Thrown when period is less than 1.</exception>
|
||||
public Alma(int period, double offset = 0.85, double sigma = 6)
|
||||
public Alma(int period, double offset = 0.85, double sigma = 6) : base()
|
||||
{
|
||||
if (period < 1)
|
||||
{
|
||||
@@ -36,8 +36,6 @@ public class Alma : AbstractBase
|
||||
_sigma = sigma;
|
||||
WarmupPeriod = period;
|
||||
Name = "Alma";
|
||||
_buffer = new CircularBuffer(_period);
|
||||
_weight = new CircularBuffer(_period);
|
||||
Init();
|
||||
}
|
||||
|
||||
@@ -54,6 +52,8 @@ public class Alma : AbstractBase
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
_buffer = new CircularBuffer(_period);
|
||||
_weight = new CircularBuffer(_period);
|
||||
_norm = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ public class Convolution : AbstractBase
|
||||
{
|
||||
private readonly double[] _kernel;
|
||||
private readonly int _kernelSize;
|
||||
private readonly CircularBuffer _buffer;
|
||||
private readonly double[] _normalizedKernel;
|
||||
private CircularBuffer _buffer;
|
||||
private double[] _normalizedKernel;
|
||||
|
||||
public Convolution(double[] kernel)
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@ public class Dema : AbstractBase
|
||||
private double _lastEma2, _p_lastEma2;
|
||||
private double _k, _e, _p_e;
|
||||
|
||||
public Dema(int period)
|
||||
public Dema(int period) : base()
|
||||
{
|
||||
if (period < 1)
|
||||
{
|
||||
|
||||
@@ -50,8 +50,8 @@ public class Dsma : AbstractBase
|
||||
_buffer = new CircularBuffer(period);
|
||||
|
||||
// SuperSmoother filter coefficients
|
||||
double _a1 = Math.Exp(-1.414 * Math.PI / (0.5 * period));
|
||||
double _b1 = 2 * _a1 * Math.Cos(1.414 * Math.PI / (0.5 * period));
|
||||
_a1 = Math.Exp(-1.414 * Math.PI / (0.5 * period));
|
||||
_b1 = 2 * _a1 * Math.Cos(1.414 * Math.PI / (0.5 * period));
|
||||
_c2 = _b1;
|
||||
_c3 = -_a1 * _a1;
|
||||
_c1 = 1 - _c2 - _c3;
|
||||
|
||||
+6
-8
@@ -25,14 +25,12 @@ public class Ema : AbstractBase
|
||||
// inherited _index
|
||||
// inherited _value
|
||||
private readonly int _period;
|
||||
private readonly CircularBuffer _sma;
|
||||
private CircularBuffer _sma;
|
||||
private double _lastEma, _p_lastEma;
|
||||
private double _e, _p_e;
|
||||
private readonly double _k;
|
||||
private bool _isInit, _p_isInit;
|
||||
private readonly bool _useSma;
|
||||
private double _k, _e, _p_e;
|
||||
private bool _isInit, _p_isInit, _useSma;
|
||||
|
||||
public Ema(int period, bool useSma = true)
|
||||
public Ema(int period, bool useSma = true) : base()
|
||||
{
|
||||
if (period < 1)
|
||||
{
|
||||
@@ -47,14 +45,13 @@ public class Ema : AbstractBase
|
||||
Init();
|
||||
}
|
||||
|
||||
public Ema(double alpha)
|
||||
public Ema(double alpha) : base()
|
||||
{
|
||||
_k = alpha;
|
||||
_useSma = false;
|
||||
_sma = new(1);
|
||||
_period = 1;
|
||||
WarmupPeriod = (int)Math.Ceiling(Math.Log(0.05) / Math.Log(1 - _k)); //95th percentile
|
||||
_sma = new(_period);
|
||||
Init();
|
||||
}
|
||||
|
||||
@@ -72,6 +69,7 @@ public class Ema : AbstractBase
|
||||
_lastEma = 0;
|
||||
_isInit = false;
|
||||
_p_isInit = false;
|
||||
_sma = new(_period);
|
||||
}
|
||||
|
||||
protected override void ManageState(bool isNew)
|
||||
|
||||
+6
-12
@@ -6,20 +6,14 @@ namespace QuanTAlib
|
||||
{
|
||||
private readonly int _period;
|
||||
private readonly double _fc;
|
||||
private readonly CircularBuffer _buffer;
|
||||
private CircularBuffer _buffer;
|
||||
private double _lastFrama;
|
||||
private double _prevLastFrama;
|
||||
|
||||
public Frama(int period, double fc = 0.5)
|
||||
public Frama(int period, double fc = 0.5) : base()
|
||||
{
|
||||
if (period < 2)
|
||||
{
|
||||
throw new ArgumentException("Period must be at least 2", nameof(period));
|
||||
}
|
||||
if (fc <= 0 || fc >= 1)
|
||||
{
|
||||
throw new ArgumentException("Fc must be between 0 and 1", nameof(fc));
|
||||
}
|
||||
|
||||
_period = period;
|
||||
_fc = fc;
|
||||
@@ -51,7 +45,7 @@ namespace QuanTAlib
|
||||
protected override double Calculation()
|
||||
{
|
||||
ManageState(Input.IsNew);
|
||||
|
||||
|
||||
_buffer.Add(Input.Value, Input.IsNew);
|
||||
|
||||
if (_buffer.Count < _period)
|
||||
@@ -84,11 +78,11 @@ namespace QuanTAlib
|
||||
}
|
||||
|
||||
double n1 = (hh - ll) / _period;
|
||||
double n2 = (hh1 - ll1 + hh2 - ll2) / half;
|
||||
double n2 = (hh1 - ll1 + hh2 - ll2) / (_period / 2);
|
||||
|
||||
double d = (Math.Log(n1 + double.Epsilon) - Math.Log(n2 + double.Epsilon)) / Math.Log(2);
|
||||
double d = (Math.Log(n2 + double.Epsilon) - Math.Log(n1 + double.Epsilon)) / Math.Log(2);
|
||||
|
||||
double alpha = Math.Exp(-4.6 * (d - 1) * _fc);
|
||||
double alpha = Math.Exp(-4.6 * (d - 1));
|
||||
alpha = Math.Max(Math.Min(alpha, 1), 0.01); // Ensure alpha is between 0.01 and 1
|
||||
|
||||
_lastFrama = alpha * (Input.Value - _lastFrama) + _lastFrama;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//not working yet
|
||||
//TODO consistency test
|
||||
|
||||
namespace QuanTAlib;
|
||||
using QuanTAlib;
|
||||
|
||||
public class Htit : AbstractBase
|
||||
{
|
||||
@@ -18,10 +18,10 @@ public class Htit : AbstractBase
|
||||
private readonly CircularBuffer _sdBuffer = new(2);
|
||||
private readonly CircularBuffer _itBuffer = new(4);
|
||||
|
||||
private double _lastPd;
|
||||
private double _p_lastPd;
|
||||
private double _lastPd = 0;
|
||||
private double _p_lastPd = 0;
|
||||
|
||||
public Htit()
|
||||
public Htit() : base()
|
||||
{
|
||||
Name = "Htit";
|
||||
WarmupPeriod = 12;
|
||||
|
||||
@@ -15,7 +15,7 @@ public class Hwma : AbstractBase
|
||||
{
|
||||
}
|
||||
|
||||
public Hwma(int period, double nA, double nB, double nC)
|
||||
public Hwma(int period, double nA, double nB, double nC) : base()
|
||||
{
|
||||
if (period < 1)
|
||||
{
|
||||
|
||||
+19
-13
@@ -1,34 +1,37 @@
|
||||
namespace QuanTAlib;
|
||||
using QuanTAlib;
|
||||
//TODO consistency test
|
||||
public class Jma : AbstractBase
|
||||
{
|
||||
private readonly int Period;
|
||||
public readonly int Period;
|
||||
private readonly double _phase;
|
||||
private readonly CircularBuffer _values;
|
||||
private readonly CircularBuffer _voltyShort;
|
||||
private readonly CircularBuffer _vsumBuff;
|
||||
private readonly int _vshort, _vlong;
|
||||
private CircularBuffer _values;
|
||||
private CircularBuffer _voltyShort;
|
||||
private CircularBuffer _vsumBuff;
|
||||
private CircularBuffer _avoltyBuff;
|
||||
|
||||
private double _beta, _len1, _pow1;
|
||||
private double _upperBand, _lowerBand, _prevMa1, _prevDet0, _prevDet1, _prevJma;
|
||||
private double _p_UpperBand, _p_LowerBand, _p_prevMa1, _p_prevDet0, _p_prevDet1, _p_prevJma;
|
||||
|
||||
public Jma(int period, double phase = 0, int vshort = 10)
|
||||
public Jma(int period, double phase = 0, int vshort = 10) : base()
|
||||
{
|
||||
if (period < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(period), "Period must be greater than or equal to 1.");
|
||||
}
|
||||
Period = period;
|
||||
int _vshort = vshort;
|
||||
int _vlong = 65;
|
||||
_vshort = vshort;
|
||||
_vlong = 65;
|
||||
_phase = Math.Clamp((phase * 0.01) + 1.5, 0.5, 2.5);
|
||||
|
||||
_values = new CircularBuffer(period);
|
||||
_voltyShort = new CircularBuffer(_vshort);
|
||||
_voltyShort = new CircularBuffer(vshort);
|
||||
_vsumBuff = new CircularBuffer(_vlong);
|
||||
_avoltyBuff = new CircularBuffer(2);
|
||||
|
||||
Name = "JMA";
|
||||
WarmupPeriod = 65;
|
||||
WarmupPeriod = period * 2;
|
||||
Init();
|
||||
}
|
||||
|
||||
@@ -39,6 +42,9 @@ public class Jma : AbstractBase
|
||||
_beta = 0.45 * (Period - 1) / (0.45 * (Period - 1) + 2);
|
||||
_len1 = Math.Max((Math.Log(Math.Sqrt(Period - 1)) / Math.Log(2.0)) + 2.0, 0);
|
||||
_pow1 = Math.Max(_len1 - 2.0, 0.5);
|
||||
_avoltyBuff.Clear();
|
||||
_avoltyBuff.Add(0, true);
|
||||
_avoltyBuff.Add(0, true);
|
||||
base.Init();
|
||||
}
|
||||
|
||||
@@ -91,9 +97,9 @@ public class Jma : AbstractBase
|
||||
double vsum = _vsumBuff.Newest() + 0.1 * (volty - _voltyShort.Oldest());
|
||||
_vsumBuff.Add(vsum, Input.IsNew);
|
||||
|
||||
double avolty = 0;
|
||||
for (int i = 0; i < _vsumBuff.Count; i++) { avolty += _vsumBuff[i]; }
|
||||
avolty /= _vsumBuff.Count;
|
||||
double prevAvolty = _avoltyBuff.Newest();
|
||||
double avolty = prevAvolty + 2.0 / (Math.Max(4.0 * Period, 30) + 1.0) * (vsum - prevAvolty);
|
||||
_avoltyBuff.Add(avolty, Input.IsNew);
|
||||
|
||||
double dVolty = (avolty > 0) ? volty / avolty : 0;
|
||||
dVolty = Math.Min(Math.Max(dVolty, 1.0), Math.Pow(_len1, 1.0 / _pow1));
|
||||
|
||||
@@ -6,10 +6,10 @@ public class Kama : AbstractBase
|
||||
{
|
||||
private readonly int _period;
|
||||
private readonly double _scFast, _scSlow;
|
||||
private readonly CircularBuffer? _buffer;
|
||||
private CircularBuffer? _buffer;
|
||||
private double _lastKama, _p_lastKama;
|
||||
|
||||
public Kama(int period, int fast = 2, int slow = 30)
|
||||
public Kama(int period, int fast = 2, int slow = 30) : base()
|
||||
{
|
||||
if (period < 1)
|
||||
{
|
||||
@@ -20,7 +20,6 @@ public class Kama : AbstractBase
|
||||
_scSlow = 2.0 / (slow + 1);
|
||||
WarmupPeriod = period;
|
||||
Name = $"Kama({_period}, {fast}, {slow})";
|
||||
_buffer = new CircularBuffer(_period + 1);
|
||||
Init();
|
||||
}
|
||||
|
||||
@@ -33,7 +32,7 @@ public class Kama : AbstractBase
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
_buffer = new CircularBuffer(_period + 1);
|
||||
_lastKama = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,12 +10,10 @@ public class Ltma : AbstractBase
|
||||
|
||||
public double Gamma => _gamma;
|
||||
|
||||
public Ltma(double gamma = 0.1)
|
||||
public Ltma(double gamma = 0.1) : base()
|
||||
{
|
||||
if (gamma < 0 || gamma > 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(gamma), "Gamma must be between 0 and 1.");
|
||||
}
|
||||
_gamma = gamma;
|
||||
Name = $"Laguerre({gamma:F2})";
|
||||
WarmupPeriod = 4; // Minimum number of samples needed
|
||||
|
||||
@@ -8,13 +8,12 @@ public class Maaf : AbstractBase
|
||||
{
|
||||
private readonly CircularBuffer _priceBuffer;
|
||||
private readonly CircularBuffer _smoothBuffer;
|
||||
private double _prevFilter, _prevValue2;
|
||||
private readonly double _threshold;
|
||||
private double _prevFilter, _prevValue2, _threshold;
|
||||
private double _p_prevFilter, _p_prevValue2;
|
||||
|
||||
private readonly int _period;
|
||||
|
||||
public Maaf(int Period = 39, double Threshold = 0.002)
|
||||
public Maaf(int Period = 39, double Threshold = 0.002) : base()
|
||||
{
|
||||
_period = Period;
|
||||
_threshold = Threshold;
|
||||
@@ -95,10 +94,7 @@ public class Maaf : AbstractBase
|
||||
length -= 2;
|
||||
}
|
||||
|
||||
if (length < 3)
|
||||
{
|
||||
length = 3;
|
||||
}
|
||||
if (length < 3) length = 3;
|
||||
|
||||
double finalAlpha = 2.0 / (length + 1);
|
||||
double filter = finalAlpha * (smooth - _prevFilter) + _prevFilter;
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
namespace QuanTAlib;
|
||||
|
||||
using QuanTAlib;
|
||||
using System;
|
||||
|
||||
public class Mama : AbstractBase
|
||||
{
|
||||
private readonly double _fastLimit, _slowLimit;
|
||||
private readonly CircularBuffer _pr, _sm, _dt, _i1, _q1, _i2, _q2, _re, _im, _pd, _ph;
|
||||
private CircularBuffer _pr, _sm, _dt, _i1, _q1, _i2, _q2, _re, _im, _pd, _ph;
|
||||
private double _mama, _fama;
|
||||
private double _prevMama, _prevFama, _sumPr;
|
||||
private double _p_prevMama, _p_prevFama, _p_sumPr;
|
||||
|
||||
public TValue Fama { get; private set; }
|
||||
|
||||
public Mama(double fastLimit = 0.5, double slowLimit = 0.05)
|
||||
public Mama(double fastLimit = 0.5, double slowLimit = 0.05) : base()
|
||||
{
|
||||
Fama = new TValue();
|
||||
Name = $"Mama({_fastLimit:F2}, {_slowLimit:F2})";
|
||||
|
||||
@@ -5,7 +5,7 @@ public class Mgdi : AbstractBase
|
||||
private readonly int _period;
|
||||
private readonly double _kFactor;
|
||||
private double _prevMd, _p_prevMd;
|
||||
public Mgdi(int period, double kFactor = 0.6)
|
||||
public Mgdi(int period, double kFactor = 0.6) : base()
|
||||
{
|
||||
if (period <= 0)
|
||||
{
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ namespace QuanTAlib
|
||||
private readonly CircularBuffer _buffer;
|
||||
private double _lastMma;
|
||||
|
||||
public Mma(int period)
|
||||
public Mma(int period) : base()
|
||||
{
|
||||
if (period < 2)
|
||||
{
|
||||
|
||||
+11
-5
@@ -2,25 +2,31 @@ namespace QuanTAlib;
|
||||
|
||||
public class Qema : AbstractBase
|
||||
{
|
||||
private readonly double _k1, _k2, _k3, _k4;
|
||||
private readonly Ema _ema1, _ema2, _ema3, _ema4;
|
||||
private double _lastQema, _p_lastQema;
|
||||
|
||||
public Qema(double k1 = 0.2, double k2 = 0.2, double k3 = 0.2, double k4 = 0.2)
|
||||
public Qema(double k1=0.2, double k2=0.2, double k3=0.2, double k4=0.2) : base()
|
||||
{
|
||||
if (k1 <= 0 || k2 <= 0 || k3 <= 0 || k4 <= 0)
|
||||
if (k1 <= 0 || k2 <= 0 || k3 <= 0 || k4 <= 0 )
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(k1), "All k values must be in the range (0, 1].");
|
||||
throw new ArgumentOutOfRangeException("All k values must be in the range (0, 1].");
|
||||
}
|
||||
|
||||
_k1 = k1;
|
||||
_k2 = k2;
|
||||
_k3 = k3;
|
||||
_k4 = k4;
|
||||
|
||||
_ema1 = new Ema(k1);
|
||||
_ema2 = new Ema(k2);
|
||||
_ema3 = new Ema(k3);
|
||||
_ema4 = new Ema(k4);
|
||||
|
||||
Name = $"QEMA ({k1:F2},{k2:F2},{k3:F2},{k4:F2})";
|
||||
double smK = Math.Min(Math.Min(k1, k2), Math.Min(k3, k4));
|
||||
double smK = Math.Min(Math.Min(_k1, _k2), Math.Min(_k3, _k4));
|
||||
|
||||
WarmupPeriod = (int)((2 - smK) / smK);
|
||||
WarmupPeriod = (int) ((2 - smK) / smK);
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,16 +12,12 @@ public class Rema : AbstractBase
|
||||
public int Period => _period;
|
||||
public double Lambda => _lambda;
|
||||
|
||||
public Rema(int period, double lambda = 0.5)
|
||||
public Rema(int period, double lambda = 0.5) : base()
|
||||
{
|
||||
if (period < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(period), "Period must be greater than or equal to 1.");
|
||||
}
|
||||
if (lambda < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(lambda), "Lambda must be non-negative.");
|
||||
}
|
||||
|
||||
_period = period;
|
||||
_lambda = lambda;
|
||||
|
||||
+2
-3
@@ -5,12 +5,11 @@ namespace QuanTAlib {
|
||||
|
||||
public class Rma : AbstractBase {
|
||||
private readonly int _period;
|
||||
private readonly double _alpha;
|
||||
private double _alpha;
|
||||
private double _lastRMA;
|
||||
private double _savedLastRMA;
|
||||
|
||||
public Rma(int period)
|
||||
{
|
||||
public Rma(int period) : base() {
|
||||
if (period < 1) {
|
||||
throw new ArgumentException("Period must be greater than or equal to 1.", nameof(period));
|
||||
}
|
||||
|
||||
+3
-3
@@ -4,10 +4,10 @@ public class Sma : AbstractBase
|
||||
{
|
||||
// inherited _index
|
||||
// inherited _value
|
||||
private readonly int Period;
|
||||
private readonly CircularBuffer _buffer;
|
||||
public readonly int Period;
|
||||
private CircularBuffer _buffer;
|
||||
|
||||
public Sma(int period)
|
||||
public Sma(int period) : base()
|
||||
{
|
||||
if (period < 1)
|
||||
{
|
||||
|
||||
@@ -5,10 +5,10 @@ namespace QuanTAlib;
|
||||
public class Smma : AbstractBase
|
||||
{
|
||||
private readonly int _period;
|
||||
private readonly CircularBuffer? _buffer;
|
||||
private CircularBuffer? _buffer;
|
||||
private double _lastSmma, _p_lastSmma;
|
||||
|
||||
public Smma(int period)
|
||||
public Smma(int period) : base()
|
||||
{
|
||||
if (period < 1)
|
||||
{
|
||||
@@ -17,7 +17,6 @@ public class Smma : AbstractBase
|
||||
_period = period;
|
||||
WarmupPeriod = period;
|
||||
Name = $"Smma({_period})";
|
||||
_buffer = new CircularBuffer(_period);
|
||||
Init();
|
||||
}
|
||||
|
||||
@@ -30,6 +29,7 @@ public class Smma : AbstractBase
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
_buffer = new CircularBuffer(_period);
|
||||
_lastSmma = 0;
|
||||
}
|
||||
|
||||
|
||||
+10
-7
@@ -3,27 +3,30 @@ namespace QuanTAlib;
|
||||
public class T3 : AbstractBase
|
||||
{
|
||||
private readonly int _period;
|
||||
private readonly double _vfactor;
|
||||
private readonly bool _useSma;
|
||||
private readonly double _k, _c1, _c2, _c3, _c4;
|
||||
private readonly double _k, _k1m, _c1, _c2, _c3, _c4;
|
||||
private readonly CircularBuffer _buffer1, _buffer2, _buffer3, _buffer4, _buffer5, _buffer6;
|
||||
private double _lastEma1, _lastEma2, _lastEma3, _lastEma4, _lastEma5, _lastEma6;
|
||||
private double _p_lastEma1, _p_lastEma2, _p_lastEma3, _p_lastEma4, _p_lastEma5, _p_lastEma6;
|
||||
|
||||
public T3(int period, double vfactor = 0.7, bool useSma = true)
|
||||
public T3(int period, double vfactor = 0.7, bool useSma = true) : base()
|
||||
{
|
||||
if (period < 1)
|
||||
{
|
||||
throw new ArgumentException("Period must be greater than or equal to 1.", nameof(period));
|
||||
}
|
||||
_period = period;
|
||||
_vfactor = vfactor;
|
||||
_useSma = useSma;
|
||||
WarmupPeriod = period;
|
||||
|
||||
_k = 2.0 / (_period + 1);
|
||||
_c1 = -vfactor * vfactor * vfactor;
|
||||
_c2 = 3 * vfactor * vfactor + 3 * vfactor * vfactor * vfactor;
|
||||
_c3 = -6 * vfactor * vfactor - 3 * vfactor - 3 * vfactor * vfactor * vfactor;
|
||||
_c4 = 1 + 3 * vfactor + vfactor * vfactor * vfactor + 3 * vfactor * vfactor;
|
||||
_k1m = 1.0 - _k;
|
||||
_c1 = -_vfactor * _vfactor * _vfactor;
|
||||
_c2 = 3 * _vfactor * _vfactor + 3 * _vfactor * _vfactor * _vfactor;
|
||||
_c3 = -6 * _vfactor * _vfactor - 3 * _vfactor - 3 * _vfactor * _vfactor * _vfactor;
|
||||
_c4 = 1 + 3 * _vfactor + _vfactor * _vfactor * _vfactor + 3 * _vfactor * _vfactor;
|
||||
|
||||
_buffer1 = new(period);
|
||||
_buffer2 = new(period);
|
||||
@@ -33,7 +36,7 @@ public class T3 : AbstractBase
|
||||
_buffer6 = new(period);
|
||||
|
||||
|
||||
Name = $"T3({_period}, {vfactor})";
|
||||
Name = $"T3({_period}, {_vfactor})";
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ public class Tema : AbstractBase
|
||||
private double _lastEma3, _p_lastEma3;
|
||||
private double _k, _e, _p_e;
|
||||
|
||||
public Tema(int period)
|
||||
public Tema(int period) : base()
|
||||
{
|
||||
if (period < 1)
|
||||
{
|
||||
@@ -58,7 +58,7 @@ public class Tema : AbstractBase
|
||||
{
|
||||
double result, _ema1, _ema2, _ema3;
|
||||
ManageState(Input.IsNew);
|
||||
|
||||
|
||||
_e = (_e > 1e-10) ? (1 - _k) * _e : 0;
|
||||
double _invE = (_e > 1e-10) ? 1 / (1 - _e) : 1;
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ public class Vidya : AbstractBase
|
||||
private readonly int _longPeriod;
|
||||
private readonly double _alpha;
|
||||
private double _lastVIDYA, _p_lastVIDYA;
|
||||
private readonly CircularBuffer? _shortBuffer;
|
||||
private readonly CircularBuffer? _longBuffer;
|
||||
private CircularBuffer? _shortBuffer;
|
||||
private CircularBuffer? _longBuffer;
|
||||
|
||||
public Vidya(int shortPeriod, int longPeriod = 0, double alpha = 0.2)
|
||||
public Vidya(int shortPeriod, int longPeriod = 0, double alpha = 0.2) : base()
|
||||
{
|
||||
if (shortPeriod < 1)
|
||||
{
|
||||
@@ -24,8 +24,6 @@ public class Vidya : AbstractBase
|
||||
_alpha = alpha;
|
||||
WarmupPeriod = _longPeriod;
|
||||
Name = $"Vidya({_shortPeriod},{_longPeriod})";
|
||||
_shortBuffer = new CircularBuffer(_shortPeriod);
|
||||
_longBuffer = new CircularBuffer(_longPeriod);
|
||||
Init();
|
||||
}
|
||||
|
||||
@@ -40,6 +38,8 @@ public class Vidya : AbstractBase
|
||||
{
|
||||
base.Init();
|
||||
_lastVIDYA = 0;
|
||||
_shortBuffer = new CircularBuffer(_shortPeriod);
|
||||
_longBuffer = new CircularBuffer(_longPeriod);
|
||||
}
|
||||
|
||||
protected override void ManageState(bool isNew)
|
||||
@@ -59,7 +59,7 @@ public class Vidya : AbstractBase
|
||||
protected override double Calculation()
|
||||
{
|
||||
ManageState(Input.IsNew);
|
||||
|
||||
|
||||
_shortBuffer!.Add(Input.Value, Input.IsNew);
|
||||
_longBuffer!.Add(Input.Value, Input.IsNew);
|
||||
|
||||
@@ -83,7 +83,7 @@ public class Vidya : AbstractBase
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static double CalculateStdDev(CircularBuffer buffer)
|
||||
private double CalculateStdDev(CircularBuffer buffer)
|
||||
{
|
||||
double mean = buffer.Average();
|
||||
double sumSquaredDiff = buffer.Sum(x => Math.Pow(x - mean, 2));
|
||||
|
||||
+4
-4
@@ -1,9 +1,8 @@
|
||||
namespace QuanTAlib;
|
||||
|
||||
//TODO fix WMA - passing Talib test
|
||||
|
||||
public class Wma : AbstractBase
|
||||
{
|
||||
private readonly int _period;
|
||||
private readonly Convolution _convolution;
|
||||
|
||||
public Wma(int period)
|
||||
@@ -12,9 +11,10 @@ public class Wma : AbstractBase
|
||||
{
|
||||
throw new ArgumentException("Period must be greater than or equal to 1.", nameof(period));
|
||||
}
|
||||
_convolution = new Convolution(GenerateWmaKernel(period));
|
||||
_period = period;
|
||||
_convolution = new Convolution(GenerateWmaKernel(_period));
|
||||
Name = "Wma";
|
||||
WarmupPeriod = period;
|
||||
WarmupPeriod = _period;
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,12 @@ namespace QuanTAlib;
|
||||
public class Zlema : AbstractBase
|
||||
{
|
||||
private readonly int _period;
|
||||
private readonly CircularBuffer? _buffer;
|
||||
private readonly double _alpha;
|
||||
private CircularBuffer? _buffer;
|
||||
private double _alpha;
|
||||
private int _lag;
|
||||
private double _lastZLEMA, _p_lastZLEMA;
|
||||
|
||||
public Zlema(int period)
|
||||
public Zlema(int period) : base()
|
||||
{
|
||||
if (period < 1)
|
||||
{
|
||||
@@ -19,8 +20,8 @@ public class Zlema : AbstractBase
|
||||
_period = period;
|
||||
WarmupPeriod = period;
|
||||
_alpha = 2.0 / (_period + 1);
|
||||
_lag = (_period - 1) / 2;
|
||||
Name = $"Zlema({_period})";
|
||||
_buffer = new CircularBuffer(_period);
|
||||
Init();
|
||||
}
|
||||
|
||||
@@ -33,6 +34,7 @@ public class Zlema : AbstractBase
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
_buffer = new CircularBuffer(_period);
|
||||
_lastZLEMA = 0;
|
||||
}
|
||||
|
||||
@@ -53,7 +55,7 @@ public class Zlema : AbstractBase
|
||||
protected override double Calculation()
|
||||
{
|
||||
ManageState(Input.IsNew);
|
||||
|
||||
|
||||
_buffer!.Add(Input.Value, Input.IsNew);
|
||||
|
||||
int lag = Math.Max(Math.Min((int)((_period - 1) * 0.5), _buffer.Count - 1), 0) + 1;
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace QuanTAlib;
|
||||
public class CircularBuffer : IEnumerable<double>
|
||||
{
|
||||
private readonly double[] _buffer;
|
||||
private int _start;
|
||||
private int _size;
|
||||
private int _start = 0;
|
||||
private int _size = 0;
|
||||
|
||||
public int Capacity { get; }
|
||||
public int Count => _size;
|
||||
@@ -69,9 +69,7 @@ public class CircularBuffer : IEnumerable<double>
|
||||
public double Newest()
|
||||
{
|
||||
if (_size == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return _buffer[(_start + _size - 1) % Capacity];
|
||||
}
|
||||
|
||||
@@ -79,9 +77,7 @@ public class CircularBuffer : IEnumerable<double>
|
||||
public double Oldest()
|
||||
{
|
||||
if (_size == 0)
|
||||
{
|
||||
ThrowInvalidOperationException();
|
||||
}
|
||||
return _buffer[_start];
|
||||
}
|
||||
|
||||
@@ -113,9 +109,7 @@ public class CircularBuffer : IEnumerable<double>
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (_index + 1 >= _buffer._size)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_index++;
|
||||
_current = _buffer[_index];
|
||||
@@ -131,9 +125,7 @@ public class CircularBuffer : IEnumerable<double>
|
||||
_current = default;
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
// not implemented
|
||||
}
|
||||
public void Dispose() { }
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
+5
-5
@@ -54,11 +54,11 @@ public class TBarSeries : List<TBar>
|
||||
{
|
||||
private readonly TBar Default = new(DateTime.MinValue, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN);
|
||||
|
||||
public TSeries Open { get; set; }
|
||||
public TSeries High { get; set; }
|
||||
public TSeries Low { get; set; }
|
||||
public TSeries Close { get; set; }
|
||||
public TSeries Volume { get; set; }
|
||||
public TSeries Open;
|
||||
public TSeries High;
|
||||
public TSeries Low;
|
||||
public TSeries Close;
|
||||
public TSeries Volume;
|
||||
|
||||
|
||||
public TBar Last => Count > 0 ? this[^1] : Default;
|
||||
|
||||
@@ -52,6 +52,12 @@ public class TSeries : List<TValue>
|
||||
var pubEvent = source.GetType().GetEvent("Pub");
|
||||
if (pubEvent != null)
|
||||
{
|
||||
/*
|
||||
var nameProperty = source.GetType().GetProperty("Name");
|
||||
if (nameProperty != null) {
|
||||
Name = nameProperty.GetValue(nameProperty)?.ToString()!;
|
||||
}
|
||||
*/
|
||||
pubEvent.AddEventHandler(source, new ValueSignal(Sub));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using System.CommandLine.Rendering.Views;
|
||||
|
||||
namespace QuanTAlib;
|
||||
|
||||
public class GbmFeed : TBarSeries
|
||||
@@ -6,7 +8,7 @@ public class GbmFeed : TBarSeries
|
||||
private readonly Random _random;
|
||||
private double _lastClose, _lastHigh, _lastLow;
|
||||
|
||||
public GbmFeed(double initialPrice = 100.0, double mu = 0.05, double sigma = 0.2)
|
||||
public GbmFeed(double initialPrice = 100.0, double mu = 0.05, double sigma = 0.2) : base()
|
||||
{
|
||||
_lastClose = _lastHigh = _lastLow = initialPrice;
|
||||
_mu = mu;
|
||||
@@ -20,6 +22,7 @@ public class GbmFeed : TBarSeries
|
||||
public void Add(int count)
|
||||
{
|
||||
DateTime startTime = DateTime.UtcNow - TimeSpan.FromHours(count);
|
||||
TBar lastBar = new();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
Add(startTime, true);
|
||||
|
||||
+43
-24
@@ -1,38 +1,57 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Title>QuanTAlib</Title>
|
||||
<Product>Library of TA Calculations, Charts and Strategies for Quantower</Product>
|
||||
<Description>Quantitative Technical Analysis Library in C# for Quantower</Description>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<RepositoryUrl>https://github.com/mihakralj/QuanTAlib</RepositoryUrl>
|
||||
<Authors>Miha Kralj</Authors>
|
||||
<Copyright>Miha Kralj</Copyright>
|
||||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||
<PackageReadmeFile>readme.md</PackageReadmeFile>
|
||||
<RootNamespace>QuanTAlib</RootNamespace>
|
||||
<AssemblyName>QuanTAlib</AssemblyName>
|
||||
<IsPublishable>True</IsPublishable>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<PackageTags>Indicators;Stock;Market;Technical;Analysis;Algorithmic;Trading;Trade;Trend;Momentum;Finance;Algorithm;Algo;AlgoTrading;Financial;Strategy;Chart;Charting;Oscillator;Overlay;Equity;Bitcoin;Crypto;Cryptocurrency;Forex;Quantitative;Historical;Quotes;</PackageTags>
|
||||
<NoWarn>$(NoWarn);NU5104</NoWarn>
|
||||
<PackageIcon>QuanTAlib2.png</PackageIcon>
|
||||
<PackageIconUrl>https://raw.githubusercontent.com/mihakralj/QuanTAlib/main/.github/QuanTAlib2.png</PackageIconUrl>
|
||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Title>QuanTAlib</Title>
|
||||
<Product>Library of TA Calculations, Charts and Strategies for Quantower</Product>
|
||||
<Description>Quantitative Technical Analysis Library in C# for Quantower</Description>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<RepositoryUrl>https://github.com/mihakralj/QuanTAlib</RepositoryUrl>
|
||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||
<Authors>Miha Kralj</Authors>
|
||||
<Copyright>Miha Kralj</Copyright>
|
||||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||
<PackageReadmeFile>readme.md</PackageReadmeFile>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<DisableImplicitNamespaceImports>false</DisableImplicitNamespaceImports>
|
||||
<NeutralLanguage>en-US</NeutralLanguage>
|
||||
<RootNamespace>QuanTAlib</RootNamespace>
|
||||
<AssemblyName>QuanTAlib</AssemblyName>
|
||||
<IsPublishable>True</IsPublishable>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
|
||||
<DebugType>full</DebugType>
|
||||
<ProduceReferenceAssembly>True</ProduceReferenceAssembly>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<PackageTags>
|
||||
Indicators;Stock;Market;Technical;Analysis;Algorithmic;Trading;Trade;Trend;Momentum;Finance;Algorithm;Algo;
|
||||
AlgoTrading;Financial;Strategy;Chart;Charting;Oscillator;Overlay;Equity;Bitcoin;Crypto;Cryptocurrency;Forex;
|
||||
Quantitative;Historical;Quotes;
|
||||
</PackageTags>
|
||||
<NoWarn>$(NoWarn);NU5104</NoWarn>
|
||||
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
|
||||
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
|
||||
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageIcon>QuanTAlib2.png</PackageIcon>
|
||||
<PackageIconUrl>https://raw.githubusercontent.com/mihakralj/QuanTAlib/main/.github/QuanTAlib2.png</PackageIconUrl>
|
||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Include="readme.md" Pack="true" PackagePath=""/>
|
||||
<None Include="..\.github\QuanTAlib2.png" Pack="true" Visible="false" PackagePath=""/>
|
||||
<PackageReference Include="Microsoft.DotNet.Interactive.Formatting" Version="1.0.0-beta.24229.4" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.0-rc.1.24431.7" />
|
||||
<PackageReference Include="Microsoft.DotNet.Interactive.Formatting" Version="1.0.0-beta.21459.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="TradingPlatform.BusinessLayer">
|
||||
<HintPath>..\.github\TradingPlatform.BusinessLayer.dll</HintPath>
|
||||
<HintPath>..\.github\TradingPlatform.BusinessLayer.dll</HintPath>
|
||||
</Reference>
|
||||
<None Include="..\.github\TradingPlatform.BusinessLayer.xml">
|
||||
<Link>TradingPlatform.BusinessLayer.xml</Link>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -7,9 +7,9 @@ using System.Linq;
|
||||
public class Entropy : AbstractBase
|
||||
{
|
||||
public readonly int Period;
|
||||
private readonly CircularBuffer _buffer;
|
||||
private CircularBuffer _buffer;
|
||||
|
||||
public Entropy(int period)
|
||||
public Entropy(int period) : base()
|
||||
{
|
||||
if (period < 2)
|
||||
{
|
||||
|
||||
@@ -4,9 +4,9 @@ namespace QuanTAlib;
|
||||
public class Kurtosis : AbstractBase
|
||||
{
|
||||
public readonly int Period;
|
||||
private readonly CircularBuffer _buffer;
|
||||
private CircularBuffer _buffer;
|
||||
|
||||
public Kurtosis(int period)
|
||||
public Kurtosis(int period) : base()
|
||||
{
|
||||
if (period < 4)
|
||||
{
|
||||
|
||||
@@ -5,12 +5,12 @@ namespace QuanTAlib
|
||||
public class Max : AbstractBase
|
||||
{
|
||||
public readonly int Period;
|
||||
private readonly CircularBuffer _buffer;
|
||||
private CircularBuffer _buffer;
|
||||
private readonly double _halfLife;
|
||||
private double _currentMax, _p_currentMax;
|
||||
private int _timeSinceNewMax, _p_timeSinceNewMax;
|
||||
|
||||
public Max(int period, double decay = 0)
|
||||
public Max(int period, double decay = 0) : base()
|
||||
{
|
||||
if (period < 1)
|
||||
{
|
||||
|
||||
@@ -6,9 +6,9 @@ namespace QuanTAlib
|
||||
public class Median : AbstractBase
|
||||
{
|
||||
public readonly int Period;
|
||||
private readonly CircularBuffer _buffer;
|
||||
private CircularBuffer _buffer;
|
||||
|
||||
public Median(int period)
|
||||
public Median(int period) : base()
|
||||
{
|
||||
if (period < 1)
|
||||
{
|
||||
|
||||
@@ -5,12 +5,12 @@ namespace QuanTAlib
|
||||
public class Min : AbstractBase
|
||||
{
|
||||
public readonly int Period;
|
||||
private readonly CircularBuffer _buffer;
|
||||
private CircularBuffer _buffer;
|
||||
private readonly double _halfLife;
|
||||
private double _currentMin, _p_currentMin;
|
||||
private int _timeSinceNewMin, _p_timeSinceNewMin;
|
||||
|
||||
public Min(int period, double decay = 0)
|
||||
public Min(int period, double decay = 0) : base()
|
||||
{
|
||||
if (period < 1)
|
||||
{
|
||||
|
||||
@@ -3,9 +3,9 @@ namespace QuanTAlib;
|
||||
public class Mode : AbstractBase
|
||||
{
|
||||
public readonly int Period;
|
||||
private readonly CircularBuffer _buffer;
|
||||
private CircularBuffer _buffer;
|
||||
|
||||
public Mode(int period)
|
||||
public Mode(int period) : base()
|
||||
{
|
||||
if (period < 1)
|
||||
{
|
||||
|
||||
@@ -7,9 +7,9 @@ public class Percentile : AbstractBase
|
||||
{
|
||||
public readonly int Period;
|
||||
public readonly double Percent;
|
||||
private readonly CircularBuffer _buffer;
|
||||
private CircularBuffer _buffer;
|
||||
|
||||
public Percentile(int period, double percent)
|
||||
public Percentile(int period, double percent) : base()
|
||||
{
|
||||
if (period < 2)
|
||||
{
|
||||
|
||||
@@ -6,9 +6,9 @@ using System.Linq;
|
||||
public class Skew : AbstractBase
|
||||
{
|
||||
public readonly int Period;
|
||||
private readonly CircularBuffer _buffer;
|
||||
private CircularBuffer _buffer;
|
||||
|
||||
public Skew(int period)
|
||||
public Skew(int period) : base()
|
||||
{
|
||||
if (period < 3)
|
||||
{
|
||||
|
||||
@@ -7,9 +7,9 @@ namespace QuanTAlib
|
||||
{
|
||||
public readonly int Period;
|
||||
public readonly bool IsPopulation;
|
||||
private readonly CircularBuffer _buffer;
|
||||
private CircularBuffer _buffer;
|
||||
|
||||
public Stddev(int period, bool isPopulation = false)
|
||||
public Stddev(int period, bool isPopulation = false) : base()
|
||||
{
|
||||
if (period < 2)
|
||||
{
|
||||
|
||||
@@ -7,9 +7,9 @@ namespace QuanTAlib
|
||||
{
|
||||
public readonly int Period;
|
||||
public readonly bool IsPopulation;
|
||||
private readonly CircularBuffer _buffer;
|
||||
private CircularBuffer _buffer;
|
||||
|
||||
public Variance(int period, bool isPopulation = false)
|
||||
public Variance(int period, bool isPopulation = false) : base()
|
||||
{
|
||||
if (period < 2)
|
||||
{
|
||||
|
||||
@@ -6,9 +6,9 @@ using System.Linq;
|
||||
public class Zscore : AbstractBase
|
||||
{
|
||||
public readonly int Period;
|
||||
private readonly CircularBuffer _buffer;
|
||||
private CircularBuffer _buffer;
|
||||
|
||||
public Zscore(int period)
|
||||
public Zscore(int period) : base()
|
||||
{
|
||||
if (period < 2)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user