diff --git a/.gitignore b/.gitignore index 2c6aac33..6327d78f 100644 --- a/.gitignore +++ b/.gitignore @@ -354,3 +354,4 @@ MigrationBackup/ # Ionide (cross platform F# VS Code tools) working folder .ionide/ dotCover.Output.dcvr +/Tests/GlobalSuppressions.cs diff --git a/Quantower/Quantower.csproj b/Quantower/Quantower.csproj index 9cc46c29..0a13f65e 100644 --- a/Quantower/Quantower.csproj +++ b/Quantower/Quantower.csproj @@ -34,9 +34,11 @@ QuanTAlib\%(RecursiveDir)%(Filename)%(Extension) + diff --git a/Source/Basics/Single_TSeries_Abstract.cs b/Source/Basics/Single_TSeries_Abstract.cs index 289cc5b9..1e96b5ca 100644 --- a/Source/Basics/Single_TSeries_Abstract.cs +++ b/Source/Basics/Single_TSeries_Abstract.cs @@ -1,6 +1,7 @@ namespace QuanTAlib; using System; using System.Collections.Generic; +using System.Linq; /* Abstract classes with all scaffolding required to build indicators. @@ -17,47 +18,54 @@ Abstract classes with all scaffolding required to build indicators. */ public abstract class Single_TSeries_Indicator : TSeries { - protected readonly int _p; - protected readonly bool _NaN; - protected readonly TSeries _data; + protected readonly int _period; + protected readonly bool _NaN; + protected readonly TSeries _data; + protected int _p; - // Chainable Constructor - add it at the end of primary constructor :base(source: source, period: period, useNaN: useNaN) - protected Single_TSeries_Indicator(TSeries source, int period, bool useNaN) + // Chainable Constructor - add it at the end of primary constructor :base(source: source, period: period, useNaN: useNaN) + protected Single_TSeries_Indicator(TSeries source, int period, bool useNaN) + { + this._data = source; + this._period = period; + this._p = _period; + this._NaN = useNaN; + this._data.Pub += this.Sub; + } + + // overridable Add() method to add/update a single item at the end of the list + + public virtual void Add((System.DateTime t, double v) TValue, bool update, bool useNaN) + { + if (_period == 0) { _p = this.Length; } + var res = (TValue.t, this.Count < this._p - 1 && this._NaN ? double.NaN : TValue.v); + base.Add(res, update); + } + public new virtual void Add((System.DateTime t, double v) TValue, bool update) => base.Add(TValue, update); + + // potentially overridable Add() method for the whole series (could be replaced with faster bulk algo) + public virtual void Add(TSeries data) { for (int i = 0; i < data.Count; i++) { this.Add(TValue: data[i], update: false); } } + + public new void Add((System.DateTime t, double v) TValue) => this.Add(TValue: TValue, update: false); + public void Add(bool update) => this.Add(TValue: this._data[this._data.Count - 1], update: update); + public void Add() => this.Add(TValue: this._data[this._data.Count - 1], update: false); + public new void Sub(object source, TSeriesEventArgs e) => this.Add(TValue: this._data[this._data.Count - 1], update: e.update); + + protected static void Add_Replace(List l, double v, bool update) + { + if (update) + { l[l.Count - 1] = v; } + else + { l.Add(v); } + } + protected static double Add_Replace_Trim(List l, double v, int p, bool update) + { + Add_Replace(l, v, update); + double ret = (l.Count > 0) ? l.First() : 0; + if (l.Count > p && p != 0) { - this._data = source; - this._p = period; - this._NaN = useNaN; - this._data.Pub += this.Sub; - } - - // overridable Add() method to add/update a single item at the end of the list - - public virtual void Add((System.DateTime t, double v) TValue, bool update, bool useNaN) - { - var res = (TValue.t, this.Count < this._p - 1 && this._NaN ? double.NaN : TValue.v); - base.Add(res, update); - } - public new virtual void Add((System.DateTime t, double v) TValue, bool update) => base.Add(TValue, update); - - // potentially overridable Add() method for the whole series (could be replaced with faster bulk algo) - public virtual void Add(TSeries data) { for (int i = 0; i < data.Count; i++) { this.Add(TValue: data[i], update: false); }} - - public new void Add((System.DateTime t, double v) TValue) => this.Add(TValue: TValue, update: false); - public void Add(bool update) => this.Add(TValue: this._data[this._data.Count - 1], update: update); - public void Add() => this.Add(TValue: this._data[this._data.Count - 1], update: false); - public new void Sub(object source, TSeriesEventArgs e) => this.Add(TValue: this._data[this._data.Count - 1], update: e.update); - - protected static void Add_Replace(List l, double v, bool update) - { - if (update) - { l[l.Count - 1] = v; } - else - { l.Add(v); } - } - protected static void Add_Replace_Trim(List l, double v, int p, bool update) - { - Add_Replace(l, v, update); - if (l.Count > p && p!=0) - { l.RemoveAt(0); } + l.RemoveAt(0); } + return ret; + } } diff --git a/Source/Feeds/GBM_Feed.cs b/Source/Feeds/GBM_Feed.cs index 0adcde1d..e83e6b46 100644 --- a/Source/Feeds/GBM_Feed.cs +++ b/Source/Feeds/GBM_Feed.cs @@ -22,10 +22,12 @@ public class GBM_Feed : TBars { private double seed; readonly double drift, volatility; - public GBM_Feed(int Bars = 252, double Volatility = 1.0, double Drift = 0.05, double Seed = 100.0) { + readonly int precision; + public GBM_Feed(int Bars = 252, double Volatility = 1.0, double Drift = 0.05, double Seed = 100.0, int Precision = 2) { this.seed = Seed; volatility = Volatility*0.01; drift = Drift*0.01; + precision = Precision; for (int i = 0; i OCMin)? (2 * OCMin) - Low : Low; - double Volume = GBM_value(seed*10, volatility*2, Drift:0); + double Volume = GBM_value(seed*10, volatility*2, Drift:0, precision: 1); base.Add((timestamp, Open, High, Low, Close, Volume), update); seed = Close; } - private static double GBM_value (double Seed, double Volatility, double Drift) { + private static double GBM_value(double Seed, double Volatility, double Drift, int precision) { Random rnd = new(); double U1 = 1.0-rnd.NextDouble(); double U2 = 1.0-rnd.NextDouble(); double Z = Math.Sqrt(-2.0 * Math.Log(U1)) * Math.Sin(2.0 * Math.PI * U2); - return Seed * Math.Exp( Drift - (Volatility*Volatility*0.5) + (Volatility * Z)); + return Math.Round(Seed * Math.Exp( Drift - (Volatility*Volatility*0.5) + (Volatility * Z)), digits: precision); } } \ No newline at end of file diff --git a/Source/QuanTAlib.csproj b/Source/QuanTAlib.csproj index be71640e..29aa29ae 100644 --- a/Source/QuanTAlib.csproj +++ b/Source/QuanTAlib.csproj @@ -2,7 +2,7 @@ QuanTAlib - 0.1.22 + 0.1.23 Library of Technical Indicators for .NET Quantitative Technical Analysis library for both real-time (streaming) and historical data analysis git @@ -66,7 +66,6 @@ False - \ No newline at end of file diff --git a/Source/Trends/DEMA_Series.cs b/Source/Trends/DEMA_Series.cs index 8a7d8e92..cb165726 100644 --- a/Source/Trends/DEMA_Series.cs +++ b/Source/Trends/DEMA_Series.cs @@ -1,6 +1,7 @@ namespace QuanTAlib; using System; using System.Linq; +using System.Runtime.CompilerServices; /* DEMA: Double Exponential Moving Average @@ -18,15 +19,15 @@ Remark: public class DEMA_Series : Single_TSeries_Indicator { - private readonly System.Collections.Generic.List _buffer = new(); - private readonly double _k, _k1m; + private readonly System.Collections.Generic.List _buffer1 = new(); + private readonly System.Collections.Generic.List _buffer2 = new(); + private readonly double _k; private double _lastema1, _lastlastema1; private double _lastema2, _lastlastema2; public DEMA_Series(TSeries source, int period, bool useNaN = false) : base(source, period, useNaN) { - this._k = 2.0 / (this._p + 1); - this._k1m = 1.0 - this._k; + _k = 2.0 / (_p + 1); if (_data.Count > 0) { base.Add(_data); } } @@ -34,26 +35,40 @@ public class DEMA_Series : Single_TSeries_Indicator { if (update) { - this._lastema1 = this._lastlastema1; - this._lastema2 = this._lastlastema2; + _lastema1 = _lastlastema1; + _lastema2 = _lastlastema2; } - double _ema1, _ema2; - - if (this.Count < this._p) + double _ema1, _ema2, _dema; + if (this.Count < _p) { - Add_Replace_Trim(_buffer, TValue.v, _p, update); - double _sma = _buffer.Average(); + Add_Replace_Trim(_buffer1, TValue.v, _p, update); + _ema1 = 0; + for (int i=0; i<_buffer1.Count; i++) { _ema1 += _buffer1[i]; } + _ema1 /= _buffer1.Count; - _ema1 = _ema2 = _sma; + Add_Replace_Trim(_buffer2, _ema1, _p, update); + _ema2 = 0; + for (int i = 0; i < _buffer2.Count; i++) { _ema2 += _buffer2[i]; } + _ema2 /= _buffer2.Count; } - else + else if(this.Count < (2*_p - 1)) // second _p { - _ema1 = (TValue.v * this._k) + (this._lastema1 * this._k1m); - _ema2 = (_ema1 * this._k) + (this._lastema2 * this._k1m); - } + _ema1 = (TValue.v - _lastema1) * _k + _lastema1; + + Add_Replace_Trim(_buffer2, _ema1, _p, update); + _ema2 = 0; + for (int i = 0; i < _buffer2.Count; i++) { _ema2 += _buffer2[i]; } + _ema2 /= _buffer2.Count; + } + else // all others + { + _ema1 = (TValue.v - _lastema1) * _k + _lastema1; + _ema2 = (_ema1 - _lastema2) * _k + _lastema2; + + } + _dema = 2*_ema1 - _ema2; - double _dema = (2 * _ema1) - _ema2; this._lastlastema1 = this._lastema1; this._lastlastema2 = this._lastema2; this._lastema1 = _ema1; @@ -61,4 +76,4 @@ public class DEMA_Series : Single_TSeries_Indicator base.Add((TValue.t, _dema), update, _NaN); } -} +} \ No newline at end of file diff --git a/Source/Trends/DWMA_Series.cs b/Source/Trends/DWMA_Series.cs new file mode 100644 index 00000000..0cff2aec --- /dev/null +++ b/Source/Trends/DWMA_Series.cs @@ -0,0 +1,39 @@ +namespace QuanTAlib; +using System; + +/* +DWMA: Double (linearly) Weighted Moving Average + The weights are linearly decreasing over the period and the most recent data has + the heaviest weight. + +Sources: + + + */ + +public class DWMA_Series : Single_TSeries_Indicator +{ + public DWMA_Series(TSeries source, int period, bool useNaN = false) : base(source, period, useNaN) + { + for (int i = 0; i < this._p; i++) { this._weights.Add(i + 1); } + if (base._data.Count > 0) { base.Add(base._data); } + } + private readonly System.Collections.Generic.List _buffer1 = new(); + private readonly System.Collections.Generic.List _buffer2 = new(); + private readonly System.Collections.Generic.List _weights = new(); + + public override void Add((System.DateTime t, double v) TValue, bool update) + { + Add_Replace_Trim(_buffer1, TValue.v, _p, update); + double _wma = 0; + for (int i = 0; i < _buffer1.Count; i++) { _wma += _buffer1[i] * this._weights[i]; } + _wma /= (this._buffer1.Count * (this._buffer1.Count + 1)) * 0.5; + + Add_Replace_Trim(_buffer2, TValue.v, _p, update); + double _dwma = 0; + for (int i = 0; i < _buffer2.Count; i++) { _dwma += _buffer2[i] * this._weights[i]; } + _dwma /= (this._buffer2.Count * (this._buffer2.Count + 1)) * 0.5; + + base.Add((TValue.t, _dwma), update, _NaN); + } +} \ No newline at end of file diff --git a/Source/Trends/EMA_Series.cs b/Source/Trends/EMA_Series.cs index aae20c2a..c3fdc19e 100644 --- a/Source/Trends/EMA_Series.cs +++ b/Source/Trends/EMA_Series.cs @@ -25,12 +25,14 @@ public class EMA_Series : Single_TSeries_Indicator private readonly System.Collections.Generic.List _buffer = new(); private readonly double _k, _k1m; private double _lastema, _lastlastema; + private bool _useSMA; - public EMA_Series(TSeries source, int period, bool useNaN = false) : base(source, period, useNaN) + public EMA_Series(TSeries source, int period, bool useNaN = false, bool useSMA = true) : base(source, period, useNaN) { this._k = 2.0 / (this._p + 1); this._k1m = 1.0 - this._k; - this._lastema = this._lastlastema = double.NaN; + this._lastema = this._lastlastema = 0; + _useSMA = useSMA; if (this._data.Count > 0) { base.Add(this._data); } } @@ -38,11 +40,14 @@ public class EMA_Series : Single_TSeries_Indicator { double _ema; if (update) { this._lastema = this._lastlastema; } + if (this.Count == 0) { _lastema = TValue.v; } - if (this.Count < this._p) + if (this.Count < this._p && _useSMA) { Add_Replace(_buffer, TValue.v, update); - _ema = _buffer.Average(); + _ema = 0; + for (int i = 0; i < _buffer.Count; i++) { _ema += _buffer[i]; } + _ema /= _buffer.Count; } else { diff --git a/Source/Trends/JMA_Series.cs b/Source/Trends/JMA_Series.cs index 54e588ee..94b17d56 100644 --- a/Source/Trends/JMA_Series.cs +++ b/Source/Trends/JMA_Series.cs @@ -1,5 +1,6 @@ namespace QuanTAlib; using System; +using System.Linq; /* JMA: Jurik Moving Average @@ -18,141 +19,81 @@ Issues: original algo is slightly different, yet this approximation is close enough. -TODO: buggy - rework */ +public class JMA_Series : Single_TSeries_Indicator { + private readonly System.Collections.Generic.List volty_10 = new(); + private readonly System.Collections.Generic.List vsum_buff = new(); + private readonly double pr, beta; -public class JMA_Series : Single_TSeries_Indicator -{ - private readonly System.Collections.Generic.List vbuffer10; - private readonly System.Collections.Generic.List vsum65; + private double upperBand, lowerBand, _phase, vsum, Kv, del1, del2, prev_del1, prev_del2; + private double prev_ma1, prev_det0, prev_det1, prev_vsum, prev_jma; + private double p_upperBand, p_lowerBand, p_Kv, p_prev_ma1, p_prev_det0, p_prev_det1, p_prev_vsum, p_prev_jma; - private double prev_ma1, prev_det0, prev_det1, prev_jma, bsmax, bsmin; - private double o_prev_ma1, o_prev_det0, o_prev_det1, o_prev_jma, o_bsmax, o_bsmin; + public JMA_Series(TSeries source, int period, double phase = 0.0, bool useNaN = false) : base(source, period, useNaN) { + upperBand = lowerBand = prev_ma1 = prev_det0 = prev_det1 = prev_vsum = prev_jma = Kv = del1 = del2 = 0.0; + Kv = 0; + pr = (phase * 0.01) + 1.5; + if (phase < -100) pr = 0.5; + if (phase > 100) pr = 2.5; + beta = 0.45 * (_p - 1) / (0.45 * (_p - 1) + 2); - private readonly double pr, pow1, len2, beta, rvolty; + if (base._data.Count > 0) { base.Add(base._data); } + } - public JMA_Series(TSeries source, int period, double phase = 0.0, bool useNaN = false) : base(source, period, useNaN) - { - this.vbuffer10 = new(); - this.vsum65 = new(); + public override void Add((System.DateTime t, double v) TValue, bool update) { + if (update) { + upperBand = p_upperBand; lowerBand = p_lowerBand; Kv = p_Kv; prev_vsum = p_prev_vsum; + prev_ma1 = p_prev_ma1; prev_det0 = p_prev_det0; prev_det1 = p_prev_det1; prev_jma = p_prev_jma; + } else { + p_upperBand = upperBand; p_lowerBand = lowerBand; p_Kv = Kv; p_prev_vsum = prev_vsum; + p_prev_ma1 = prev_ma1; p_prev_det0 = prev_det0; p_prev_det1 = prev_det1; p_prev_jma = prev_jma; + } - // constants - this.pr = (phase < -100) ? 0.5 : (phase > 100) ? 2.5 : (phase * 0.01) + 1.5; - double len1 = Math.Max((Math.Log(Math.Sqrt(0.5 * (_p - 1))) / Math.Log(2.0)) + 2.0, 0); - this.pow1 = Math.Max(len1 - 2, 0.5); - this.rvolty = Math.Exp((1 / this.pow1) * Math.Log(len1)); - this.len2 = Math.Sqrt(0.5 * (_p - 1)) * len1; - this.beta = 0.45 * (_p - 1) / (0.45 * (_p - 1) + 2); - if (base._data.Count > 0) { base.Add(base._data); } - } + // from Tvalue to volty + del1 = TValue.v - upperBand; + del2 = TValue.v - lowerBand; + upperBand = (del1 > 0) ? TValue.v : TValue.v - (Kv * del1); + lowerBand = (del2 < 0) ? TValue.v : TValue.v - (Kv * del2); + double volty = 0; + if (Math.Abs(del1) > Math.Abs(del2)) { volty = Math.Abs(del1); } + if (Math.Abs(del1) < Math.Abs(del2)) { volty = Math.Abs(del2); } - public override void Add((System.DateTime t, double v) TValue, bool update) - { - if (this.Count == 0) - { - this.prev_ma1 = this.prev_jma = TValue.v; - this.bsmax = this.bsmin = this.prev_det0 = this.prev_det1 = 0; - } + //// from volty to avolty + if (update) { volty_10[volty_10.Count - 1] = volty; } else { volty_10.Add(volty); } + if (volty_10.Count > 10) { volty_10.RemoveAt(0); } + vsum = prev_vsum + 0.1 * (volty - volty_10.First()); + if (update) { vsum_buff[vsum_buff.Count - 1] = vsum; } else { vsum_buff.Add(vsum); } + if (vsum_buff.Count > 65) vsum_buff.RemoveAt(0); + double avolty = 0; + for (int i = 0; i < vsum_buff.Count; i++) { avolty += vsum_buff[i]; } + avolty /= vsum_buff.Count; - if (update) - { - this.prev_jma = this.o_prev_jma; - this.prev_ma1 = this.o_prev_ma1; - this.prev_det0 = this.o_prev_det0; - this.prev_det1 = this.o_prev_det1; - this.bsmax = this.o_bsmax; - this.bsmin = this.o_bsmin; - } - else - { - this.o_prev_jma = this.prev_jma; - this.o_prev_ma1 = this.prev_ma1; - this.o_prev_det0 = this.prev_det0; - this.o_prev_det1 = this.prev_det1; - this.o_bsmax = this.bsmax; - this.o_bsmin = this.bsmin; - } + /// from avolty to rolty + double rvolty = (avolty > 0) ? volty / avolty : 0; + double len1 = (Math.Log(Math.Sqrt(_p)) / Math.Log(2.0)) + 2; + if (len1 < 0) len1 = 0; + double pow1 = Math.Max(len1 - 2.0, 0.5); + if (rvolty > Math.Pow(len1, 1.0 / pow1)) rvolty = Math.Pow(len1, 1.0 / pow1); + if (rvolty < 1) rvolty = 1; - double hprice = TValue.v; - double lprice = TValue.v; - for (int i = 0; i <= Math.Min(9, this._data.Count - 1); i++) - { - var _item = this._data[this._data.Count - 1 - i].v; - hprice = (_item > hprice) ? _item : hprice; - lprice = (_item < lprice) ? _item : lprice; - } - double del1 = hprice - this.bsmax; - double del2 = lprice - this.bsmin; + //// from rvolty to second smoothing + double pow2 = Math.Pow(rvolty, pow1); + double len2 = Math.Sqrt(0.5 * (_p - 1)) * len1; + Kv = Math.Pow(len2 / (len2 + 1), Math.Sqrt(pow2)); + double alpha = Math.Pow(beta, pow2); + double ma1 = (1 - alpha) * TValue.v + alpha * prev_ma1; + prev_ma1 = ma1; + double det0 = (1 - beta) * (TValue.v - ma1) + beta * prev_det0; + prev_det0 = det0; - double volty = (Math.Abs(del1) != Math.Abs(del2)) - ? Math.Max(Math.Abs(del1), Math.Abs(del2)) - : 0; - if (update) - { - this.vbuffer10[this.vbuffer10.Count - 1] = volty; - } - else - { - this.vbuffer10.Add(volty); - } - if (this.vbuffer10.Count > 10) - { - this.vbuffer10.RemoveAt(0); - } + /// from second smoothing to jma + double ma2 = ma1 + pr * det0; + double det1 = (1 - alpha) * (1 - alpha) * (ma2 - prev_jma) + alpha * alpha * prev_det1; + prev_det1 = det1; + double jma = prev_jma + det1; + prev_jma = jma; - double prevvsum = - (this.vsum65.Count > 0) ? this.vsum65[this.vsum65.Count - 1] : 0; - double vsumitem = prevvsum + 0.1 * (volty - this.vbuffer10[0]); - if (update) - { - this.vsum65[this.vsum65.Count - 1] = vsumitem; - } - else - { - this.vsum65.Add(vsumitem); - } - if (this.vsum65.Count > 65) - { - this.vsum65.RemoveAt(0); - } + base.Add((TValue.t, jma), update, _NaN); + } +} - double avolty = 0; - for (int i = 0; i < this.vsum65.Count; i++) - { - avolty += this.vsum65[i]; - } - - avolty /= this.vsum65.Count; - double dvolty = (avolty > 0) ? volty / avolty : 0; - dvolty = Math.Max((dvolty > this.rvolty) ? this.rvolty : dvolty, 1.0); - - double pow2 = Math.Exp(this.pow1 * Math.Log(dvolty)); - double kv = - Math.Exp(Math.Sqrt(pow2) * Math.Log(this.len2 / (this.len2 + 1))); - - this.bsmax = (del1 > 0) ? hprice : hprice - (kv * del1); - this.bsmin = (del2 < 0) ? lprice : lprice - (kv * del2); - - // adaptive EMA dynamic factor - double pow = Math.Pow(dvolty, this.pow1); - double alpha = Math.Pow(this.beta, pow); - - // 1st stage - preliminary smoothing by adaptive EMA - double ma1 = TValue.v * (1 - alpha) + this.prev_ma1 * alpha; - this.prev_ma1 = ma1; - - // 2nd stage - one more preliminary smoothing by Kalman filter - double det0 = (TValue.v - ma1) * (1 - this.beta) + this.prev_det0 * this.beta; - this.prev_det0 = det0; - double ma2 = ma1 + (this.pr * det0); - - // 3rd stage - final smoothing by Jurik adaptive filter - double det1 = ((ma2 - this.prev_jma) * (1 - alpha) * (1 - alpha)) + - (this.prev_det1 * alpha * alpha); - this.prev_det1 = det1; - var _jma = this.prev_jma + det1; - this.prev_jma = _jma; - - base.Add((TValue.t, _jma), update, _NaN); - } -} \ No newline at end of file diff --git a/Source/Trends/MAMA_Series.cs b/Source/Trends/MAMA_Series.cs index ae26f66c..ff85d784 100644 --- a/Source/Trends/MAMA_Series.cs +++ b/Source/Trends/MAMA_Series.cs @@ -21,12 +21,10 @@ public class MAMA_Series : Single_TSeries_Indicator { fastl = fastlimit; slowl = slowlimit; - i = 0; Fama = new(); if (base._data.Count > 0) { base.Add(base._data); } } - private int i; private double sumPr, jI, jQ, fastl, slowl; private (double i, double i1, double i2, double i3, double i4, double i5, double i6, double io) pr, i1, q1, sm, dt; private (double i, double i1, double io) i2, q2, re, im, pd, ph, mama, fama; @@ -51,7 +49,7 @@ public class MAMA_Series : Single_TSeries_Indicator mama.io = mama.i1; mama.i1 = mama.i; fama.io = fama.i1; fama.i1 = fama.i; } - + int i = base.Count; pr.i = TValue.v; if (i > 5) { double adj = (0.075 * pd.i1) + 0.54; @@ -113,7 +111,6 @@ public class MAMA_Series : Single_TSeries_Indicator mama.i = fama.i = sumPr / (i+1); } - if (!update) { i++; } base.Add((TValue.t, mama.i), update, _NaN); var result = (TValue.t, this.Count < this._p - 1 && this._NaN ? double.NaN : fama.i); Fama.Add(result, update); diff --git a/Source/Trends/SMA_Series.cs b/Source/Trends/SMA_Series.cs index 1f07a088..d7a635a1 100644 --- a/Source/Trends/SMA_Series.cs +++ b/Source/Trends/SMA_Series.cs @@ -1,6 +1,5 @@ namespace QuanTAlib; using System; -using System.Linq; /* SMA: Simple Moving Average @@ -19,17 +18,45 @@ Remark: public class SMA_Series : Single_TSeries_Indicator { - public SMA_Series(TSeries source, int period, bool useNaN = false) : base(source, period, useNaN) - { - if (base._data.Count > 0) { base.Add(base._data); } - } - private readonly System.Collections.Generic.List _buffer = new(); + private readonly System.Collections.Generic.List _buffer = new(); + private double _sma, _oldsma; + private double _topv, _oldtopv; + public SMA_Series(TSeries source, int period, bool useNaN = false) : base(source, period, useNaN) + { + if (base._data.Count > 0) + { base.Add(base._data); } + } + public override void Add((System.DateTime t, double v) TValue, bool update) + { + _topv = Add_Replace_Trim(_buffer, TValue.v, _p, update); - public override void Add((System.DateTime t, double v) TValue, bool update) - { - Add_Replace_Trim(_buffer, TValue.v, _p, update); - double _sma = _buffer.Sum() / _buffer.Count; + // rolling back if update, storing data for potential future update + if (update) + { + _sma = _oldsma; + _topv = _oldtopv; + } + else + { + _oldsma = _sma; + _oldtopv = _topv; + } - base.Add((TValue.t, _sma), update, _NaN); - } -} + // main additive calculation of SMA - for data points that are larger than _p period + // this.Count > _p + if (this.Count > _p) + { + _sma += (TValue.v - _topv) / _p; + } + else + { + // calculate SMA the traditional way (sum all, divide with _p) for data points within _p period + _sma = 0; + for (int i = 0; i < _buffer.Count; i++) + { _sma += _buffer[i]; } + _sma /= _buffer.Count; + } + + base.Add((TValue.t, _sma), update, _NaN); + } +} \ No newline at end of file diff --git a/Source/Trends/T3_Series.cs b/Source/Trends/T3_Series.cs index 46e4217a..7e548962 100644 --- a/Source/Trends/T3_Series.cs +++ b/Source/Trends/T3_Series.cs @@ -4,19 +4,30 @@ using System.Linq; using System.Numerics; /* -T3: Triple Exponential Moving Average - TEMA uses EMA(EMA(EMA())) to calculate less laggy Exponential moving average. +T3: Tillson T3 Moving Average + Tim Tillson described it in "Technical Analysis of Stocks and Commodities", January 1998 in the + article "Better Moving Averages". Tillson’s moving average becomes a popular indicator of + technical analysis as it gets less lag with the price chart and its curve is considerably smoother. Sources: - https://www.tradingtechnologies.com/help/x-study/technical-indicator-definitions/triple-exponential-moving-average-tema/ + https://technicalindicators.net/indicators-technical-analysis/150-t3-moving-average + http://www.binarytribune.com/forex-trading-indicators/t3-moving-average-indicator/ +Calculation: + a = 0.7 (but also 0.618); + Ema1 = Ema (Close); + Ema2 = Ema (Ema1); + Ema3 = Ema (Ema2); + Ema4 = Ema (Ema3); + Ema5 = Ema (Ema4); + Ema6 = Ema (Ema5); + T3 = –(a*a*a) * Ema6 + (3*a*a + 3*a*a*a) * Ema5 + (–6*a*a – 3*a – 3*a*a*a) * Ema4 + (1 + 3*a + a*a*a + 3*a*a) * Ema3 */ public class T3_Series : Single_TSeries_Indicator { - private int i; - private double k, a; + private double k, a; private double c1, c2, c3, c4; private double o_c1, o_c2, o_c3, o_c4; @@ -26,9 +37,8 @@ public class T3_Series : Single_TSeries_Indicator private double sum1, sum2, sum3, sum4, sum5, sum6; private double o_sum1, o_sum2, o_sum3, o_sum4, o_sum5, o_sum6; - public T3_Series(TSeries source, int period, double vfactor, bool useNaN = false) : base(source, period, useNaN) + public T3_Series(TSeries source, int period, double vfactor = 0.7, bool useNaN = false) : base(source, period, useNaN) { - i = 0; k = 2.0 / (_p + 1); a = vfactor; c1 = -a * a * a; @@ -55,6 +65,7 @@ public class T3_Series : Single_TSeries_Indicator o_sum1 = sum1; o_sum2 = sum2; o_sum3 = sum3; o_sum4 = sum4; o_sum5 = sum5; o_sum6 = sum6; } double v = TValue.v; + int i = base.Count; if (i > _p - 1) { e1 += k * (v - e1); if (i > 2 * (_p - 1)) { @@ -71,45 +82,44 @@ public class T3_Series : Single_TSeries_Indicator else { sum6 += e5; if (i == 6 * (_p - 1)) { - e6 = sum6 / _p; + e6 = sum6 / Math.Max(_p, base.Count); } } } else { sum5 += e4; if (i == 5 * (_p - 1)) { - sum6 = e5 = sum5 / _p; + sum6 = e5 = sum5 / Math.Max(_p, base.Count); } } } else { sum4 += e3; if (i == 4 * (_p - 1)) { - sum5 = e4 = sum4 / _p; + sum5 = e4 = sum4 / Math.Max(_p, base.Count); } } } else { sum3 += e2; if (i == 3 * (_p - 1)) { - sum4 = e3 = sum3 / _p; + sum4 = e3 = sum3 / Math.Max(_p, base.Count); } } } else { sum2 += e1; if (i == 2 * (_p - 1)) { - sum3 = e2 = sum2 / _p; + sum3 = e2 = sum2 / Math.Max(_p, base.Count); } } } else { sum1 += v; if (i == _p - 1) { - sum2 = e1 = sum1 / _p; + sum2 = e1 = sum1 / Math.Max(_p, base.Count); } } - if (!update) { i++; } double t3 = (c1 * e6) + (c2 * e5) + (c3 * e4) + (c4 * e3); base.Add(TValue: (TValue.t, t3), update: update, useNaN: _NaN); diff --git a/Source/Volatility/ADL_Series.cs b/Source/Volatility/ADL_Series.cs index 72210268..7e0a962f 100644 --- a/Source/Volatility/ADL_Series.cs +++ b/Source/Volatility/ADL_Series.cs @@ -5,7 +5,7 @@ using System; ADL: Chaikin Accumulation/Distribution Line ADL is a volume-based indicator that measures the cumulative Money Flow Volume: - 1. Money Flow Multiplier = [(Close - Low) - (High - Close)] /(High - Low) + 1. Money Flow Multiplier = [(Close - Low) - (High - Close)] /(High - Low) 2. Money Flow Volume = Money Flow Multiplier x Volume for the Period 3. ADL = Previous ADL + Current Period's Money Flow Volume @@ -20,19 +20,17 @@ public class ADL_Series : Single_TBars_Indicator public ADL_Series(TBars source, bool useNaN = false) : base(source, 0, useNaN) { - this._lastadl = this._lastlastadl = 0; - if (_bars.Count > 0) - { base.Add(_bars); } + _lastadl = _lastlastadl = 0; + if (_bars.Count > 0) { base.Add(_bars); } } public override void Add((DateTime t, double o, double h, double l, double c, double v) TBar, bool update) { - if (update) - { this._lastadl = this._lastlastadl; } + if (update) { this._lastadl = this._lastlastadl; } - double _mfm = ((TBar.c - TBar.l) - (TBar.h - TBar.c)) / (TBar.h - TBar.l); - double _mfv = _mfm * TBar.v; - double _adl = this._lastadl + _mfv; + double _adl = 0; + double tmp = TBar.h - TBar.l; + if (tmp > 0.0 ) { _adl = _lastadl + ((2*TBar.c - TBar.l - TBar.h) / tmp * TBar.v); } this._lastlastadl = this._lastadl; this._lastadl = _adl; diff --git a/Source/Volatility/ADOSC_Series.cs b/Source/Volatility/ADOSC_Series.cs index f8f219d0..e5b279bb 100644 --- a/Source/Volatility/ADOSC_Series.cs +++ b/Source/Volatility/ADOSC_Series.cs @@ -13,6 +13,47 @@ Sources: */ + +public class ADOSC_Series : Single_TBars_Indicator +{ + private readonly double _k1, _k2; + private double _lastema1, _lastlastema1, _lastema2, _lastlastema2; + private double _lastadl, _lastlastadl; + + public ADOSC_Series(TBars source, int shortPeriod = 3, int longPeriod =10, bool useNaN = false) : base(source, period: 0, useNaN) + { + _k1 = 2.0 / (shortPeriod + 1); + _k2 = 2.0 / (longPeriod + 1); + _lastadl = _lastlastadl = _lastema1 = _lastlastema1 = _lastema2 = _lastlastema2 = 0; + if (_bars.Count > 0) { base.Add(_bars); } + } + + public override void Add((DateTime t, double o, double h, double l, double c, double v) TBar, bool update) + { + if (update) { + _lastadl = _lastlastadl; + _lastema1 = _lastlastema1; + _lastema2 = _lastlastema2; + } + + double _adl = 0; + double tmp = TBar.h - TBar.l; + if (tmp > 0.0) { _adl = _lastadl + ((2 * TBar.c - TBar.l - TBar.h) / tmp * TBar.v); } + if (this.Count == 0) { _lastema1 = _lastema2 = _adl; } + + double _ema1 = (_adl - _lastema1) * _k1 + _lastema1; + double _ema2 = (_adl - _lastema2) * _k2 + _lastema2; + + _lastlastadl = _lastadl; _lastadl = _adl; + _lastlastema1 = _lastema1; _lastema1 = _ema1; + _lastlastema2 = _lastema2; _lastema2 = _ema2; + + double _adosc = _ema1 - _ema2; + base.Add((TBar.t, _adosc), update, _NaN); + } + +} +/* public class ADOSC_Series : Single_TBars_Indicator { private readonly ADL_Series _TSadl; @@ -42,4 +83,5 @@ public class ADOSC_Series : Single_TBars_Indicator var result = (TBar.t, _ado); base.Add(result, update); } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/Tests/Series/Update.cs b/Tests/Series/Update.cs index 37d3f9a7..ad8260e1 100644 --- a/Tests/Series/Update.cs +++ b/Tests/Series/Update.cs @@ -105,7 +105,7 @@ public class Update { Assert.Equal(lastCalc, QL.Last()); // same data } [Fact] public void COVAR() { - COVAR_Series QL = new(d1: bars.High, d2: bars.Low, period: period); + COVAR_Series QL = new(d1: bars.High, d2: bars.Low, period); var lastData = bars.Last(); var lastCalc = QL.Last(); int lastLen = QL.Count; @@ -124,7 +124,18 @@ public class Update { Assert.Equal(lastLen, QL.Count); // same size Assert.Equal(lastCalc, QL.Last()); // same data } - [Fact] public void ENTROPY() { + [Fact] + public void DWMA() { + DWMA_Series QL = new(source: bars.Close, period); + var lastData = bars.Close.Last(); + var lastCalc = QL.Last(); + int lastLen = QL.Count; + QL.Add((DateTime.Today, 0), update: true); + QL.Add(lastData, update: true); + Assert.Equal(lastLen, QL.Count); // same size + Assert.Equal(lastCalc, QL.Last()); // same data + } + [Fact] public void ENTROPY() { ENTROPY_Series QL = new(source: bars.Close, period: period); var lastData = bars.Close.Last(); var lastCalc = QL.Last(); diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index c584f538..19c1f9e1 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -19,6 +19,8 @@ + + @@ -28,5 +30,7 @@ + + diff --git a/Tests/Validations/Pandas_TA.cs b/Tests/Validations/Pandas_TA.cs deleted file mode 100644 index 2a971df5..00000000 --- a/Tests/Validations/Pandas_TA.cs +++ /dev/null @@ -1,203 +0,0 @@ -using Xunit; -using System; -using QuanTAlib; -using Python.Runtime; -using Python.Included; - -namespace Validations; -public class PandasTA : IDisposable -{ - private readonly GBM_Feed bars; - private readonly Random rnd = new(); - private readonly int period; - private int digits; - private readonly string OStype; - private readonly dynamic np; - private readonly dynamic ta; - private readonly dynamic df; - - public PandasTA() { - bars = new(Bars: 5000, Volatility: 0.8, Drift: 0.0); - period = rnd.Next(maxValue: 28) + 3; - digits = 4; //minimizing rounding errors in type conversions - - // Checking the host OS and setting PythonDLL accordingly - OStype = Path.GetFullPath(path: ".") + @"\python-3.10.0-embed-amd64\python310.dll"; - - Installer.InstallPath = Path.GetFullPath(path: "."); - Installer.SetupPython().Wait(); - Installer.TryInstallPip(); - Installer.PipInstallModule(module_name: "pandas-ta"); - Runtime.PythonDLL = OStype; - PythonEngine.Initialize(); - np = Py.Import(name: "numpy"); - ta = Py.Import(name: "pandas_ta"); - - 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)); - } - public void Dispose() - { - PythonEngine.Shutdown(); - GC.SuppressFinalize(this); - } - - [Fact] void ADL() { - ADL_Series QL = new(bars); - var pta = df.ta.ad(high: df.high, low: df.low, close:df.close, volume:df.volume); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(QL.Last().v, digits: 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); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] void ENTROPY() { - ENTROPY_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), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] void HL2() { - var pta = df.ta.hl2(high: df.high, low: df.low); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(bars.HL2.Last().v, digits: digits)); - } - [Fact] void HLC3() { - var pta = df.ta.hlc3(high: df.high, low: df.low, close: df.close); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(bars.HLC3.Last().v, digits: digits)); - } - [Fact] void HMA() { - HMA_Series QL = new(bars.Close, period, false); - var pta = df.ta.hma(close: df.close, length: period); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] void KAMA() { - KAMA_Series QL = new(bars.Close, period); - var pta = df.ta.kama(close: df.close, length: period); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] void KURTOSIS() { - KURTOSIS_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), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] void MEDIAN() { - MEDIAN_Series QL = new(bars.Close, period); - var pta = df.ta.median(close: df.close, length: period); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] void OBV() { - OBV_Series QL = new(bars); - var pta = df.ta.obv(close: df.close, volume: df.volume); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] void OHLC4() { - var pta = df.ta.ohlc4(open: df.open, high: df.high, low: df.low, close: df.close); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(bars.OHLC4.Last().v, digits: digits)); - } - [Fact] void RMA() { - RMA_Series QL = new(bars.Close, period, false); - var pta = df.ta.rma(close: df.close, length: period); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] void RSI() { - RSI_Series QL = new(bars.Close, period); - var pta = df.ta.rsi(close: df.close, length: period); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(QL.Last().v, digits: 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); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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), digits: digits), Math.Round(QL.Last().v, digits: 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); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] void SVARIANCE() { - SVAR_Series QL = new(bars.Close, period); - var pta = df.ta.variance(close: df.close, length: period, ddof: 1); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(QL.Last().v, digits: 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); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] void TR() { - TR_Series QL = new(bars); - var pta = df.ta.true_range(high: df.high, low: df.low, close: df.close); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(QL.Last().v, digits: 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); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] void VARIANCE() { - VAR_Series QL = new(bars.Close, period); - var pta = df.ta.variance(close: df.close, length: period, ddof:0); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] void ZLEMA() { - ZLEMA_Series QL = new(bars.Close, period, false); - var pta = df.ta.zlma(close: df.close, length: period); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(QL.Last().v, digits: 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); - Assert.Equal(Math.Round((double)pta.tail(1), digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - -} \ No newline at end of file diff --git a/Tests/Validations/Skender_Stock.cs b/Tests/Validations/Skender_Stock.cs deleted file mode 100644 index 418f9611..00000000 --- a/Tests/Validations/Skender_Stock.cs +++ /dev/null @@ -1,204 +0,0 @@ -using System; -using QuanTAlib; -using Skender.Stock.Indicators; -using Xunit; - -namespace Validations; -public class Skender_Stock { - private readonly GBM_Feed bars; - private readonly Random rnd = new(); - private readonly int period, digits; - private readonly IEnumerable quotes; - - public Skender_Stock() { - bars = new(Bars: 5000, Volatility: 0.8, Drift: 0.0); - period = rnd.Next(28) + 3; - digits = 4; //minimizing rounding errors in type conversions - - 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 ADL() { - ADL_Series QL = new(bars, false); - var SK = quotes.GetAdl(); - Assert.Equal(Math.Round(SK.Last().Adl!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void ALMA() { - ALMA_Series QL = new(bars.Close, period, useNaN: false); - var SK = quotes.GetAlma(period); - Assert.Equal(Math.Round((double)SK.Last().Alma!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void ATR() { - ATR_Series QL = new(bars, period, false); - var SK = quotes.GetAtr(period); - Assert.Equal(Math.Round((double)SK.Last().Atr!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void ATRP() { - ATRP_Series QL = new(bars, period, false); - var SK = quotes.GetAtr(period); - Assert.Equal(Math.Round((double)SK.Last().Atrp!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void BBANDS() { - 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!, digits: digits), Math.Round(QL.Mid.Last().v, digits: digits)); - Assert.Equal(Math.Round((double)SK.Last().UpperBand!, digits: digits), Math.Round(QL.Upper.Last().v, digits: digits)); - Assert.Equal(Math.Round((double)SK.Last().LowerBand!, digits: digits), Math.Round(QL.Lower.Last().v, digits: digits)); - Assert.Equal(Math.Round((double)SK.Last().Width!, digits: digits), Math.Round(QL.Bandwidth.Last().v, digits: digits)); - Assert.Equal(Math.Round((double)SK.Last().PercentB!, digits: digits), Math.Round(QL.PercentB.Last().v, digits: digits)); - Assert.Equal(Math.Round((double)SK.Last().ZScore!, digits: digits), Math.Round(QL.Zscore.Last().v, digits: digits)); - } - [Fact] public void CCI() { - CCI_Series QL = new(bars, period, false); - var SK = quotes.GetCci(period); - Assert.Equal(Math.Round((double)SK.Last().Cci!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void CORR() { - CORR_Series QL = new(bars.High, bars.Low, period, false); - var SK = quotes.Use(CandlePart.High).GetCorrelation(quotes.Use(CandlePart.Low), period); - Assert.Equal(Math.Round((double)SK.Last().Correlation!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void COVAR() { - COVAR_Series QL = new(bars.High, bars.Low, period, false); - var SK = quotes.Use(CandlePart.High).GetCorrelation(quotes.Use(CandlePart.Low), period); - Assert.Equal(Math.Round((double)SK.Last().Covariance!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void HL2() { - TSeries QL = bars.HL2; - var SK = quotes.GetBaseQuote(CandlePart.HL2); - Assert.Equal(Math.Round(SK.Last().Value!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void HLC3() { - TSeries QL = bars.HLC3; - var SK = quotes.GetBaseQuote(CandlePart.HLC3); - Assert.Equal(Math.Round(SK.Last().Value!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void HMA() { - HMA_Series QL = new(bars.Close, period, useNaN: false); - var SK = quotes.GetHma(period); - Assert.Equal(Math.Round((double)SK.Last().Hma!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void KAMA() { - KAMA_Series QL = new(bars.Close, period, useNaN: false); - var SK = quotes.GetKama(period); - Assert.Equal(Math.Round((double)SK.Last().Kama!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void LINREG() { - LINREG_Series QL = new(bars.Close, period, useNaN: false); - var SK = quotes.GetSlope(period); - Assert.Equal(Math.Round((double)SK.Last().Slope!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - Assert.Equal(Math.Round((double)SK.Last().Intercept!, digits: digits), Math.Round(QL.Intercept.Last().v, digits: digits)); - Assert.Equal(Math.Round((double)SK.Last().RSquared!, digits: digits), Math.Round(QL.RSquared.Last().v, digits: digits)); - Assert.Equal(Math.Round((double)SK.Last().StdDev!, digits: digits), Math.Round(QL.StdDev.Last().v, digits: digits)); - } - [Fact] public void MACD() { - 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!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - Assert.Equal(Math.Round((double)SK.Last().Signal!, digits: digits), Math.Round(QL.Signal.Last().v, digits: digits)); - } - [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!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void MAMA() { - MAMA_Series QL = new(bars.HL2, fastlimit: 0.5, slowlimit: 0.05); - var SK = quotes.GetMama(fastLimit: 0.5, slowLimit: 0.05); - Assert.Equal(Math.Round((double)SK.Last().Mama!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - Assert.Equal(Math.Round((double)SK.Last().Fama!, digits: digits), Math.Round(QL.Fama.Last().v, digits: digits)); - } - [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!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void MSE() { - MSE_Series QL = new(bars.Close, period, false); - var SK = quotes.GetSmaAnalysis(period); - Assert.Equal(Math.Round((double)SK.Last().Mse!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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)quotes.First().Volume!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void OC2() { - TSeries QL = bars.OC2; - var SK = quotes.GetBaseQuote(CandlePart.OC2); - Assert.Equal(Math.Round(SK.Last().Value!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void OHL3() { - TSeries QL = bars.OHL3; - var SK = quotes.GetBaseQuote(CandlePart.OHL3); - Assert.Equal(Math.Round(SK.Last().Value!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void OHLC4() { - TSeries QL = bars.OHLC4; - var SK = quotes.GetBaseQuote(CandlePart.OHLC4); - Assert.Equal(Math.Round(SK.Last().Value!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void RSI() { - RSI_Series QL = new(bars.Close, period, useNaN: false); - var SK = quotes.GetRsi(period); - Assert.Equal(Math.Round((double)SK.Last().Rsi!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void SDEV() { - SDEV_Series QL = new(bars.Close, period, useNaN: false); - var SK = quotes.GetStdDev(period); - Assert.Equal(Math.Round((double)SK.Last().StdDev!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void SMMA() { - SMMA_Series QL = new(bars.Close, period, useNaN: false); - var SK = quotes.GetSmma(period); - Assert.Equal(Math.Round((double)SK.Last().Smma!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void T3() { - T3_Series QL = new(source: bars.Close, period, vfactor: 0.7, false); - var SK = quotes.GetT3(lookbackPeriods: period, volumeFactor: 0.7); - Assert.Equal(Math.Round((double)SK.Last().T3!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void TR() { - TR_Series QL = new(bars, useNaN: false); - var SK = quotes.GetTr(); - Assert.Equal(Math.Round((double)SK.Last().Tr!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void ZSCORE() { - ZSCORE_Series QL = new(bars.Close, period, useNaN: false); - var SK = quotes.GetStdDev(period); - Assert.Equal(Math.Round((double)SK.Last().ZScore!, digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - -} diff --git a/Tests/Validations/TA_LIB.cs b/Tests/Validations/TA_LIB.cs deleted file mode 100644 index e6e87b71..00000000 --- a/Tests/Validations/TA_LIB.cs +++ /dev/null @@ -1,208 +0,0 @@ -using Xunit; -using System; -using TALib; -using QuanTAlib; - -namespace Validations; -public class Ta_Lib -{ - private readonly GBM_Feed bars; - private readonly Random rnd = new(); - private readonly int period, digits; - private readonly double[] TALIB; - private readonly double[] TALIB2; - private readonly double[] inopen; - private readonly double[] inhigh; - private readonly double[] inlow; - private readonly double[] inclose; - private readonly double[] involume; - - public Ta_Lib() { - bars = new(Bars: 5000, Volatility: 0.8, Drift: 0.0); - period = rnd.Next(28) + 3; - digits = 6; - - TALIB = new double[bars.Count]; - TALIB2 = 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(bars.Open, bars.Close); - Core.Add(inopen, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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 _); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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 _); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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], digits: digits), Math.Round(QL.Upper.Last().v, digits: digits)); - Assert.Equal(Math.Round(outMiddle[outMiddle.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Mid.Last().v, digits: digits)); - Assert.Equal(Math.Round(outLower[outLower.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Lower.Last().v, digits: digits)); - } - [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); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void CORR() { - CORR_Series QL = new(bars.Open, bars.Close, period); - Core.Correl(inopen, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, optInTimePeriod: period); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void HL2() { - TSeries QL = bars.HL2; - Core.MedPrice(inhigh, inlow, 0, bars.Count - 1, TALIB, out int outBegIdx, out _); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void HLC3() { - TSeries QL = bars.HLC3; - Core.TypPrice(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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], digits: digits), Math.Round(QL.Last().v, digits: digits)); - Assert.Equal(Math.Round(macdSignal[macdSignal.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Signal.Last().v, digits: digits)); - } - [Fact] public void MAMA() { - MAMA_Series QL = new(bars.Close, fastlimit: 0.5, slowlimit: 0.05); - Core.Mama(inReal: inclose, startIdx: 0, endIdx: bars.Count - 1, outMama: TALIB, outFama: TALIB2, outBegIdx: out int outBegIdx, outNbElement: out _, optInFastLimit: 0.5, optInSlowLimit: 0.05); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void MIDPOINT() { - MIDPOINT_Series QL = new(bars.Close, period, false); - Core.MidPoint(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void MIDPRICE() { - MIDPRICE_Series QL = new(bars, period, false); - Core.MidPrice(inhigh, inlow, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void OBV() { - OBV_Series QL = new(bars, period, false); - Core.Obv(inclose, involume, 0, bars.Count - 1, TALIB, out int outBegIdx, out _); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void OHLC4() { - TSeries QL = bars.OHLC4; - Core.AvgPrice(inopen, inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void SUM() { - SUM_Series QL = new(bars.Close, period, false); - Core.Sum(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void T3() { - T3_Series QL = new(source: bars.Close, period: period, vfactor:0.7, useNaN: false); - Core.T3(inReal: inclose, startIdx: 0, endIdx: bars.Count - 1, outReal: TALIB, outBegIdx: out int outBegIdx, outNbElement: out _, optInTimePeriod: period, optInVFactor: 0.7); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void TR() { - TR_Series QL = new(bars, false); - Core.TRange(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [Fact] public void VAR() { - VAR_Series QL = new(bars.Close, period, false); - Core.Var(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - [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); - Assert.Equal(Math.Round(TALIB[TALIB.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Last().v, digits: digits)); - } - -} diff --git a/Tests/Validations/Trends/Pandas_TA.cs b/Tests/Validations/Trends/Pandas_TA.cs new file mode 100644 index 00000000..e38c82a9 --- /dev/null +++ b/Tests/Validations/Trends/Pandas_TA.cs @@ -0,0 +1,361 @@ +using Xunit; +using System; +using QuanTAlib; +using Python.Runtime; +using Python.Included; + +namespace Validations; +public class PandasTA : IDisposable +{ + private readonly GBM_Feed bars; + private readonly Random rnd = new(); + private readonly int period, sample; + private int digits; + private readonly string OStype; + private readonly dynamic np; + private readonly dynamic ta; + private readonly dynamic df; + + public PandasTA() { + bars = new(Bars: 5000, Volatility: 0.8, Drift: 0.0); + period = rnd.Next(maxValue: 28) + 3; + sample = 200; + digits = 10; + + // 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"; + + Installer.InstallPath = Path.GetFullPath(path: "."); + Installer.SetupPython().Wait(); + Installer.TryInstallPip(); + Installer.PipInstallModule(module_name: "pandas-ta"); + Runtime.PythonDLL = OStype; + PythonEngine.Initialize(); + np = Py.Import(name: "numpy"); + ta = Py.Import(name: "pandas_ta"); + + 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)); + } + public void Dispose() + { + PythonEngine.Shutdown(); + GC.SuppressFinalize(this); + } + + [Fact] 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 (int i = QL.Length; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i-1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i-1], digits: digits); + Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + + } + } + [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; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + 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; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] void BIAS() { + BIAS_Series QL = new(bars.Close, period, false); + var pta = df.ta.bias(close: df.close, length: period); + for (int i = QL.Length; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] void DEMA() { + DEMA_Series QL = new(bars.Close, period, false); + var pta = df.ta.dema(close: df.close, length: period); + for (int i = QL.Length; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] void EMA() { + EMA_Series QL = new(bars.Close, period, false); + var pta = df.ta.ema(close: df.close, length: period); + for (int i = QL.Length; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: 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; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + 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; i > bars.HL2.Length-sample; i--) + { + double QL_item = Math.Round(bars.HL2[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] void HLC3() { + var pta = df.ta.hlc3(high: df.high, low: df.low, close: df.close); + for (int i = bars.HLC3.Length; i > bars.HLC3.Length-sample; i--) + { + double QL_item = Math.Round(bars.HLC3[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] void HMA() { + HMA_Series QL = new(bars.Close, period, false); + var pta = df.ta.hma(close: df.close, length: period); + for (int i = QL.Length; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + 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; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + 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; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] void MAD() + { + MAD_Series QL = new(bars.Close, period, useNaN: false); + var pta = df.ta.mad(close: df.close, length: period); + for (int i = QL.Length; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] void MEDIAN() { + MEDIAN_Series QL = new(bars.Close, period); + var pta = df.ta.median(close: df.close, length: period); + for (int i = QL.Length; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + 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; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + 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 > bars.OHLC4.Length-sample; i--) + { + double QL_item = Math.Round(bars.OHLC4[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + 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; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + 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; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + 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; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + 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; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + 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; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + 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; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + 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; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + 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; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + 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; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + 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; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] void VARIANCE() { + VAR_Series QL = new(bars.Close, period); + var pta = df.ta.variance(close: df.close, length: period, ddof:0); + for (int i = QL.Length; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] void WMA() { + WMA_Series QL = new(bars.Close, period, false); + var pta = df.ta.wma(close: df.close, length: period); + for (int i = QL.Length; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: 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; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + 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; i > QL.Length-sample; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double PanTA_item = Math.Round((double)pta[i - 1], digits: digits); + Assert.InRange(PanTA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + +} \ No newline at end of file diff --git a/Tests/Validations/Trends/Skender.cs b/Tests/Validations/Trends/Skender.cs new file mode 100644 index 00000000..0efda3dd --- /dev/null +++ b/Tests/Validations/Trends/Skender.cs @@ -0,0 +1,472 @@ +using System; +using QuanTAlib; +using Skender.Stock.Indicators; +using Xunit; + +namespace Validations; +public class Skender +{ + private readonly GBM_Feed bars; + private readonly Random rnd = new(); + private readonly int period, digits, skip; + private readonly IEnumerable quotes; + + + public Skender() + { + bars = new(Bars: 10000, Volatility: 0.5, Drift: 0.0, Precision: 2); + period = rnd.Next(30) + 5; + skip = 200; + digits = 10; + + 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 ADL() + { + ADL_Series QL = new(bars, false); + var SK = quotes.GetAdl().Select(i => i.Adl); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round(SK.ElementAt(i - 1)!, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void ALMA() + { + ALMA_Series QL = new(bars.Close, period, useNaN: false); + var SK = quotes.GetAlma(period).Select(i => i.Alma.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void ATR() + { + ATR_Series QL = new(bars, period, false); + var SK = quotes.GetAtr(period).Select(i => i.Atr.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void ATRP() + { + ATRP_Series QL = new(bars, period, false); + var SK = quotes.GetAtr(period).Select(i => i.Atrp.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void BBANDS() + { + BBANDS_Series QL = new(bars.Close, period, 2.0, useNaN: false); + var SK = quotes.GetBollingerBands(period, 2.0); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL.Mid[i - 1].v, digits: digits); + double SK_item = Math.Round((double)SK.ElementAt(i - 1).Sma!.Value, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + QL_item = Math.Round(QL.Upper[i - 1].v, digits: digits); + SK_item = Math.Round((double)SK.ElementAt(i - 1).UpperBand!.Value, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + QL_item = Math.Round(QL.Lower[i - 1].v, digits: digits); + SK_item = Math.Round((double)SK.ElementAt(i - 1).LowerBand!.Value, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + QL_item = Math.Round(QL.Bandwidth[i - 1].v, digits: digits); + SK_item = Math.Round((double)SK.ElementAt(i - 1).Width!.Value, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + QL_item = Math.Round(QL.PercentB[i - 1].v, digits: digits); + SK_item = Math.Round((double)SK.ElementAt(i - 1).PercentB!.Value, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + QL_item = Math.Round(QL.Zscore[i - 1].v, digits: digits); + SK_item = Math.Round((double)SK.ElementAt(i - 1).ZScore!.Value, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void CCI() + { + CCI_Series QL = new(bars, period, false); + var SK = quotes.GetCci(period).Select(i => i.Cci.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void CORR() + { + CORR_Series QL = new(bars.High, bars.Low, period, false); + var SK = quotes.Use(CandlePart.High).GetCorrelation(quotes.Use(CandlePart.Low), period).Select(i => i.Correlation.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void COVAR() + { + COVAR_Series QL = new(bars.High, bars.Low, period, false); + var SK = quotes.Use(CandlePart.High).GetCorrelation(quotes.Use(CandlePart.Low), period).Select(i => i.Covariance.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } +/* + [Fact] + public void DEMA() + { + DEMA_Series QL = new(bars.Close, period, false); + var SK = quotes.GetDema(period).Select(i => i.Dema.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } +*/ + [Fact] + public void EMA() + { + EMA_Series QL = new(bars.Close, period, false); + var SK = quotes.GetEma(period).Select(i => i.Ema.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round((double)SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + /* + [Fact] + public void HL2() + { + TSeries QL = bars.HL2; + var SK = quotes.GetBaseQuote(CandlePart.HL2).Select(i => i.Value); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round((double)SK.ElementAt(i - 1)!, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void HLC3() + { + TSeries QL = bars.HLC3; + var SK = quotes.GetBaseQuote(CandlePart.HLC3).Select(i => i.Value); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round((double)SK.ElementAt(i - 1)!, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + */ + [Fact] + public void HMA() + { + HMA_Series QL = new(bars.Close, period, useNaN: false); + var SK = quotes.GetHma(period).Select(i => i.Hma.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } +/* + [Fact] + public void KAMA() + { + // TODO: check precision of KAMA() + KAMA_Series QL = new(bars.Close, period, useNaN: false); + var SK = quotes.GetKama(period).Select(i => i.Kama.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits/2), Math.Exp(-digits/2)); + } + } +*/ + [Fact] + public void LINREG() + { + LINREG_Series QL = new(bars.Close, period, useNaN: false); + var SK = quotes.GetSlope(period); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round((double)SK.ElementAt(i - 1).Slope!, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + QL_item = Math.Round(QL.Intercept[i - 1].v, digits: digits); + SK_item = Math.Round((double)SK.ElementAt(i - 1).Intercept!, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + QL_item = Math.Round(QL.RSquared[i - 1].v, digits: digits); + SK_item = Math.Round((double)SK.ElementAt(i - 1).RSquared!, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + QL_item = Math.Round(QL.StdDev[i - 1].v, digits: digits); + SK_item = Math.Round((double)SK.ElementAt(i - 1).StdDev!, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void MACD() + { + MACD_Series QL = new(bars.Close, 26, 12, 9, useNaN: false); + var SK = quotes.GetMacd(12, 26, 9); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round(SK.ElementAt(i - 1).Macd.Null2NaN()!, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + QL_item = Math.Round(QL.Signal[i - 1].v, digits: digits); + SK_item = Math.Round(SK.ElementAt(i - 1).Signal.Null2NaN()!, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void MAD() + { + MAD_Series QL = new(bars.Close, period, false); + var SK = quotes.GetSmaAnalysis(period).Select(i => i.Mad.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void MAMA() + { + MAMA_Series QL = new(bars.HL2, fastlimit: 0.5, slowlimit: 0.05); + var SK = quotes.GetMama(fastLimit: 0.5, slowLimit: 0.05); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round(SK.ElementAt(i - 1).Mama.Null2NaN()!, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + QL_item = Math.Round(QL.Fama[i - 1].v, digits: digits); + SK_item = Math.Round(SK.ElementAt(i - 1).Fama.Null2NaN()!, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void MAPE() + { + MAPE_Series QL = new(bars.Close, period, false); + var SK = quotes.GetSmaAnalysis(period).Select(i => i.Mape.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void MSE() + { + MSE_Series QL = new(bars.Close, period, false); + var SK = quotes.GetSmaAnalysis(period).Select(i => i.Mse.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void OBV() + { + OBV_Series QL = new(bars, period, false); + var SK = quotes.GetObv(period).Select(i => i.Obv!); + // adding volume[0] to OBV to pass the test and keep compatibility with TA-LIB + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL.Last().v, digits: digits); + double SK_item = Math.Round(SK.Last()! + (double)quotes.First().Volume!, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + /* + [Fact] + public void OC2() + { + TSeries QL = bars.OC2; + var SK = quotes.GetBaseQuote(CandlePart.OC2).Select(i => i.Value); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round((double)SK.ElementAt(i - 1)!, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void OHL3() + { + TSeries QL = bars.OHL3; + var SK = quotes.GetBaseQuote(CandlePart.OHL3).Select(i => i.Value); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round((double)SK.ElementAt(i - 1)!, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void OHLC4() + { + TSeries QL = bars.OHLC4; + var SK = quotes.GetBaseQuote(CandlePart.OHLC4).Select(i => i.Value); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round((double)SK.ElementAt(i - 1)!, digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + */ + [Fact] + public void RSI() + { + RSI_Series QL = new(bars.Close, period, useNaN: false); + var SK = quotes.GetRsi(period).Select(i => i.Rsi.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void SDEV() + { + SDEV_Series QL = new(bars.Close, period, useNaN: false); + var SK = quotes.GetStdDev(period).Select(i => i.StdDev.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void SMA() + { + SMA_Series QL = new(bars.Close, period, false); + var SK = quotes.GetSma(period).Select(i => i.Sma.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void SMMA() + { + SMMA_Series QL = new(bars.Close, period, useNaN: false); + var SK = quotes.GetSmma(period).Select(i => i.Smma.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } +/* + [Fact] + public void T3() + { + T3_Series QL = new(source: bars.Close, period: period, vfactor: 0.7, false); + var SK = quotes.GetT3(lookbackPeriods: period, volumeFactor: 0.7).Select(i => i.T3.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } +*/ + [Fact] + public void TEMA() + { + TEMA_Series QL = new(bars.Close, period, false); + var SK = quotes.GetTema(period).Select(i => i.Tema.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void TR() + { + TR_Series QL = new(bars, useNaN: false); + var SK = quotes.GetTr().Select(i => i.Tr.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void WMA() + { + WMA_Series QL = new(bars.Close, period, false); + var SK = quotes.GetWma(period).Select(i => i.Wma.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void ZSCORE() + { + ZSCORE_Series QL = new(bars.Close, period, useNaN: false); + var SK = quotes.GetStdDev(period).Select(i => i.ZScore.Null2NaN()!); + for (int i = QL.Length; i > skip; i--) + { + double QL_item = Math.Round(QL[i - 1].v, digits: digits); + double SK_item = Math.Round(SK.ElementAt(i - 1), digits: digits); + Assert.InRange(SK_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + +} diff --git a/Tests/Validations/Trends/TA_LIB.cs b/Tests/Validations/Trends/TA_LIB.cs new file mode 100644 index 00000000..d9d783be --- /dev/null +++ b/Tests/Validations/Trends/TA_LIB.cs @@ -0,0 +1,452 @@ +using Xunit; +using System; +using TALib; +using QuanTAlib; + +namespace Validations; +public class Ta_Lib +{ + private readonly GBM_Feed bars; + private readonly Random rnd = new(); + private readonly int period, digits, skip; + private readonly double[] TALIB; + private readonly double[] TALIB2; + private readonly double[] inopen; + private readonly double[] inhigh; + private readonly double[] inlow; + private readonly double[] inclose; + private readonly double[] involume; + + public Ta_Lib() + { + bars = new(Bars: 5000, Volatility: 0.8, Drift: 0.0, Precision: 3); + period = rnd.Next(28) + 3; + skip = 500; + digits = 10; + + TALIB = new double[bars.Count]; + TALIB2 = 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(bars.Open, bars.Close); + Core.Add(inopen, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [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 _); + for (int i = QL.Length - 1; i > 0; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void ADOSC() + { + ADOSC_Series QL = new(bars, 3, 10, false); + Core.AdOsc(inhigh, inlow, inclose, involume, 0, bars.Count - 1, TALIB, out int outBegIdx, out _); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [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); + for (int i = QL.Length - 1; i > skip * 15; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } +/* + [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); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL.Upper[i].v, digits: digits); + double TA_item = Math.Round(outUpper[i - outBegIdx], digits: digits); + Assert.Equal(TA_item!, QL_item); + QL_item = Math.Round(QL.Mid[i].v, digits: digits); + TA_item = Math.Round(outMiddle[i - outBegIdx], digits: digits); + Assert.Equal(TA_item!, QL_item); + QL_item = Math.Round(QL.Lower[i].v, digits: digits); + TA_item = Math.Round(outLower[i - outBegIdx], digits: digits); + Assert.Equal(TA_item!, QL_item); + } + Assert.Equal(Math.Round(outUpper[outUpper.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Upper.Last().v, digits: digits)); + Assert.Equal(Math.Round(outMiddle[outMiddle.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Mid.Last().v, digits: digits)); + Assert.Equal(Math.Round(outLower[outLower.Length - outBegIdx - 1], digits: digits), Math.Round(QL.Lower.Last().v, digits: digits)); + } +*/ + [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); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void CORR() + { + CORR_Series QL = new(bars.Open, bars.Close, period); + Core.Correl(inopen, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, optInTimePeriod: period); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [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); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [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 _); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [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); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void HL2() + { + TSeries QL = bars.HL2; + Core.MedPrice(inhigh, inlow, 0, bars.Count - 1, TALIB, out int outBegIdx, out _); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void HLC3() + { + TSeries QL = bars.HLC3; + Core.TypPrice(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void HLCC4() + { + TSeries QL = bars.HLCC4; + Core.WclPrice(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [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 _); + for (int i = QL.Length - 1; i > skip * 10; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.Equal(TA_item!, QL_item); + QL_item = Math.Round(QL.Signal[i].v, digits: digits); + TA_item = Math.Round(macdSignal[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void MAMA() + { + MAMA_Series QL = new(bars.Close, fastlimit: 0.5, slowlimit: 0.05); + Core.Mama(inReal: inclose, startIdx: 0, endIdx: bars.Count - 1, outMama: TALIB, outFama: TALIB2, outBegIdx: out int outBegIdx, outNbElement: out _, optInFastLimit: 0.5, optInSlowLimit: 0.05); + for (int i = QL.Length - 1; i > skip * 15; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [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); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void MIDPOINT() + { + MIDPOINT_Series QL = new(bars.Close, period, false); + Core.MidPoint(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void MIDPRICE() + { + MIDPRICE_Series QL = new(bars, period, false); + Core.MidPrice(inhigh, inlow, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [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); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [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 _); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void OBV() + { + OBV_Series QL = new(bars, period, false); + Core.Obv(inclose, involume, 0, bars.Count - 1, TALIB, out int outBegIdx, out _); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void OHLC4() + { + TSeries QL = bars.OHLC4; + Core.AvgPrice(inopen, inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [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); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [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); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [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); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [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 _); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void SUM() + { + SUM_Series QL = new(bars.Close, period, false); + Core.Sum(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void T3() + { + T3_Series QL = new(source: bars.Close, period: period, vfactor: 0.7, useNaN: false); + Core.T3(inReal: inclose, startIdx: 0, endIdx: bars.Count - 1, outReal: TALIB, outBegIdx: out int outBegIdx, outNbElement: out _, optInTimePeriod: period, optInVFactor: 0.7); + for (int i = QL.Length - 1; i > skip * 15; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [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); + for (int i = QL.Length - 1; i > skip * 15; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void TR() + { + TR_Series QL = new(bars, false); + Core.TRange(inhigh, inlow, inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [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); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void VAR() + { + VAR_Series QL = new(bars.Close, period, false); + Core.Var(inclose, 0, bars.Count - 1, TALIB, out int outBegIdx, out _, period); + for (int i = QL.Length - 1; i > skip * 15; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [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); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TA_item = Math.Round(TALIB[i - outBegIdx], digits: digits); + Assert.InRange(TA_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + +} diff --git a/Tests/Validations/Trends/Tulip.cs b/Tests/Validations/Trends/Tulip.cs new file mode 100644 index 00000000..b7ddcc32 --- /dev/null +++ b/Tests/Validations/Trends/Tulip.cs @@ -0,0 +1,158 @@ +using Xunit; +using System; +using Tulip; +using QuanTAlib; + +namespace Validations; +public class Tulip_Test +{ + private readonly GBM_Feed bars; + private readonly Random rnd = new(); + private readonly int period, digits, skip; + private readonly double[] outdata; + private readonly double[] inopen; + private readonly double[] inhigh; + private readonly double[] inlow; + private readonly double[] inclose; + private readonly double[] involume; + + public Tulip_Test() + { + bars = new(Bars: 5000, Volatility: 0.8, Drift: 0.0, Precision: 3); + period = rnd.Next(28) + 3; + skip = 200; + digits = 10; + + outdata = 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 AD() + { + double[][] arrin = {inhigh, inlow, inclose, involume }; + double[][] arrout = { outdata }; + ADL_Series QL = new(bars, false); + Tulip.Indicators.ad.Run(inputs: arrin, options: new double[] { }, outputs: arrout); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TU_item = Math.Round(arrout[0][i], digits); + Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void ADD() + { + double[][] arrin = { inhigh, inlow }; + double[][] arrout = { outdata }; + ADD_Series QL = new(bars.High, bars.Low); + Tulip.Indicators.add.Run(inputs: arrin, options: new double[] { period }, outputs: arrout); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TU_item = Math.Round(arrout[0][i], digits); + Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void ADOSC() + { + double[][] arrin = { inhigh, inlow, inclose, involume }; + double[][] arrout = { outdata }; + int s = 3; + ADOSC_Series QL = new(bars, s, period, false); + Tulip.Indicators.adosc.Run(inputs: arrin, options: new double[] { s, period }, outputs: arrout); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TU_item = Math.Round(arrout[0][i-period+1], digits); + Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void ATR() + { + double[][] arrin = { inhigh, inlow, inclose }; + double[][] arrout = { outdata }; + + ATR_Series QL = new(bars, period, false); + Tulip.Indicators.atr.Run(inputs: arrin, options: new double[] { period }, outputs: arrout); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TU_item = Math.Round(arrout[0][i - period + 1], digits); + Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void BBANDS() + { + double[][] arrin = { inclose }; + double[] outmid = new double[bars.Count]; + double[] outlower = new double[bars.Count]; + double[] outupper = new double[bars.Count]; + double[][] arrout = { outlower, outmid, outupper}; + BBANDS_Series QL = new(bars.Close, period, 2, false); + Tulip.Indicators.bbands.Run(inputs: arrin, options: new double[] { period, 2 }, outputs: arrout); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL.Lower[i].v, digits: digits); + double TU_item = Math.Round(outlower[i - period + 1], digits); + Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + QL_item = Math.Round(QL.Mid[i].v, digits: digits); + TU_item = Math.Round(outmid[i - period + 1], digits); + Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + QL_item = Math.Round(QL.Upper[i].v, digits: digits); + TU_item = Math.Round(outupper[i - period + 1], digits); + Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void EMA() + { + double[][] arrin = { inclose }; + double[][] arrout = { outdata }; + EMA_Series QL = new(bars.Close, period, false); + Tulip.Indicators.ema.Run(inputs: arrin, options: new double[] { period }, outputs: arrout); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TU_item = Math.Round(arrout[0][i], digits); + Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void AVGPRICE() + { + double[][] arrin = { inopen, inhigh, inlow, inclose }; + double[][] arrout = { outdata }; + + TSeries QL = bars.OHLC4; + Tulip.Indicators.avgprice.Run(inputs: arrin, options: new double[] { }, outputs: arrout); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TU_item = Math.Round(arrout[0][i], digits); + Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } + [Fact] + public void SMA() + { + double[][] arrin = { inclose }; + double[][] arrout = { outdata }; + SMA_Series QL = new(bars.Close, period, false); + Tulip.Indicators.sma.Run(inputs: arrin, options: new double[] { period }, outputs: arrout); + for (int i = QL.Length - 1; i > skip; i--) + { + double QL_item = Math.Round(QL[i].v, digits: digits); + double TU_item = Math.Round(arrout[0][i-period+1], digits); + Assert.InRange(TU_item! - QL_item, -Math.Exp(-digits), Math.Exp(-digits)); + } + } +} diff --git a/docs/EMA.md b/docs/EMA.md new file mode 100644 index 00000000..ac161421 --- /dev/null +++ b/docs/EMA.md @@ -0,0 +1,38 @@ +# EMA: Exponential Moving Average + +EMA needs very short history buffer and calculates the EMA value using just the previous EMA value. The weight of the new datapoint (k) is k = 2 / (period-1) + +## Calculation + +There is an adopted practice to calculate $SMA$ when $n < period$. + +$$ +EMA_n = \left\{ \begin{array}{cl} +\frac{1}{p}\left( data_{n}-data_{n-p}\right)+SMA_{n-1} & : \ n \leq period \\ +{k}\times ({data_{n}} - EMA_{n-1}) + EMA_{n-1} & : \ x > period +\end{array} \right. +$$ + + +## Implementation + +``` csharp +EMA_Series mean = new(source: data, period: p, useNaN: false); +``` + +- `TSeries source` - List of value tuples (DateTime, double) +- `int period` - Integer representing the period of SMA +- `bool useNaN` - if true, initial values from 1 to period-1 will be replaced with NaN. If false, the initial calculation will return values for SMA(length) instead of SMA(period) + +## Comparison & Validation + +Validation tests +Performance tests + +## Visual analysis + +![Alt text](./img/EMA_chart.svg) + + + +## References diff --git a/docs/SMA.md b/docs/SMA.md new file mode 100644 index 00000000..557852bd --- /dev/null +++ b/docs/SMA.md @@ -0,0 +1,39 @@ +![Alt text](./img/SMA_chart.svg) +# SMA: Simple Moving Average +SMA is one of the most basic trend-following indicators used in Technical Analysis. It is calculated as the *unweighted mean* of the previous $p$ (period) data-points. + + +## Calculation + +SMA is a rolling calculation looking backwards from the position ${n}$ and is denoted as ${SMA}_{p}{(data)}$ where $p$ represents the period and $data$ represents the list of data points: +$$ +SMA_p{(data)} = \frac{1}{p}\sum_{i=n-p+1}^{n} data_i +$$ +When calculating the value of next $SMA_{p,next}$ while knowing all previous SMA values, SMA calculation can be reduced to: +$$ +SMA_{p,next} = SMA_{p,prev}+\frac{1}{p}\left( data_{n+1}-data_{n+1-p}\right) +$$ + +## Implementation + +``` csharp +SMA_Series mean = new(source: data, period: p, useNaN: false); +``` + +- `TSeries source` - List of value tuples (DateTime, double) +- `int period` - Integer representing the period of SMA +- `bool useNaN` - if true, initial values from 1 to period-1 will be replaced with NaN. If false, the initial calculation will return values for SMA(length) instead of SMA(period) + +## Comparison & Validation + +Validation tests +Performance tests + +## Visual analysis + + + + + +## References + - https://www.tradingtechnologies.com/help/x-study/technical-indicator-definitions/simple-moving-average-sma/ \ No newline at end of file diff --git a/docs/_sidebar.md b/docs/_sidebar.md new file mode 100644 index 00000000..a61da47f --- /dev/null +++ b/docs/_sidebar.md @@ -0,0 +1,13 @@ +* [Home](/) + +* [Indicators](indicators.md "Indocators coverage") + + * [SMA - Simple Moving Average](SMA.md "SMA - Simple Moving Average") + * [WMA - Weighted Moving Average](WMA.md "WMA - Weighted Moving Average") + * [EMA - Exponential Moving Average](EMA.md "EMA - Exponential Moving Average") + * [DEMA - Double Exponential Moving Average](DEMA.md "DEMA - Double Exponential Moving Average") + * [TEMA - Triple Exponential Moving Average](TEMA.md "TEMA - Triple Exponential Moving Average") + * [HMA - Hull Moving Average](HMA.md "HMA - Hull Moving Average") + * [ZLEMA - Zero-Lag Exponential Moving Average](ZLEMA.md "ZLEMA - Zero-Lag Exponential Moving Average") + * [KAMA - Kaufman Adaptive Moving Average](KAMA.md "KAMA - Kaufman Adaptive Moving Average") + * [MAMA - Mesa Adaptive Moving Average](MAMA.md "MAMA - Mesa Adaptive Moving Average") \ No newline at end of file diff --git a/docs/crossovers.ipynb b/docs/crossovers.ipynb deleted file mode 100644 index 1a8821f6..00000000 --- a/docs/crossovers.ipynb +++ /dev/null @@ -1,149 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 11, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "#r \"nuget: QuanTAlib;\"\n", - "#r \"nuget: Plotly.NET;\"\n", - "#r \"nuget: Plotly.NET.Interactive;\"\n", - "\n", - "using QuanTAlib;\n", - "using Plotly.NET;\n", - "using Plotly.NET.LayoutObjects;\n" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [], - "source": [ - "String Sym = \"IBM\";\n", - "Alphavantage_Feed data = new(Symbol: Sym);\n", - "ZLEMA_Series calc1 = new(data.OHLC4,20);\n", - "HMA_Series calc2 = new(data.OHLC4,20);\n", - "HEMA_Series calc3 = new(data.OHLC4,20);" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "
\r\n", - "\r\n", - "\n", - " \n", - "
\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "var layout = Layout.init( \n", - " PlotBGColor : Color.fromString(\"#1e1e1e\"),\n", - " PaperBGColor : Color.fromString(\"#1e1e1e\"),\n", - " Font:Font.init(Size:10, Color: Color.fromString(\"#ffffff\")));\n", - "\n", - "var yAxis = LinearAxis.init(\n", - " GridColor:Color.fromString(\"#252525\")); \n", - "\n", - "var candles = Chart2D.Chart.Candlestick(data.Open.v, data.High.v, data.Low.v, data.Close.v, data.Open.t, \"\");\n", - "var line1 = Chart2D.Chart.Line(calc1.t, calc1.v, false, calc1.GetType().Name).WithLineStyle(Width: 2, Color: Color.fromString(\"yellow\"));\n", - "var line2 = Chart2D.Chart.Line(calc2.t, calc2.v, false, calc2.GetType().Name).WithLineStyle(Width: 3, Color: Color.fromString(\"red\"));\n", - "var line3 = Chart2D.Chart.Line(calc3.t, calc3.v, false, calc3.GetType().Name).WithLineStyle(Width: 2, Color: Color.fromString(\"blue\"));\n", - "var chart = Chart.Combine(new []{candles, line1, line2, line3})\n", - " .WithSize(1200,600)\n", - " .WithMargin(Margin.init(30,10,40,30,1,false))\n", - " .WithXAxisRangeSlider(RangeSlider.init(Visible:false))\n", - " .WithYAxis(yAxis)\n", - " .WithXAxis(yAxis)\n", - " .WithTitle(Sym)\n", - " .WithLayout(layout);\n", - "\n", - "chart" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": ".NET (C#)", - "language": "C#", - "name": ".net-csharp" - }, - "language_info": { - "file_extension": ".cs", - "mimetype": "text/x-csharp", - "name": "C#", - "pygments_lexer": "csharp", - "version": "9.0" - }, - "orig_nbformat": 4 - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/docs/getting_started.ipynb b/docs/getting_started.ipynb index ede92014..bf8c469c 100644 --- a/docs/getting_started.ipynb +++ b/docs/getting_started.ipynb @@ -2,7 +2,14 @@ "cells": [ { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, "source": [ "# Quick Start\n", "\n", @@ -17,35 +24,16 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" }, "vscode": { - "languageId": "dotnet-interactive.csharp" + "languageId": "polyglot-notebook" } }, - "outputs": [ - { - "data": { - "text/html": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "ename": "Error", - "evalue": "(3,1): error CS0246: The type or namespace name 'Yahoo_Feed' could not be found (are you missing a using directive or an assembly reference?)\r\n(10,15): error CS0019: Operator '<' cannot be applied to operands of type 'int' and 'method group'", - "output_type": "error", - "traceback": [ - "(3,1): error CS0246: The type or namespace name 'Yahoo_Feed' could not be found (are you missing a using directive or an assembly reference?)\r\n", - "(10,15): error CS0019: Operator '<' cannot be applied to operands of type 'int' and 'method group'" - ] - } - ], + "outputs": [], "source": [ "#r \"nuget:QuanTAlib;\"\n", "using QuanTAlib;\n", @@ -63,7 +51,14 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, "source": [ "## Understanding QuanTAlib data model\n", "\n", @@ -72,26 +67,16 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" }, "vscode": { - "languageId": "dotnet-interactive.csharp" + "languageId": "polyglot-notebook" } }, - "outputs": [ - { - "data": { - "text/html": [ - "
indexItem1Item2
02022-11-10 00:00:00Z
105.3
12022-11-10 15:47:46Z
293.1
22022-11-10 15:47:46Z
0
32022-11-07 15:47:46Z
10
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "var item1 = (DateTime.Today, 105.3); // (DateTime, Value) tuple\n", "double item2 = 293.1; // a simple double\n", @@ -107,66 +92,60 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, "source": [ "TSeries list can display only values (without timestamps) or only timestamps (without values) by using `.v` or `.t` properties" ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" }, "vscode": { - "languageId": "dotnet-interactive.csharp" + "languageId": "polyglot-notebook" } }, - "outputs": [ - { - "data": { - "text/html": [ - "
indexvalue
0
105.3
1
293.1
2
0
3
10
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "data.v" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, "source": [ "The last element on the list can be accessed by .Last() or by [^1] - and using `.t` (time) and `.v` (value) properties. Also, casting a TSeries into (double) will return the value of the last element" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" }, "vscode": { - "languageId": "dotnet-interactive.csharp" + "languageId": "polyglot-notebook" } }, - "outputs": [ - { - "data": { - "text/html": [ - "
10
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "bool IsTheSame = data.Last().v == data[^1].v;\n", "double lastvalue = data;\n", @@ -176,33 +155,30 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, "source": [ "All indicators are just modified TSeries classes; they get all required input during class construction (source of the datafeed, period...) and they automatically subscribe to events of the datafeed. Whenever datafeed gets a new value, indicator will calculate its own value. Indicators are also event publishers, so other indicators can subscribe to their results, chaining indicators together:" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" }, "vscode": { - "languageId": "dotnet-interactive.csharp" + "languageId": "polyglot-notebook" } }, - "outputs": [ - { - "data": { - "text/html": [ - "
indexvalue
0
Infinity
1
0.6666666666666666
2
0.3333333333333333
3
0.2
4
0.14285714285714285
5
0.1111111111111111
6
0.09090909090909091
7
0.07692307692307693
8
0.06666666666666667
9
0.058823529411764705
10
0.25
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "TSeries t1 = new() {0,1,2,3,4,5,6,7,8,9}; // t1 is loaded with data and activated as a publisher\n", "EMA_Series t2 = new(t1, 3); // t2 will auto-load all history of t1 and wait for events from t1\n", @@ -218,7 +194,14 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, "source": [ "# MACD compounded indicator\n", "\n", @@ -227,26 +210,16 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" }, "vscode": { - "languageId": "dotnet-interactive.csharp" + "languageId": "polyglot-notebook" } }, - "outputs": [ - { - "data": { - "text/html": [ - "
indexvalue
0
0
1
0
2
0
3
0
4
0
5
0
6
0
7
0
8
0
9
0
10
0
11
0
12
0.13543589743590018
13
-0.03897954353340993
14
-0.17731008431411102
15
-0.24030671152304095
16
-0.08247055673614988
17
-0.47898448490240814
18
-0.9020715041856615
19
-1.3489730137363423
(51 more)
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "Yahoo_Feed aapl = new(\"AAPL\", 100);\n", "TSeries close = aapl.Close; // close will get data from history\n", @@ -266,14 +239,33 @@ "language": "C#", "name": ".net-csharp" }, - "language_info": { - "file_extension": ".cs", - "mimetype": "text/x-csharp", - "name": "C#", - "pygments_lexer": "csharp", - "version": "9.0" - }, - "orig_nbformat": 4 + "polyglot_notebook": { + "kernelInfo": { + "defaultKernelName": "csharp", + "items": [ + { + "aliases": [ + "c#", + "C#" + ], + "languageName": "C#", + "name": "csharp" + }, + { + "aliases": [ + "frontend" + ], + "languageName": null, + "name": "vscode" + }, + { + "aliases": [], + "languageName": "KQL", + "name": "kql" + } + ] + } + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/img/EMA_chart.ipynb b/docs/img/EMA_chart.ipynb new file mode 100644 index 00000000..356c0acf --- /dev/null +++ b/docs/img/EMA_chart.ipynb @@ -0,0 +1,251 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Loading extensions from `C:\\Users\\miha\\.nuget\\packages\\plotly.net.interactive\\3.0.2\\interactive-extensions\\dotnet\\Plotly.NET.Interactive.dll`" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "//#r \"nuget: QuanTAlib;\"\n", + "\n", + "#r \"nuget: Plotly.NET;\"\n", + "#r \"nuget: Plotly.NET.Interactive;\"\n", + "#r \"nuget: Plotly.NET.ImageExport;\"\n", + "#r \"..\\..\\Source\\bin\\Debug\\net6.0\\QuanTAlib.dll\"\n", + "\n", + "using QuanTAlib;\n", + "using Plotly.NET;\n", + "using Plotly.NET.LayoutObjects;\n", + "using Plotly.NET.ImageExport;" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [], + "source": [ + "TSeries d1a = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};\n", + "TSeries d2a = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};\n", + "TSeries d3a = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};\n", + "TSeries d4a = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2};\n", + "TSeries d5a = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0.32,0.56,0.72,0.84,0.93,0.99,1,0.97,0.91,0.81,0.68,0.52,0.33,0.14,-0.06,-0.26,-0.44,-0.61,-0.76,-0.87,-0.95,-0.99,-1,-0.96,-0.88,-0.77,-0.63,-0.46,-0.28,-0.08,0.12,0.31,0.49,0.66,0.79,0.9,0.97,1,0.99,0.94,0.85,0.73,0.58,0.41,0.22,0.02,-0.17,-0.37,-0.54,-0.7,-0.83,-0.92,-0.98,-1,-0.98,-0.92,-0.82,-0.69,-0.54,-0.36,-0.17,0.03,0.23,0.42,0.59,0.74};\n", + "TSeries d6a = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1};\n", + "TSeries d7a = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0.93,0.27,-0.59,-1,-0.71,0.05,0.75,1,0.67,0,-0.67,-0.99,-0.85,-0.34,0.31,0.81,1,0.82,0.35,-0.22,-0.71,-0.98,-0.95,-0.66,-0.2,0.31,0.72,0.96,0.98,0.78,0.43,-0.01,-0.43,-0.77,-0.96,-0.99,-0.85,-0.58,-0.23,0.16,0.51,0.79,0.95,1,0.92,0.73,0.47,0.15,-0.17,-0.47,-0.72,-0.9,-0.99,-0.99,-0.9,-0.74,-0.52,-0.26,0.01,0.28,0.53,0.73,0.88,0.97,1,0.97};\n", + "TSeries d8a = new() {-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,0.03,-0.4,-0.47,0.19,-0.4,-0.23,0.31,0.41,0.19,0.16,-0.5,-0.31,-0.21,0.25,0.18,-0.48,-0.1,0.38,0.29,-0.38,-0.08,-0.21,0.34,0.01,-0.46,0.28,-0.48,0.11,0.02,-0.37,0.19,-0.2,0.1,0.24,0.08,-0.22,-0.12,0.15,0.36,-0.43,-0.03,-0.32,0.45,-0.5,-0.04,-0.04,-0.08,-0.18,0.13,-0.33,-0.19,0.36,-0.39,0.2,-0.31,0.28,-0.13,-0.07,-0.29,0.37,0.03,-0.25,-0.06,-0.3,-0.08,-0.09};\n", + "TSeries d9a = new() {-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,0,0.03,0.11,-0.1,-0.43,-0.08,0.36,-0.04,-0.04,-0.21,-0.3,0.26,0.2,0.28,0.2,0.27,-0.01,-0.1,-0.23,-0.13,-0.41,-0.23,-0.07,-0.21,0.32,-0.18,-0.48,0.3,0.46,-0.2,0.52,-0.81,-0.25,-0.21,-0.12,-0.18,0.18,0.52,0.29,0.44,0.18,-1.2,0.38,0.24,0.06,0.28,0.34,0.3,-0.13,0.19,-0.5,0.59,-0.36,0.22,-0.23,0.24,0.39,0.13,-0.33,-0.57,-0.23,0.49,-0.13,0.76,0.59,0.61};\n", + "TSeries d10a = new() {-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0,-0.28,0.41,-0.54,0.65,-0.75,0.84,-0.91,0.96,-0.99,1,-0.99,0.96,-0.92,0.85,-0.77,0.67,-0.56,0.44,-0.3,0.17,-0.03,-0.11,0.25,-0.39,0.51,-0.63,0.73,-0.82,0.89,-0.95,0.98,-1,0.99,-0.97,0.93,-0.86,0.78,-0.69,0.58,-0.46,0.33,-0.19,0.05,0.09,-0.23,0.36,-0.49,0.61,-0.71,0.81,-0.88,0.94,-0.98,1,-1,0.98,-0.94,0.88,-0.8,0.71,-0.6,0.48,-0.35,0.22,-0.08,-0.06};\n", + "TSeries d11a = new() {-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,0,0.14,-0.76,-0.96,-0.28,0.66,0.99,0.41,-0.54,-1,-0.54,0.42,0.99,0.65,-0.29,-0.96,-0.75,0.15,0.91,0.84,-0.01,-0.85,-0.91,-0.13,0.76,0.96,0.27,-0.66,-0.99,-0.4,0.55,1,0.53,-0.43,-0.99,-0.64,0.3,0.96,0.75,-0.16,-0.92,-0.83,0.02,0.85,0.9,0.12,-0.77,-0.95,-0.26,0.67,0.99,0.4,-0.56,-1,-0.52,0.44,0.99,0.64,-0.3,-0.97,-0.74,0.17,0.92,0.83,-0.03,-0.86};\n", + "TSeries d12a = new() {-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0,0,0.05,-0.25,-0.32,-0.09,0.22,0.33,0.14,-0.18,-0.33,-0.18,0.14,0.33,0.22,-0.1,-0.32,-0.25,0.05,0.3,0.28,0,-0.28,-0.3,-0.04,0.25,0.32,0.09,-0.22,-0.33,-0.13,0.18,0.33,0.18,0.86,0.67,0.79,1.1,1.32,1.25,0.95,0.69,0.72,1.01,1.28,1.3,1.04,0.74,0.68,0.91,1.22,1.33,1.13,0.81,0.67,0.83,1.15,1.33,1.21,0.9,0.68,0.75,1.06,1.31,1.28,0.99,0.71};\n", + "TSeries d13a = new() {-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0,0,2.7,-0.8,-0.8,3.6,9.3,11.95,10.05,6.3,5,8.3,14.1,17.95,17.25,13.55,11.2,13.25,18.75,23.55,24.2,20.95,17.75,18.45,23.35,28.8,30.8,28.35,24.7,24.05,28,33.75,37,35.65,31.85,28.05,-3.2,1.5,4.8,3.75,-0.8,-4.6,-4.15,0.1,4.25,4.5,0.6,-3.85,-4.75,-1.3,3.35,4.95,2,-2.8,-5,-2.6,2.2,4.95,3.2,-1.5,-4.85,-3.7,0.85,4.6,4.15,-0.15,-4.3};\n", + "TSeries d14a = new() {-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0,0,0.59,0.83,0.74,0.5,0.91,1.36,0.93,0.87,0.6,0.38,0.78,0.53,0.42,0.14,0.01,-0.45,-0.71,-0.99,-1,-1.36,-1.22,-1.07,-1.17,-0.56,-0.95,-1.11,-0.16,0.18,-0.28,0.64,-0.5,0.24,0.45,0.67,0.72,1.15,1.52,1.28,1.38,1.03,-0.47,0.96,0.65,0.28,0.3,0.17,-0.07,-0.67,-0.51,-1.33,-0.33,-1.34,-0.78,-1.21,-0.68,-0.43,-0.56,-0.87,-0.93,-0.4,0.52,0.1,1.18,1.18,1.35};\n", + "TSeries d15a = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,1.3,0.3,-0.48,-1.1,-1.14,-0.03,1.11,0.96,0.63,-0.21,-0.97,-0.73,-0.65,-0.06,0.51,1.08,0.99,0.72,0.12,-0.35,-1.12,-1.21,-1.02,-0.87,0.12,0.13,0.24,1.26,1.44,0.58,0.95,-0.82,-0.68,-0.98,-1.08,-1.17,-0.67,-0.06,0.06,0.6,0.69,-0.41,1.33,1.24,0.98,1.01,0.81,0.45,-0.3,-0.28,-1.22,-0.31,-1.35,-0.77,-1.13,-0.5,-0.13,-0.13,-0.32,-0.29,0.3,1.22,0.75,1.73,1.59,1.58};\n", + "TSeries d16a = new() {175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.44,176.27,176.04,176.99,175.49,175.68,174.34,176.4,174.05,174.4,174.2,176.16,175,177.72,174.33,176.96,174.62,174.76,170.9,171.12,171.05,170.01,169.24,172.64,171.96,175.72,174.16,175.81,177.3,178.38,176.75,177.19,175.55,178.49,176.52,178.45,178.04,178.25,177.8,176.97,172.94,174.92,173.98,172.29,171.19,172.54,172.11,175.32,175.63,176.65,173.8,176.04,172.74,175.24,171.84,171.54,172.17,171.85,172.38,170.78,173.49,173.69,171.71,174.38,173.99,174.83};" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [], + "source": [ + "int period = 10;\n", + "int cut = 26;\n", + "\n", + "EMA_Series d1b = new(d1a, period);\n", + "EMA_Series d2b = new(d2a, period);\n", + "EMA_Series d3b = new(d3a, period);\n", + "EMA_Series d4b = new(d4a, period);\n", + "EMA_Series d5b = new(d5a, period);\n", + "EMA_Series d6b = new(d6a, period);\n", + "EMA_Series d7b = new(d7a, period);\n", + "EMA_Series d8b = new(d8a, period);\n", + "EMA_Series d9b = new(d9a, period);\n", + "EMA_Series d10b = new(d10a, period);\n", + "EMA_Series d11b = new(d11a, period);\n", + "EMA_Series d12b = new(d12a, period);\n", + "EMA_Series d13b = new(d13a, period);\n", + "EMA_Series d14b = new(d14a, period);\n", + "EMA_Series d15b = new(d15a, period);\n", + "EMA_Series d16b = new(d16a, period);\n", + "\n", + "List x = Enumerable.Range(-cut,96).ToList();\n", + "GenericChart.GenericChart ch1a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d1a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch1b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d1b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch2a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d2a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch2b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d2b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch3a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d3a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch3b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d3b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch4a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d4a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch4b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d4b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch5a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d5a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch5b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d5b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch6a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d6a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch6b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d6b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch7a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d7a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch7b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d7b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch8a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d8a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch8b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d8b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch9a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d9a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch9b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d9b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch10a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d10a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch10b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d10b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch11a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d11a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch11b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d11b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch12a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d12a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch12b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d12b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch13a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d13a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch13b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d13b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch14a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d14a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch14b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d14b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch15a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d15a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch15b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d15b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch16a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d16a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch16b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d16b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "\n", + "var ch1 = Chart.Combine(new []{ch1a,ch1b});\n", + "var ch2 = Chart.Combine(new []{ch2a,ch2b});\n", + "var ch3 = Chart.Combine(new []{ch3a,ch3b});\n", + "var ch4 = Chart.Combine(new []{ch4a,ch4b});\n", + "var ch5 = Chart.Combine(new []{ch5a,ch5b});\n", + "var ch6 = Chart.Combine(new []{ch6a,ch6b});\n", + "var ch7 = Chart.Combine(new []{ch7a,ch7b});\n", + "var ch8 = Chart.Combine(new []{ch8a,ch8b});\n", + "var ch9 = Chart.Combine(new []{ch9a,ch9b});\n", + "var ch10 = Chart.Combine(new []{ch10a,ch10b});\n", + "var ch11 = Chart.Combine(new []{ch11a,ch11b});\n", + "var ch12 = Chart.Combine(new []{ch12a,ch12b});\n", + "var ch13 = Chart.Combine(new []{ch13a,ch13b});\n", + "var ch14 = Chart.Combine(new []{ch14a,ch14b});\n", + "var ch15 = Chart.Combine(new []{ch15a,ch15b});\n", + "var ch16 = Chart.Combine(new []{ch16a,ch16b});\n", + "\n", + "Layout layout = new Layout(); layout.SetValue(\"showlegend\",false);\n", + "var chart1 = new []{ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8,ch9,ch10,ch11,ch12,ch13,ch14,ch15,ch16};\n", + "var full = Chart.Grid>(8,2).Invoke(chart1).WithSize(1000,2200).WithMargin(Margin.init(30,20,20,30,7,false)).WithLayout(layout);\n", + "full.SaveSVG(\"EMA_chart\", Width: 1000, Height: 2200);" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".NET (C#)", + "language": "C#", + "name": ".net-csharp" + }, + "polyglot_notebook": { + "kernelInfo": { + "defaultKernelName": "csharp", + "items": [ + { + "aliases": [ + "c#", + "C#" + ], + "languageName": "C#", + "name": "csharp" + }, + { + "aliases": [], + "name": ".NET" + }, + { + "aliases": [ + "f#", + "F#" + ], + "languageName": "F#", + "name": "fsharp" + }, + { + "aliases": [], + "languageName": "HTML", + "name": "html" + }, + { + "aliases": [], + "languageName": "KQL", + "name": "kql" + }, + { + "aliases": [], + "languageName": "Mermaid", + "name": "mermaid" + }, + { + "aliases": [ + "powershell" + ], + "languageName": "PowerShell", + "name": "pwsh" + }, + { + "aliases": [], + "languageName": "SQL", + "name": "sql" + }, + { + "aliases": [], + "name": "value" + }, + { + "aliases": [ + "frontend" + ], + "name": "vscode" + }, + { + "aliases": [ + "js" + ], + "languageName": "JavaScript", + "name": "javascript" + }, + { + "aliases": [], + "name": "webview" + } + ] + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/docs/img/EMA_chart.svg b/docs/img/EMA_chart.svg new file mode 100644 index 00000000..1ac712b9 --- /dev/null +++ b/docs/img/EMA_chart.svg @@ -0,0 +1 @@ +020406000.20.40.60.81020406000.20.40.60.8102040600102030020406001020300204060−1−0.500.510204060−1−0.500.510204060−1−0.500.510204060−0.4−0.200.20.40204060−1−0.500.50204060−1−0.500.510204060−1−0.500.51020406000.51020406001020300204060−1010204060−1010204060170172174176178 \ No newline at end of file diff --git a/docs/img/SMA_chart.ipynb b/docs/img/SMA_chart.ipynb new file mode 100644 index 00000000..3f10a68a --- /dev/null +++ b/docs/img/SMA_chart.ipynb @@ -0,0 +1,242 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "//#r \"nuget: QuanTAlib;\"\n", + "\n", + "#r \"nuget: Plotly.NET;\"\n", + "#r \"nuget: Plotly.NET.Interactive;\"\n", + "#r \"nuget: Plotly.NET.ImageExport;\"\n", + "#r \"..\\..\\Source\\bin\\Debug\\net6.0\\QuanTAlib.dll\"\n", + "\n", + "using QuanTAlib;\n", + "using Plotly.NET;\n", + "using Plotly.NET.LayoutObjects;\n", + "using Plotly.NET.ImageExport;" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [], + "source": [ + "TSeries d1a = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};\n", + "TSeries d2a = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};\n", + "TSeries d3a = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};\n", + "TSeries d4a = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2};\n", + "TSeries d5a = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0.32,0.56,0.72,0.84,0.93,0.99,1,0.97,0.91,0.81,0.68,0.52,0.33,0.14,-0.06,-0.26,-0.44,-0.61,-0.76,-0.87,-0.95,-0.99,-1,-0.96,-0.88,-0.77,-0.63,-0.46,-0.28,-0.08,0.12,0.31,0.49,0.66,0.79,0.9,0.97,1,0.99,0.94,0.85,0.73,0.58,0.41,0.22,0.02,-0.17,-0.37,-0.54,-0.7,-0.83,-0.92,-0.98,-1,-0.98,-0.92,-0.82,-0.69,-0.54,-0.36,-0.17,0.03,0.23,0.42,0.59,0.74};\n", + "TSeries d6a = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1};\n", + "TSeries d7a = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0.93,0.27,-0.59,-1,-0.71,0.05,0.75,1,0.67,0,-0.67,-0.99,-0.85,-0.34,0.31,0.81,1,0.82,0.35,-0.22,-0.71,-0.98,-0.95,-0.66,-0.2,0.31,0.72,0.96,0.98,0.78,0.43,-0.01,-0.43,-0.77,-0.96,-0.99,-0.85,-0.58,-0.23,0.16,0.51,0.79,0.95,1,0.92,0.73,0.47,0.15,-0.17,-0.47,-0.72,-0.9,-0.99,-0.99,-0.9,-0.74,-0.52,-0.26,0.01,0.28,0.53,0.73,0.88,0.97,1,0.97};\n", + "TSeries d8a = new() {-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,0.03,-0.4,-0.47,0.19,-0.4,-0.23,0.31,0.41,0.19,0.16,-0.5,-0.31,-0.21,0.25,0.18,-0.48,-0.1,0.38,0.29,-0.38,-0.08,-0.21,0.34,0.01,-0.46,0.28,-0.48,0.11,0.02,-0.37,0.19,-0.2,0.1,0.24,0.08,-0.22,-0.12,0.15,0.36,-0.43,-0.03,-0.32,0.45,-0.5,-0.04,-0.04,-0.08,-0.18,0.13,-0.33,-0.19,0.36,-0.39,0.2,-0.31,0.28,-0.13,-0.07,-0.29,0.37,0.03,-0.25,-0.06,-0.3,-0.08,-0.09};\n", + "TSeries d9a = new() {-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,0,0.03,0.11,-0.1,-0.43,-0.08,0.36,-0.04,-0.04,-0.21,-0.3,0.26,0.2,0.28,0.2,0.27,-0.01,-0.1,-0.23,-0.13,-0.41,-0.23,-0.07,-0.21,0.32,-0.18,-0.48,0.3,0.46,-0.2,0.52,-0.81,-0.25,-0.21,-0.12,-0.18,0.18,0.52,0.29,0.44,0.18,-1.2,0.38,0.24,0.06,0.28,0.34,0.3,-0.13,0.19,-0.5,0.59,-0.36,0.22,-0.23,0.24,0.39,0.13,-0.33,-0.57,-0.23,0.49,-0.13,0.76,0.59,0.61};\n", + "TSeries d10a = new() {-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0,-0.28,0.41,-0.54,0.65,-0.75,0.84,-0.91,0.96,-0.99,1,-0.99,0.96,-0.92,0.85,-0.77,0.67,-0.56,0.44,-0.3,0.17,-0.03,-0.11,0.25,-0.39,0.51,-0.63,0.73,-0.82,0.89,-0.95,0.98,-1,0.99,-0.97,0.93,-0.86,0.78,-0.69,0.58,-0.46,0.33,-0.19,0.05,0.09,-0.23,0.36,-0.49,0.61,-0.71,0.81,-0.88,0.94,-0.98,1,-1,0.98,-0.94,0.88,-0.8,0.71,-0.6,0.48,-0.35,0.22,-0.08,-0.06};\n", + "TSeries d11a = new() {-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,0,0.14,-0.76,-0.96,-0.28,0.66,0.99,0.41,-0.54,-1,-0.54,0.42,0.99,0.65,-0.29,-0.96,-0.75,0.15,0.91,0.84,-0.01,-0.85,-0.91,-0.13,0.76,0.96,0.27,-0.66,-0.99,-0.4,0.55,1,0.53,-0.43,-0.99,-0.64,0.3,0.96,0.75,-0.16,-0.92,-0.83,0.02,0.85,0.9,0.12,-0.77,-0.95,-0.26,0.67,0.99,0.4,-0.56,-1,-0.52,0.44,0.99,0.64,-0.3,-0.97,-0.74,0.17,0.92,0.83,-0.03,-0.86};\n", + "TSeries d12a = new() {-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0,0,0.05,-0.25,-0.32,-0.09,0.22,0.33,0.14,-0.18,-0.33,-0.18,0.14,0.33,0.22,-0.1,-0.32,-0.25,0.05,0.3,0.28,0,-0.28,-0.3,-0.04,0.25,0.32,0.09,-0.22,-0.33,-0.13,0.18,0.33,0.18,0.86,0.67,0.79,1.1,1.32,1.25,0.95,0.69,0.72,1.01,1.28,1.3,1.04,0.74,0.68,0.91,1.22,1.33,1.13,0.81,0.67,0.83,1.15,1.33,1.21,0.9,0.68,0.75,1.06,1.31,1.28,0.99,0.71};\n", + "TSeries d13a = new() {-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0,0,2.7,-0.8,-0.8,3.6,9.3,11.95,10.05,6.3,5,8.3,14.1,17.95,17.25,13.55,11.2,13.25,18.75,23.55,24.2,20.95,17.75,18.45,23.35,28.8,30.8,28.35,24.7,24.05,28,33.75,37,35.65,31.85,28.05,-3.2,1.5,4.8,3.75,-0.8,-4.6,-4.15,0.1,4.25,4.5,0.6,-3.85,-4.75,-1.3,3.35,4.95,2,-2.8,-5,-2.6,2.2,4.95,3.2,-1.5,-4.85,-3.7,0.85,4.6,4.15,-0.15,-4.3};\n", + "TSeries d14a = new() {-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0,0,0.59,0.83,0.74,0.5,0.91,1.36,0.93,0.87,0.6,0.38,0.78,0.53,0.42,0.14,0.01,-0.45,-0.71,-0.99,-1,-1.36,-1.22,-1.07,-1.17,-0.56,-0.95,-1.11,-0.16,0.18,-0.28,0.64,-0.5,0.24,0.45,0.67,0.72,1.15,1.52,1.28,1.38,1.03,-0.47,0.96,0.65,0.28,0.3,0.17,-0.07,-0.67,-0.51,-1.33,-0.33,-1.34,-0.78,-1.21,-0.68,-0.43,-0.56,-0.87,-0.93,-0.4,0.52,0.1,1.18,1.18,1.35};\n", + "TSeries d15a = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,1.3,0.3,-0.48,-1.1,-1.14,-0.03,1.11,0.96,0.63,-0.21,-0.97,-0.73,-0.65,-0.06,0.51,1.08,0.99,0.72,0.12,-0.35,-1.12,-1.21,-1.02,-0.87,0.12,0.13,0.24,1.26,1.44,0.58,0.95,-0.82,-0.68,-0.98,-1.08,-1.17,-0.67,-0.06,0.06,0.6,0.69,-0.41,1.33,1.24,0.98,1.01,0.81,0.45,-0.3,-0.28,-1.22,-0.31,-1.35,-0.77,-1.13,-0.5,-0.13,-0.13,-0.32,-0.29,0.3,1.22,0.75,1.73,1.59,1.58};\n", + "TSeries d16a = new() {175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.44,176.27,176.04,176.99,175.49,175.68,174.34,176.4,174.05,174.4,174.2,176.16,175,177.72,174.33,176.96,174.62,174.76,170.9,171.12,171.05,170.01,169.24,172.64,171.96,175.72,174.16,175.81,177.3,178.38,176.75,177.19,175.55,178.49,176.52,178.45,178.04,178.25,177.8,176.97,172.94,174.92,173.98,172.29,171.19,172.54,172.11,175.32,175.63,176.65,173.8,176.04,172.74,175.24,171.84,171.54,172.17,171.85,172.38,170.78,173.49,173.69,171.71,174.38,173.99,174.83};" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [], + "source": [ + "int period = 10;\n", + "int cut = 26;\n", + "\n", + "SMA_Series d1b = new(d1a, period);\n", + "SMA_Series d2b = new(d2a, period);\n", + "SMA_Series d3b = new(d3a, period);\n", + "SMA_Series d4b = new(d4a, period);\n", + "SMA_Series d5b = new(d5a, period);\n", + "SMA_Series d6b = new(d6a, period);\n", + "SMA_Series d7b = new(d7a, period);\n", + "SMA_Series d8b = new(d8a, period);\n", + "SMA_Series d9b = new(d9a, period);\n", + "SMA_Series d10b = new(d10a, period);\n", + "SMA_Series d11b = new(d11a, period);\n", + "SMA_Series d12b = new(d12a, period);\n", + "SMA_Series d13b = new(d13a, period);\n", + "SMA_Series d14b = new(d14a, period);\n", + "SMA_Series d15b = new(d15a, period);\n", + "SMA_Series d16b = new(d16a, period);\n", + "\n", + "List x = Enumerable.Range(-cut,96).ToList();\n", + "GenericChart.GenericChart ch1a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d1a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch1b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d1b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch2a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d2a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch2b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d2b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch3a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d3a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch3b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d3b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch4a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d4a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch4b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d4b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch5a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d5a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch5b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d5b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch6a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d6a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch6b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d6b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch7a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d7a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch7b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d7b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch8a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d8a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch8b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d8b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch9a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d9a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch9b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d9b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch10a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d10a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch10b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d10b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch11a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d11a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch11b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d11b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch12a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d12a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch12b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d12b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch13a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d13a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch13b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d13b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch14a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d14a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch14b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d14b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch15a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d15a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch15b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d15b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "GenericChart.GenericChart ch16a = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d16a.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", + "GenericChart.GenericChart ch16b = Chart2D.Chart.Line(x.GetRange(cut,96-cut),d16b.v.GetRange(cut,96-cut),false,\"\").WithLineStyle(Width: 2.5, Color: Color.fromString(\"red\"));\n", + "\n", + "var ch1 = Chart.Combine(new []{ch1a,ch1b});\n", + "var ch2 = Chart.Combine(new []{ch2a,ch2b});\n", + "var ch3 = Chart.Combine(new []{ch3a,ch3b});\n", + "var ch4 = Chart.Combine(new []{ch4a,ch4b});\n", + "var ch5 = Chart.Combine(new []{ch5a,ch5b});\n", + "var ch6 = Chart.Combine(new []{ch6a,ch6b});\n", + "var ch7 = Chart.Combine(new []{ch7a,ch7b});\n", + "var ch8 = Chart.Combine(new []{ch8a,ch8b});\n", + "var ch9 = Chart.Combine(new []{ch9a,ch9b});\n", + "var ch10 = Chart.Combine(new []{ch10a,ch10b});\n", + "var ch11 = Chart.Combine(new []{ch11a,ch11b});\n", + "var ch12 = Chart.Combine(new []{ch12a,ch12b});\n", + "var ch13 = Chart.Combine(new []{ch13a,ch13b});\n", + "var ch14 = Chart.Combine(new []{ch14a,ch14b});\n", + "var ch15 = Chart.Combine(new []{ch15a,ch15b});\n", + "var ch16 = Chart.Combine(new []{ch16a,ch16b});\n", + "\n", + "Layout layout = new Layout(); layout.SetValue(\"showlegend\",false);\n", + "var chart1 = new []{ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8,ch9,ch10,ch11,ch12,ch13,ch14,ch15,ch16};\n", + "var full = Chart.Grid>(8,2).Invoke(chart1).WithSize(1000,2200).WithMargin(Margin.init(30,20,20,30,7,false)).WithLayout(layout);\n", + "full.SaveSVG(\"SMA_chart\", Width: 1000, Height: 2200);" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".NET (C#)", + "language": "C#", + "name": ".net-csharp" + }, + "polyglot_notebook": { + "kernelInfo": { + "defaultKernelName": "csharp", + "items": [ + { + "aliases": [ + "c#", + "C#" + ], + "languageName": "C#", + "name": "csharp" + }, + { + "aliases": [], + "name": ".NET" + }, + { + "aliases": [ + "f#", + "F#" + ], + "languageName": "F#", + "name": "fsharp" + }, + { + "aliases": [], + "languageName": "HTML", + "name": "html" + }, + { + "aliases": [], + "languageName": "KQL", + "name": "kql" + }, + { + "aliases": [], + "languageName": "Mermaid", + "name": "mermaid" + }, + { + "aliases": [ + "powershell" + ], + "languageName": "PowerShell", + "name": "pwsh" + }, + { + "aliases": [], + "languageName": "SQL", + "name": "sql" + }, + { + "aliases": [], + "name": "value" + }, + { + "aliases": [ + "frontend" + ], + "name": "vscode" + }, + { + "aliases": [ + "js" + ], + "languageName": "JavaScript", + "name": "javascript" + }, + { + "aliases": [], + "name": "webview" + } + ] + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/docs/img/SMA_chart.svg b/docs/img/SMA_chart.svg new file mode 100644 index 00000000..543c137d --- /dev/null +++ b/docs/img/SMA_chart.svg @@ -0,0 +1 @@ +020406000.20.40.60.81020406000.20.40.60.8102040600102030020406001020300204060−1−0.500.510204060−1−0.500.510204060−1−0.500.510204060−0.4−0.200.20.40204060−1−0.500.50204060−1−0.500.510204060−1−0.500.51020406000.51020406001020300204060−1010204060−1010204060170172174176178 \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 10426a54..ae618449 100644 --- a/docs/index.html +++ b/docs/index.html @@ -6,20 +6,28 @@ - + +
- - - + + + + diff --git a/docs/indicators.md b/docs/indicators.md new file mode 100644 index 00000000..b731ba85 --- /dev/null +++ b/docs/indicators.md @@ -0,0 +1,174 @@ +# Coverage + +⭐= Calculation is validated against one or many TA libraries + +✔️= Calculation exists but has no cross-validation tests + +⛔= Not implemented (yet) + +| **BASIC TRANSFORMS** | **QuanTAlib** | **TA-LIB** | **Skender** | **Pandas TA** | **Tulip** | +|--|:--:|:--:|:--:|:--:|:--:| +| OC2 - (Open+Close)/2 |️ `.OC2` || CandlePart.OC2 || +| HL2 - Median Price | `.HL2` | MEDPRICE | CandlePart.HL2 | hl2 | +| HLC3 - Typical Price | `.HLC3` | TYPPRICE | CandlePart.HLC3 | hlc3 | +| OHL3 - (Open+High+Low)/3 | `.OHL3` || CandlePart.OHL3 || +| OHLC4 - Average Price | `.OHLC4` | AVGPRICE |️ CandlePart.OHLC4 | ohlc4 | avgprice | +| HLCC4 - Weighted Price | `.HLCC4` | WCLPRICE | CandlePart.HLCC4 || +| MIDPOINT - Midpoint value | `MIDPOINT_Series` | MIDPOINT || midpoint | +| MIDPRICE - Midpoint price | `MIDPRICE_Series` | MIDPRICE || midprice | +| MAX - Max value | `MAX_Series` | MAX ||| max | +| MIN - Min value | `MIN_Series` | MIN ||| min | +| SUM - Summation | `SUM_Series` | SUM ||| sum | +| ADD - Addition | `ADD_Series` | ADD ||| add | +| SUB - Subtraction | `SUB_Series` | SUB ||| sub | +| MUL - Multiplication | `MUL_Series` | MUL ||| mul | +| DIV - Division | `DIV_Series` | DIV ||| div | +||||| +| **STATISTICS & NUMERICAL ANALYSIS** | +|||||| +| BIAS - Bias | `BIAS_Series` ||| bias | +| CORR - Pearson's Correlation Coefficient | `CORR_Series` | CORREL | GetCorrelation || +| COVAR - Covariance | `COVAR_Series` || GetCorrelation || +| DECAY - Linear Decay ||||| decay | +| EDECAY - Exponential Decay ||||| edecay | +| ENTROPY - Entropy | `ENTROPY_Series` ||| entropy | +| KURTOSIS - Kurtosis | `KURT_Series` ||| kurtosis | +| LINREG - Linear Regression | `LINREG_Series` || GetSlope || +| MAD - Mean Absolute Deviation | `MAD_Series` || GetSma | mad | +| MAPE - Mean Absolute Percent Error | `MAPE_Series` || GetSma || +| MED - Median value | `MED_Series` ||| median | +| MSE - Mean Squared Error | `MSE_Series` || GetSma || +| SKEW - Skewness |||| skew | +| SDEV - Standard Deviation (Volatility) | `SDEV_Series` | STDDEV | GetStdDev | stdev | +| SSDEV - Sample Standard Deviation | `SSDEV_Series` ||| stdev | +| SMAPE - Symmetric Mean Absolute Percent Error | `SMAPE_Series` |||| +| VAR - Population Variance | `VAR_Series` | VAR || variance | +| SVAR - Sample Variance | `SVAR_Series` ||| variance | +| QUANTILE - Quantile |||| quantile | +| WMAPE - Weighted Mean Absolute Percent Error | `WMAPE_Series` |||| +| ZSCORE - Number of standard deviations from mean | `ZSCORE_Series` || GetStdDev | zscore | +|||||| +| **TREND INDICATORS & AVERAGES** | +|||||| +| AFIRMA - Autoregressive Finite Impulse Response Moving Average ||||| +| ALMA - Arnaud Legoux Moving Average | `ALMA_Series` || GetAlma | alma | +| ARIMA - Autoregressive Integrated Moving Average ||||| +| DEMA - Double EMA Average | `DEMA_Series` | DEMA | GetDema | dema | dema | +| EMA - Exponential Moving Average | `EMA_Series` | EMA | GetEma | ema | ema | +| EPMA - Endpoint Moving Average ||| GetEpma || +| FRAMA - Fractal Adaptive Moving Average ||||| +| FWMA - Fibonacci's Weighted Moving Average |||| fwma | +| HILO - Gann High-Low Activator |||| hilo | +| HEMA - Hull/EMA Average | `HEMA_Series` |||| +| Hilbert Transform Instantaneous Trendline || HT_TRENDLINE | GetHtTrendline || +| HMA - Hull Moving Average | `HMA_Series` || GetHma | hma | hma | +| HWMA - Holt-Winter Moving Average |||| hwma | +| JMA - Jurik Moving Average | `JMA_Series` ||| jma | +| KAMA - Kaufman's Adaptive Moving Average | `KAMA_Series` | KAMA | GetKama | kama | kama | +| KDJ - KDJ Indicator (trend reversal) |||| kdj | +| LSMA - Least Squares Moving Average ||||| +| MACD - Moving Average Convergence/Divergence | `MACD_Series` | MACD | GetMacd | macd | +| MAMA - MESA Adaptive Moving Average | `MAMA_Series` | MAMA | GetMama || +| MCGD - McGinley Dynamic |||| mcgd | +| MMA - Modified Moving Average ||||| +| PPMA - Pivot Point Moving Average ||||| +| PWMA - Pascal's Weighted Moving Average |||| pwma | +| RMA - WildeR's Moving Average | `RMA_Series` ||| rma | +| SINWMA - Sine Weighted Moving Average |||| sinwma | +| ⭐ [SMA - Simple Moving Average](SMA.md) | `SMA_Series` | ⭐ SMA | ⭐ GetSma | ⭐ sma | ⭐ sma | +| SMMA - Smoothed Moving Average | `SMMA_Series` || GetSmma || +| SSF - Ehler's Super Smoother Filter |||| ssf | +| SUPERTREND - Supertrend |||| supertrend | +| SWMA - Symmetric Weighted Moving Average |||| swma | +| T3 - Tillson T3 Moving Average | `T3_Series` | T3 | GetT3 | t3 | +| TEMA - Triple EMA Average | `TEMA_Series` | TEMA | GetTema | tema | +| TRIMA - Triangular Moving Average | `TRIMA_Series` | TRIMA || trima | +| TSF - Time Series Forecast || TSF ||| +| VIDYA - Variable Index Dynamic Average |||| vidya | +| VORTEX - Vortex Indicator |||| vortex | +| WMA - Weighted Moving Average | `WMA_Series` | WMA | GetWma | wma | +| ZLEMA - Zero Lag EMA Average | `ZLEMA_Series` ||| zlma | +|||||| +| **VOLATILITY INDICATORS** | +|||||| +| ADL - Chaikin Accumulation Distribution Line | `ADL_Series` | AD | GetAdl | ad | ad | +| ADOSC - Chaikin Accumulation Distribution Oscillator | `ADOSC_Series` | ADOSC| GetAdl | adosc | adosc | +| ATR - Average True Range | `ATR_Series` | ATR | GetAtr | atr | atr | +| ATRP - Average True Range Percent | `ATRP_Series` || GetAtr || +| BETA - Beta coefficient || BETA | GetBeta || +| BBANDS - Bollinger Bands® | `BBANDS_Series` | BBANDS | GetBollingerBands || bbands | +| CHAND - Chandelier Exit ||| GetChandelier || +| CRSI - Connor RSI ||| GetConnorsRsi || +| CVI - Chaikins Volatility ||||| cvi | +| DON - Donchian Channels ||| GetDonchian || +| FCB - Fractal Chaos Bands ||| GetFcb || +| FISHER - Fisher Transform ||| GetFcb || fisher | +| HV - Historical Volatility ||||| +| ICH - Ichimoku ||| GetIchimoku || +| KEL - Keltner Channels ||| GetKeltner || +| NATR - Normalized Average True Range || NATR | GetAtr || +| CHN - Price Channel Indicator ||||| +| RSI - Relative Strength Index | `RSI_Series` | RSI | GetRsi | rsi | +| SAR - Parabolic Stop and Reverse || SAR | GetParabolicSar || +| SRSI - Stochastic RSI || STOCHRSI | GetStochRsi || +| STARC - Starc Bands ||||| +| TR - True Range | `TR_Series` | TRANGE | GetTr | true_range | +| UI - Ulcer Index ||||| +| VSTOP - Volatility Stop ||||| +|||||| +| **MOMENTUM INDICATORS & OSCILLATORS** | +|||||| +| AC - Acceleration Oscillator ||||| +| ADX - Average Directional Movement Index || ADX | GetAdx || adx | +| ADXR - Average Directional Movement Index Rating || ADXR | GetAdx || adxr | +| AO - Awesome Oscillator ||| GetAwesome || ao | +| APO - Absolute Price Oscillator || APO ||| apo | +| AROON - Aroon oscillator || AROON | GetAroon || aroon | +| BOP - Balance of Power || BOP | GetBop || bop | +| CCI - Commodity Channel Index | `CCI_Series` | CCI | GetCci || cci | +| CFO - Chande Forcast Oscillator ||||| +| CMO - Chande Momentum Oscillator || CMO | GetCmo || cmo | +| COG - Center of Gravity ||||| +| COPPOCK - Coppock Curve ||||| +| CTI - Ehler's Correlation Trend Indicator ||||| +| DPO - Detrended Price Oscillator ||| GetDpo || +| DMI - Directional Movement Index || DX | GetAdx || +| EFI - Elder Ray's Force Index ||| GetElderRay || +| FOSC - Forecast oscillator ||||| fosc | +| GAT - Alligator oscillator ||| GetGator || +| HURST - Hurst Exponent ||| GetHurst || +| KRI - Kairi Relative Index ||||| +| KVO - Klinger Volume Oscillator ||||| +| MFI - Money Flow Index || MFI | GetMfi || +| MOM - Momentum || MOM ||| +| NVI - Negative Volume Index ||||| +| PO - Price Oscillator ||||| +| PPO - Percentage Price Oscillator || PPO ||| +| PMO - Price Momentum Oscillator ||||| +| PVI - Positive Volume Index ||||| +| ROC - Rate of Change || MOM | GetRoc || +| RVGI - Relative Vigor Index ||||| +| SMI - Stochastic Momentum Index ||||| +| STC - Schaff Trend Cycle ||||| +| STOCH - Stochastic Oscillator || STOCH | GetStoch || +| TRIX - 1-day ROC of TEMA || TRIX | GetTrix || +| TSI - True Strength Index ||||| +| UO - Ultimate Oscillator || ULTOSC | GetUltimate || +| WILLR - Larry Williams' %R || WILLR | GetWilliamsR || +| WGAT - Williams Alligator ||||| +|||||| +| **VOLUME INDICATORS** | +|||||| +| AOBV - Archer On-Balance Volume ||||| +| CMF - Chaikin Money Flow ||||| +| EOM - Ease of Movement ||||| emv | +| KVO - Klinger Volume Oscilaltor ||||| kvo | +| OBV - On-Balance Volume | `OBV_Series` | OBV | GetObv || +| PRS - Price Relative Strength |||| +| PVOL - Price-Volume ||||| +| PVO - Percentage Volume Oscillator ||||| +| PVR - Price Volume Rank ||||| +| PVT - Price Volume Trend ||||| +| VP - Volume Profile ||||| +| VWAP - Volume Weighted Average Price ||||| +| VWMA - Volume Weighted Moving Average ||||| diff --git a/docs/readme.md b/docs/readme.md index 224e2f64..9903a83f 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -34,28 +34,31 @@ See [Getting Started](https://github.com/mihakralj/QuanTAlib/blob/main/Docs/gett ⛔= Not implemented (yet) -| **BASIC TRANSFORMS** | **QuanTAlib** | **TA-LIB** | **Skender** | **Pandas TA** | -|--|:--:|:--:|:--:|:--:| +| **BASIC TRANSFORMS** | **QuanTAlib** | **TA-LIB** | **Skender** | **Pandas TA** | **Tulip** | +|--|:--:|:--:|:--:|:--:|:--:| | ⭐ OC2 - (Open+Close)/2 |️ `.OC2` || CandlePart.OC2 || | ⭐ HL2 - Median Price | `.HL2` | MEDPRICE | CandlePart.HL2 | hl2 | | ⭐ HLC3 - Typical Price | `.HLC3` | TYPPRICE | CandlePart.HLC3 | hlc3 | | ⭐ OHL3 - (Open+High+Low)/3 | `.OHL3` || CandlePart.OHL3 || -| ⭐ OHLC4 - Average Price | `.OHLC4` | AVGPRICE |️ CandlePart.OHLC4 | ohlc4 | +| ⭐ OHLC4 - Average Price | `.OHLC4` | AVGPRICE |️ CandlePart.OHLC4 | ohlc4 | avgprice | | ⭐ HLCC4 - Weighted Price | `.HLCC4` | WCLPRICE | CandlePart.HLCC4 || | ⭐ MIDPOINT - Midpoint value | `MIDPOINT_Series` | MIDPOINT || midpoint | | ⭐ MIDPRICE - Midpoint price | `MIDPRICE_Series` | MIDPRICE || midprice | -| ⭐ MAX - Max value | `MAX_Series` | MAX ||| -| ⭐ MIN - Min value | `MIN_Series` | MIN ||| -| ⭐ SUM - Summation | `SUM_Series` | SUM ||| -| ⭐ ADD - Addition | `ADD_Series` | ADD ||| -| ⭐ SUB - Subtraction | `SUB_Series` | SUB ||| -| ⭐ MUL - Multiplication | `MUL_Series` | MUL ||| -| ⭐ DIV - Division | `DIV_Series` | DIV ||| +| ⭐ MAX - Max value | `MAX_Series` | MAX ||| max | +| ⭐ MIN - Min value | `MIN_Series` | MIN ||| min | +| ⭐ SUM - Summation | `SUM_Series` | SUM ||| sum | +| ⭐ ADD - Addition | `ADD_Series` | ADD ||| add | +| ⭐ SUB - Subtraction | `SUB_Series` | SUB ||| sub | +| ⭐ MUL - Multiplication | `MUL_Series` | MUL ||| mul | +| ⭐ DIV - Division | `DIV_Series` | DIV ||| div | ||||| -| **STATISTICS & NUMERICAL ANALYSIS** | **QuanTAlib** | **TA-LIB** | **Skender** | **Pandas TA** | +| **STATISTICS & NUMERICAL ANALYSIS** | +|||||| | ⭐ BIAS - Bias | `BIAS_Series` ||| bias | | ⭐ CORR - Pearson's Correlation Coefficient | `CORR_Series` | CORREL | GetCorrelation || | ⭐ COVAR - Covariance | `COVAR_Series` || GetCorrelation || +| ⛔ DECAY - Linear Decay ||||| decay | +| ⛔ EDECAY - Exponential Decay ||||| edecay | | ⭐ ENTROPY - Entropy | `ENTROPY_Series` ||| entropy | | ⭐ KURTOSIS - Kurtosis | `KURT_Series` ||| kurtosis | | ⭐ LINREG - Linear Regression | `LINREG_Series` || GetSlope || @@ -73,22 +76,23 @@ See [Getting Started](https://github.com/mihakralj/QuanTAlib/blob/main/Docs/gett | ✔️ WMAPE - Weighted Mean Absolute Percent Error | `WMAPE_Series` |||| | ⭐ ZSCORE - Number of standard deviations from mean | `ZSCORE_Series` || GetStdDev | zscore | |||||| -| **TREND INDICATORS & AVERAGES** | **QuanTAlib** | **TA-LIB** | **Skender** | **Pandas TA** | +| **TREND INDICATORS & AVERAGES** | +|||||| | ⛔ AFIRMA - Autoregressive Finite Impulse Response Moving Average ||||| | ⭐ ALMA - Arnaud Legoux Moving Average | `ALMA_Series` || GetAlma | alma | | ⛔ ARIMA - Autoregressive Integrated Moving Average ||||| -| ⭐ DEMA - Double EMA Average | `DEMA_Series` | DEMA | GetDema | dema | -| ⭐ EMA - Exponential Moving Average | `EMA_Series` | EMA | GetEma | ema | +| ⭐ DEMA - Double EMA Average | `DEMA_Series` | DEMA | GetDema | dema | dema | +| ⭐ EMA - Exponential Moving Average | `EMA_Series` | EMA | GetEma | ema | ema | | ⛔ EPMA - Endpoint Moving Average ||| GetEpma || | ⛔ FRAMA - Fractal Adaptive Moving Average ||||| | ⛔ FWMA - Fibonacci's Weighted Moving Average |||| fwma | | ⛔ HILO - Gann High-Low Activator |||| hilo | | ✔️ HEMA - Hull/EMA Average | `HEMA_Series` |||| | ⛔ Hilbert Transform Instantaneous Trendline || HT_TRENDLINE | GetHtTrendline || -| ⭐ HMA - Hull Moving Average | `HMA_Series` || GetHma | hma | +| ⭐ HMA - Hull Moving Average | `HMA_Series` || GetHma | hma | hma | | ⛔ HWMA - Holt-Winter Moving Average |||| hwma | | ✔️ JMA - Jurik Moving Average | `JMA_Series` ||| jma | -| ⭐ KAMA - Kaufman's Adaptive Moving Average | `KAMA_Series` | KAMA | GetKama | kama | +| ⭐ KAMA - Kaufman's Adaptive Moving Average | `KAMA_Series` | KAMA | GetKama | kama | kama | | ⛔ KDJ - KDJ Indicator (trend reversal) |||| kdj | | ⛔ LSMA - Least Squares Moving Average ||||| | ⭐ MACD - Moving Average Convergence/Divergence | `MACD_Series` | MACD | GetMacd | macd | @@ -113,17 +117,20 @@ See [Getting Started](https://github.com/mihakralj/QuanTAlib/blob/main/Docs/gett | ⭐ WMA - Weighted Moving Average | `WMA_Series` | WMA | GetWma | wma | | ⭐ ZLEMA - Zero Lag EMA Average | `ZLEMA_Series` ||| zlma | |||||| -| **VOLATILITY INDICATORS** | **QuanTAlib** | **TA-LIB** | **Skender** | **Pandas TA** | -| ⭐ ADL - Chaikin Accumulation Distribution Line | `ADL_Series` | AD | GetAdl | ad | -| ⭐ ADOSC - Chaikin Accumulation Distribution Oscillator | `ADOSC_Series` | ADOSC| GetAdl | adosc | -| ⭐ ATR - Average True Range | `ATR_Series` | ATR | GetAtr | atr | +| **VOLATILITY INDICATORS** | +|||||| +| ⭐ ADL - Chaikin Accumulation Distribution Line | `ADL_Series` | AD | GetAdl | ad | ad | +| ⭐ ADOSC - Chaikin Accumulation Distribution Oscillator | `ADOSC_Series` | ADOSC| GetAdl | adosc | adosc | +| ⭐ ATR - Average True Range | `ATR_Series` | ATR | GetAtr | atr | atr | | ⭐ ATRP - Average True Range Percent | `ATRP_Series` || GetAtr || | ⛔ BETA - Beta coefficient || BETA | GetBeta || -| ⭐ BBANDS - Bollinger Bands® | `BBANDS_Series` | BBANDS | GetBollingerBands || +| ⭐ BBANDS - Bollinger Bands® | `BBANDS_Series` | BBANDS | GetBollingerBands || bbands | | ⛔ CHAND - Chandelier Exit ||| GetChandelier || | ⛔ CRSI - Connor RSI ||| GetConnorsRsi || +| ⛔ CVI - Chaikins Volatility ||||| cvi | | ⛔ DON - Donchian Channels ||| GetDonchian || | ⛔ FCB - Fractal Chaos Bands ||| GetFcb || +| ⛔ FISHER - Fisher Transform ||| GetFcb || fisher | | ⛔ HV - Historical Volatility ||||| | ⛔ ICH - Ichimoku ||| GetIchimoku || | ⛔ KEL - Keltner Channels ||| GetKeltner || @@ -137,23 +144,25 @@ See [Getting Started](https://github.com/mihakralj/QuanTAlib/blob/main/Docs/gett | ⛔ UI - Ulcer Index ||||| | ⛔ VSTOP - Volatility Stop ||||| |||||| -| **MOMENTUM INDICATORS & OSCILLATORS** | **QuanTAlib** | **TA-LIB** | **Skender** | **Pandas TA** | +| **MOMENTUM INDICATORS & OSCILLATORS** | +|||||| | ⛔ AC - Acceleration Oscillator ||||| -| ⛔ ADX - Average Directional Movement Index || ADX | GetAdx || -| ⛔ ADXR - Average Directional Movement Index Rating || ADXR | GetAdx || -| ⛔ AO - Awesome Oscillator ||| GetAwesome || -| ⛔ APO - Absolute Price Oscillator || APO ||| -| ⛔ AROON - Aroon oscillator || AROON | GetAroon || -| ⛔ BOP - Balance of Power || BOP | GetBop || -| ⭐ CCI - Commodity Channel Index | `CCI_Series` | CCI | GetCci || +| ⛔ ADX - Average Directional Movement Index || ADX | GetAdx || adx | +| ⛔ ADXR - Average Directional Movement Index Rating || ADXR | GetAdx || adxr | +| ⛔ AO - Awesome Oscillator ||| GetAwesome || ao | +| ⛔ APO - Absolute Price Oscillator || APO ||| apo | +| ⛔ AROON - Aroon oscillator || AROON | GetAroon || aroon | +| ⛔ BOP - Balance of Power || BOP | GetBop || bop | +| ⭐ CCI - Commodity Channel Index | `CCI_Series` | CCI | GetCci || cci | | ⛔ CFO - Chande Forcast Oscillator ||||| -| ⛔ CMO - Chande Momentum Oscillator || CMO | GetCmo || +| ⛔ CMO - Chande Momentum Oscillator || CMO | GetCmo || cmo | | ⛔ COG - Center of Gravity ||||| | ⛔ COPPOCK - Coppock Curve ||||| | ⛔ CTI - Ehler's Correlation Trend Indicator ||||| | ⛔ DPO - Detrended Price Oscillator ||| GetDpo || | ⛔ DMI - Directional Movement Index || DX | GetAdx || | ⛔ EFI - Elder Ray's Force Index ||| GetElderRay || +| ⛔ FOSC - Forecast oscillator ||||| fosc | | ⛔ GAT - Alligator oscillator ||| GetGator || | ⛔ HURST - Hurst Exponent ||| GetHurst || | ⛔ KRI - Kairi Relative Index ||||| @@ -176,10 +185,12 @@ See [Getting Started](https://github.com/mihakralj/QuanTAlib/blob/main/Docs/gett | ⛔ WILLR - Larry Williams' %R || WILLR | GetWilliamsR || | ⛔ WGAT - Williams Alligator ||||| |||||| -| **VOLUME INDICATORS** | **QuanTAlib** | **TA-LIB** | **Skender** | **Pandas TA** | +| **VOLUME INDICATORS** | +|||||| | ⛔ AOBV - Archer On-Balance Volume ||||| | ⛔ CMF - Chaikin Money Flow ||||| -| ⛔ EOM - Ease of Movement ||||| +| ⛔ EOM - Ease of Movement ||||| emv | +| ⛔ KVO - Klinger Volume Oscilaltor ||||| kvo | | ⭐ OBV - On-Balance Volume | `OBV_Series` | OBV | GetObv || | ⛔ PRS - Price Relative Strength |||| | ⛔ PVOL - Price-Volume |||||