From 86d0adc1d46182a9256dc579611d816a18047072 Mon Sep 17 00:00:00 2001 From: Miha Kralj Date: Sun, 24 Apr 2022 20:15:11 -0700 Subject: [PATCH] Sonar changes --- Docs/coverage.md | 314 ++++++++++++++--------------- Quantower/Indicators/ZLMA_chart.cs | 8 +- Source/Indicators/JMA_Series.cs | 2 - Source/Indicators/ZLEMA_Series.cs | 140 ++++++------- Tests/Validations/Pandas_TA.cstemp | 238 +++++++++++----------- 5 files changed, 350 insertions(+), 352 deletions(-) diff --git a/Docs/coverage.md b/Docs/coverage.md index 7d8b9e97..665c170e 100644 --- a/Docs/coverage.md +++ b/Docs/coverage.md @@ -1,157 +1,157 @@ -# Coverage of indicators - -| Indicator | QuanTAlib | TA-LIB | Skender | Pandas-TA | -|--|:--:|:--:|:--:|:--:| -| **Basics** ||||| -| OC2 - (Open+Close)/2 |✔️|||✔️| -| HL2 - (High+Low)/2 |✔️|||✔️| -| HLC3 - Typical Price |✔️|||✔️| -| OHL3 - (Open+High+Low)/3 |✔️|||✔️| -| OHLC4 - (O+H+L+C)/4 |✔️|||✔️| -| HLCC4 - Weighted Price |✔️||✔️|✔️| -| ZL - Zero Lag - De-lagged price |✔️|||✔️| -| ADD - Addition |✔️|✔️||| -| SUB - Subtraction |✔️|✔️||| -| MUL - Multiplication |✔️|✔️||| -| DIV - Division |✔️|✔️||| -|||||| -| **Statistics** ||||| -| BETA - Beta coefficient |||✔️|| -| BIAS - Bias |✔️|||✔️| -| ENTR - Entropy |✔️|||✔️| -| KUR - Kurtosis |✔️|||✔️| -| LINREG - Linear Regression ||✔️|✔️|| -| MAD - Mean Absolute Deviation |✔️||✔️|✔️| -| MAPE - Mean Absolute Percent Error |✔️||✔️|| -| MAX - Max value |✔️|✔️||| -| MIN - Min value |✔️|✔️||| -| MED - Median value |✔️|✔️||✔️| -| MSE - Mean Squared Error |✔️||✔️|| -| PSDEV - Population Standard Deviation |✔️|||| -| PVAR - Population Variance |✔️|||| -| QUANTILE ||||✔️| -| RS - R-Squared Coefficient |||✔️|| -| SKEW - Skewness ||||✔️| -| SLOPE - Slope |||✔️|| -| SMAPE - Symmetric Mean Absolute Percent Error |✔️|||| -| SDEV - Sample Standard Deviation |✔️|✔️|✔️|✔️| -| VAR - Sample Variance |✔️|||✔️| -| WMAPE - Weighted Mean Absolute Percent Error |✔️|||| -| ZSCORE |||✔️|✔️| -|||||| -| **Moving Averages** ||||| -| AFIRMA - Autoregressive Finite Impulse Response Moving Average ||||| -| ALMA - Arnaud Legoux Moving Average |||✔️|✔️| -| ARIMA - Autoregressive Integrated Moving Average ||||| -| ATR - Average True Range |✔️|✔️|✔️|✔️| -| ATRP - Average True Range Percent |✔️||✔️|| -| DEMA - Double EMA |✔️|✔️|✔️|✔️| -| EMA - Exponential Moving Average |✔️|✔️|✔️|✔️| -| EPMA - Endpoint Moving Average |||✔️|| -| FWMA - Fibonacci's Weighted Moving Average ||||✔️| -| HEMA - Hull Exponential Moving Average |✔️|||| -| HMA - Hull Moving Average |✔️||✔️|✔️| -| HWMA - Holt-Winter Moving Average ||||✔️| -| JMA - Jurik Moving Average |✔️|||✔️| -| KAMA - Kaufman's Adaptive Moving Average |✔️|✔️|✔️|✔️| -| LSMA - Least Squares Moving Average |||✔️|| -| MACD - Moving Average Convergence/Divergence ||✔️|✔️|✔️| -| MAMA - MESA Adaptive Moving Average ||✔️|✔️|| -| MMA - Modified Moving Average |||✔️|| -| NATR - Normalized Average True Range ||✔️|✔️|✔️| -| PPMA - Pivot Point Moving Average |||✔️|| -| PWMA - Pascal's Weighted Moving Average ||||✔️| -| RMA - WildeR's Moving Average |✔️|||✔️| -| SINWMA - Sine Weighted Moving Average ||||✔️| -| SMA - Simple Moving Average |✔️|✔️|✔️|✔️| -| SMMA - Smoothed Moving Average |✔️||✔️|| -| STOCH - Stochastic Oscillator ||✔️|✔️|✔️| -| SSF - Ehler's Super Smoother Filter ||||✔️| -| SUP - Supertrend |||✔️|✔️| -| SWMA - Symmetric Weighted Moving Average ||||✔️| -| T3 - Tillson T3 Moving Average ||✔️|✔️|✔️| -| TEMA - Triple EMA |✔️|✔️|✔️|✔️| -| TRIMA - Triangular Moving Average ||✔️||✔️| -| VIDYA - Variable Index Dynamic Average ||||✔️| -| VWAP - Volume Weighted Average Price |||✔️|✔️| -| VWMA - Volume Weighted Moving Average |||✔️|✔️| -| WMA - Weighted Moving Average |✔️|✔️|✔️|✔️| -| ZLEMA - Zero Lag EMA |✔️|||✔️| -|||||| -| **Oscillators and Indices** ||||| -| AC - Acceleration Oscillator ||||✔️| -| AD - Chaikin Accumulation Distribution ||✔️|✔️|✔️| -| ADOSC - Chaikin Accumulation Distribution Oscillator ||✔️|✔️|| -| ADX - Average Directional Movement Index ||✔️|✔️|✔️| -| ADXR - Average Directional Movement Index Rating ||✔️|✔️|| -| AO - Awesome Oscillator |||✔️|✔️| -| APO - Absolute Price Oscillator ||✔️||✔️| -| AROON - Aroon oscillator ||✔️|✔️|✔️| -| BBANDS - Bollinger Bands ||✔️|✔️|✔️| -| BOP - Balance of Power ||✔️|✔️|✔️| -| CCI - Commodity Channel Index ||✔️|✔️|✔️| -| CFO - Chande Forcast Oscillator ||||✔️| -| CMF - Chaikin Money Flow |||✔️|✔️| -| CMO - Chande Momentum Oscillator ||✔️||✔️| -| COG - Center of Gravity ||||✔️| -| CRSI - Connor RSI |||✔️|| -| CTI - Ehler's Correlation Trend Indicator ||||✔️| -| DMI - Directional Movement Index ||✔️|✔️|✔️| -| EFI - Elder Ray's Force Index |||✔️|✔️| -| GAT - Alligator oscillator |||✔️|| -| KRI - Kairi Relative Index ||||| -| KVO - Klinger Volume Oscillator |||✔️|✔️| -| MFI - Money Flow Index ||✔️|✔️|✔️| -| MOM - Momentum |||✔️|✔️| -| NVI - Negative Volume Index ||||✔️| -| PO - Price Oscillator ||||✔️| -| PPO - Percentage Price Oscillator ||✔️||✔️| -| PVI - Positive Volume Index ||||✔️| -| RSI - Relative Strength Index ||✔️|✔️|✔️| -| RVGI - Relative Vigor Index ||||✔️| -| SRSI - Stochastic RSI |||✔️|✔️| -| TRIX - 1-day ROC of TEMA ||✔️|✔️|✔️| -| TSI - True Strength Index |||✔️|✔️| -| UI - Ulcer Index |||✔️|✔️| -| UO - Ultimate Oscillator ||✔️|✔️|✔️| -| WGAT - Williams Alligator |||✔️|| -|||||| -| **Volume** ||||| -| AOBV - Archer On-Balance Volume ||||✔️| -| OBV - On-Balance Volume ||✔️|✔️|✔️| -| PRS - Price Relative Strength |||✔️|| -| PVOL - Price-Volume ||||| -| PVR - Price Volume Rank ||||✔️| -| PVT - Price Volume Trend ||||✔️| -| VP - Volume Profile ||||✔️| -|||||| -|**Unsorted**||||| -| CHN - Price Channel |||✔️|| -| COPPOCK - Coppock Curve ||||✔️| -| CORREL - Pearson's Correlation Coefficient ||✔️|✔️|| -| EOM - Ease of Movement ||||✔️| -| HILO - Gann High-Low Activator ||||✔️| -| HV - Historical Volatility |||✔️|| -| HT - HT Trendline |||✔️|| -| ICH - Ichimoku |||✔️|✔️| -| MCGD - McGinley Dynamic ||||✔️| -| ROC - Rate of Change ||✔️|✔️|✔️| -| SAR - Parabolic Stop and Reverse ||✔️|✔️|✔️| -| STC - Schaff Trend Cycle |||✔️|✔️| -| TR - True Range ||✔️|✔️|✔️| -| WILLR - Larry Williams' %R ||✔️|✔️|✔️| -| HURST - Hurst Exponent |||✔️|| -| VOR - Vortex Indicator |||✔️|✔️| -| DON - Donchian Channels |||✔️|✔️| -| FCB - Fractal Chaos Bands |||✔️|| -| KEL - Keltner Channels |||✔️|✔️| -| PVT - Pivot Points |||✔️|| -| STARC - Starc Bands |||✔️|| -| DPO - De-trended Price Oscillator |||✔️|✔️| -| KDJ - KDJ Index |||✔️|✔️| -| SMI - Stochastic Momentum Index |||✔️|✔️| -| CHAND - Chandelier Exit |||✔️|| -| VSTOP - Volatility Stop |||✔️|| -| PVO - Percentage Volume Oscillator |||✔️|✔️| -| Hilbert Transform Instantaneous Trendline ||||| -| PMO - Price Momentum Oscillator |||✔️|| +# Coverage of indicators + +| Indicator | QuanTAlib | TA-LIB | Skender | Pandas-TA | +|--|:--:|:--:|:--:|:--:| +| **Basics** ||||| +| OC2 - (Open+Close)/2 |✔️|||✔️| +| HL2 - (High+Low)/2 |✔️|||✔️| +| HLC3 - Typical Price |✔️|||✔️| +| OHL3 - (Open+High+Low)/3 |✔️|||✔️| +| OHLC4 - (O+H+L+C)/4 |✔️|||✔️| +| HLCC4 - Weighted Price |✔️||✔️|✔️| +| ZL - Zero Lag - De-lagged price |✔️|||✔️| +| ADD - Addition |✔️|✔️||| +| SUB - Subtraction |✔️|✔️||| +| MUL - Multiplication |✔️|✔️||| +| DIV - Division |✔️|✔️||| +|||||| +| **Statistics** ||||| +| BETA - Beta coefficient |||✔️|| +| BIAS - Bias |✔️|||✔️| +| ENTR - Entropy |✔️|||✔️| +| KUR - Kurtosis |✔️|||✔️| +| LINREG - Linear Regression ||✔️|✔️|| +| MAD - Mean Absolute Deviation |✔️||✔️|✔️| +| MAPE - Mean Absolute Percent Error |✔️||✔️|| +| MAX - Max value |✔️|✔️||| +| MIN - Min value |✔️|✔️||| +| MED - Median value |✔️|✔️||✔️| +| MSE - Mean Squared Error |✔️||✔️|| +| PSDEV - Population Standard Deviation |✔️|||| +| PVAR - Population Variance |✔️|||| +| QUANTILE ||||✔️| +| RS - R-Squared Coefficient |||✔️|| +| SKEW - Skewness ||||✔️| +| SLOPE - Slope |||✔️|| +| SMAPE - Symmetric Mean Absolute Percent Error |✔️|||| +| SDEV - Sample Standard Deviation |✔️|✔️|✔️|✔️| +| VAR - Sample Variance |✔️|||✔️| +| WMAPE - Weighted Mean Absolute Percent Error |✔️|||| +| ZSCORE |||✔️|✔️| +|||||| +| **Moving Averages** ||||| +| AFIRMA - Autoregressive Finite Impulse Response Moving Average ||||| +| ALMA - Arnaud Legoux Moving Average |||✔️|✔️| +| ARIMA - Autoregressive Integrated Moving Average ||||| +| ATR - Average True Range |✔️|✔️|✔️|✔️| +| ATRP - Average True Range Percent |✔️||✔️|| +| DEMA - Double EMA |✔️|✔️|✔️|✔️| +| EMA - Exponential Moving Average |✔️|✔️|✔️|✔️| +| EPMA - Endpoint Moving Average |||✔️|| +| FWMA - Fibonacci's Weighted Moving Average ||||✔️| +| HEMA - Hull Exponential Moving Average |✔️|||| +| HMA - Hull Moving Average |✔️||✔️|✔️| +| HWMA - Holt-Winter Moving Average ||||✔️| +| JMA - Jurik Moving Average |✔️|||✔️| +| KAMA - Kaufman's Adaptive Moving Average |✔️|✔️|✔️|✔️| +| LSMA - Least Squares Moving Average |||✔️|| +| MACD - Moving Average Convergence/Divergence ||✔️|✔️|✔️| +| MAMA - MESA Adaptive Moving Average ||✔️|✔️|| +| MMA - Modified Moving Average |||✔️|| +| NATR - Normalized Average True Range ||✔️|✔️|✔️| +| PPMA - Pivot Point Moving Average |||✔️|| +| PWMA - Pascal's Weighted Moving Average ||||✔️| +| RMA - WildeR's Moving Average |✔️|||✔️| +| SINWMA - Sine Weighted Moving Average ||||✔️| +| SMA - Simple Moving Average |✔️|✔️|✔️|✔️| +| SMMA - Smoothed Moving Average |✔️||✔️|| +| STOCH - Stochastic Oscillator ||✔️|✔️|✔️| +| SSF - Ehler's Super Smoother Filter ||||✔️| +| SUP - Supertrend |||✔️|✔️| +| SWMA - Symmetric Weighted Moving Average ||||✔️| +| T3 - Tillson T3 Moving Average ||✔️|✔️|✔️| +| TEMA - Triple EMA |✔️|✔️|✔️|✔️| +| TRIMA - Triangular Moving Average ||✔️||✔️| +| VIDYA - Variable Index Dynamic Average ||||✔️| +| VWAP - Volume Weighted Average Price |||✔️|✔️| +| VWMA - Volume Weighted Moving Average |||✔️|✔️| +| WMA - Weighted Moving Average |✔️|✔️|✔️|✔️| +| ZLEMA - Zero Lag EMA |✔️|||✔️| +|||||| +| **Oscillators and Indices** ||||| +| AC - Acceleration Oscillator ||||✔️| +| AD - Chaikin Accumulation Distribution ||✔️|✔️|✔️| +| ADOSC - Chaikin Accumulation Distribution Oscillator ||✔️|✔️|| +| ADX - Average Directional Movement Index ||✔️|✔️|✔️| +| ADXR - Average Directional Movement Index Rating ||✔️|✔️|| +| AO - Awesome Oscillator |||✔️|✔️| +| APO - Absolute Price Oscillator ||✔️||✔️| +| AROON - Aroon oscillator ||✔️|✔️|✔️| +| BBANDS - Bollinger Bands ||✔️|✔️|✔️| +| BOP - Balance of Power ||✔️|✔️|✔️| +| CCI - Commodity Channel Index ||✔️|✔️|✔️| +| CFO - Chande Forcast Oscillator ||||✔️| +| CMF - Chaikin Money Flow |||✔️|✔️| +| CMO - Chande Momentum Oscillator ||✔️||✔️| +| COG - Center of Gravity ||||✔️| +| CRSI - Connor RSI |||✔️|| +| CTI - Ehler's Correlation Trend Indicator ||||✔️| +| DMI - Directional Movement Index ||✔️|✔️|✔️| +| EFI - Elder Ray's Force Index |||✔️|✔️| +| GAT - Alligator oscillator |||✔️|| +| KRI - Kairi Relative Index ||||| +| KVO - Klinger Volume Oscillator |||✔️|✔️| +| MFI - Money Flow Index ||✔️|✔️|✔️| +| MOM - Momentum |||✔️|✔️| +| NVI - Negative Volume Index ||||✔️| +| PO - Price Oscillator ||||✔️| +| PPO - Percentage Price Oscillator ||✔️||✔️| +| PVI - Positive Volume Index ||||✔️| +| RSI - Relative Strength Index ||✔️|✔️|✔️| +| RVGI - Relative Vigor Index ||||✔️| +| SRSI - Stochastic RSI |||✔️|✔️| +| TRIX - 1-day ROC of TEMA ||✔️|✔️|✔️| +| TSI - True Strength Index |||✔️|✔️| +| UI - Ulcer Index |||✔️|✔️| +| UO - Ultimate Oscillator ||✔️|✔️|✔️| +| WGAT - Williams Alligator |||✔️|| +|||||| +| **Volume** ||||| +| AOBV - Archer On-Balance Volume ||||✔️| +| OBV - On-Balance Volume ||✔️|✔️|✔️| +| PRS - Price Relative Strength |||✔️|| +| PVOL - Price-Volume ||||| +| PVR - Price Volume Rank ||||✔️| +| PVT - Price Volume Trend ||||✔️| +| VP - Volume Profile ||||✔️| +|||||| +|**Unsorted**||||| +| CHN - Price Channel |||✔️|| +| COPPOCK - Coppock Curve ||||✔️| +| CORREL - Pearson's Correlation Coefficient ||✔️|✔️|| +| EOM - Ease of Movement ||||✔️| +| HILO - Gann High-Low Activator ||||✔️| +| HV - Historical Volatility |||✔️|| +| HT - HT Trendline |||✔️|| +| ICH - Ichimoku |||✔️|✔️| +| MCGD - McGinley Dynamic ||||✔️| +| ROC - Rate of Change ||✔️|✔️|✔️| +| SAR - Parabolic Stop and Reverse ||✔️|✔️|✔️| +| STC - Schaff Trend Cycle |||✔️|✔️| +| TR - True Range ||✔️|✔️|✔️| +| WILLR - Larry Williams' %R ||✔️|✔️|✔️| +| HURST - Hurst Exponent |||✔️|| +| VOR - Vortex Indicator |||✔️|✔️| +| DON - Donchian Channels |||✔️|✔️| +| FCB - Fractal Chaos Bands |||✔️|| +| KEL - Keltner Channels |||✔️|✔️| +| PVT - Pivot Points |||✔️|| +| STARC - Starc Bands |||✔️|| +| DPO - De-trended Price Oscillator |||✔️|✔️| +| KDJ - KDJ Index |||✔️|✔️| +| SMI - Stochastic Momentum Index |||✔️|✔️| +| CHAND - Chandelier Exit |||✔️|| +| VSTOP - Volatility Stop |||✔️|| +| PVO - Percentage Volume Oscillator |||✔️|✔️| +| Hilbert Transform Instantaneous Trendline ||||| +| PMO - Price Momentum Oscillator |||✔️|| diff --git a/Quantower/Indicators/ZLMA_chart.cs b/Quantower/Indicators/ZLMA_chart.cs index c8a23b28..61020e38 100644 --- a/Quantower/Indicators/ZLMA_chart.cs +++ b/Quantower/Indicators/ZLMA_chart.cs @@ -30,12 +30,12 @@ public class ZLMA_chart : Indicator private int matype = 2; #endregion Parameters - + private TBars bars; - /////// + /////// private TSeries indicator; - /////// - + /////// + public ZLMA_chart() { this.SeparateWindow = false; diff --git a/Source/Indicators/JMA_Series.cs b/Source/Indicators/JMA_Series.cs index 7359c4d4..dfe2bf9a 100644 --- a/Source/Indicators/JMA_Series.cs +++ b/Source/Indicators/JMA_Series.cs @@ -41,8 +41,6 @@ public class JMA_Series : Single_TSeries_Indicator 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); - //this._l = (int)Math.Round(this._p - 1 * 0.5); - if (base._data.Count > 0) { base.Add(base._data); } } diff --git a/Source/Indicators/ZLEMA_Series.cs b/Source/Indicators/ZLEMA_Series.cs index 5642cf8f..be2913f7 100644 --- a/Source/Indicators/ZLEMA_Series.cs +++ b/Source/Indicators/ZLEMA_Series.cs @@ -1,71 +1,71 @@ -namespace QuanTAlib; -using System; - -/* -ZLEMA: Zero Lag Exponential Moving Average - The Zero lag exponential moving average (ZLEMA) indicator was created by John - Ehlers and Ric Way. - -The formula for a given N-Day period and for a given Data series is: - Lag = (Period-1)/2 - Ema Data = {Data+(Data-Data(Lag days ago)) - ZLEMA = EMA (EmaData,Period) - -Remark: - The idea is do a regular exponential moving average (EMA) calculation but on a - de-lagged data instead of doing it on the regular data. Data is de-lagged by - removing the data from "lag" days ago thus removing (or attempting to remove) - the cumulative lag effect of the moving average. - - */ - -public class ZLEMA_Series : Single_TSeries_Indicator -{ - private readonly System.Collections.Generic.List _buffer = new(); - private readonly double _k, _k1m; - private double _lastema, _lastlastema; - - public ZLEMA_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; - this._lastema = this._lastlastema = double.NaN; - if (base._data.Count > 0) - { base.Add(base._data); } - } - - public override void Add((System.DateTime t, double v) TValue, bool update) - { - int _lag = (int)((_p - 1) * 0.5); - _lag = (this.Count - _lag < 0) ? 0 : this.Count - _lag; - double _zl = TValue.v + (TValue.v - _data[_lag].v); - double _ema = 0; - if (update) - { this._lastema = this._lastlastema; } - if (this.Count < this._p) - { - if (update) - { this._buffer[this._buffer.Count - 1] = _zl; } - else - { - this._buffer.Add(_zl); - } - if (this._buffer.Count > this._p) - { this._buffer.RemoveAt(0); } - - for (int i = 0; i < this._buffer.Count; i++) - { _ema += this._buffer[i]; } - _ema /= this._buffer.Count; - } - else - { - _ema = TValue.v * this._k + this._lastema * this._k1m; - } - - this._lastlastema = this._lastema; - this._lastema = _ema; - - var ret = (TValue.t, this.Count < this._p - 1 && this._NaN ? double.NaN : _ema); - base.Add(ret, update); - } +namespace QuanTAlib; +using System; + +/* +ZLEMA: Zero Lag Exponential Moving Average + The Zero lag exponential moving average (ZLEMA) indicator was created by John + Ehlers and Ric Way. + +The formula for a given N-Day period and for a given Data series is: + Lag = (Period-1)/2 + Ema Data = {Data+(Data-Data(Lag days ago)) + ZLEMA = EMA (EmaData,Period) + +Remark: + The idea is do a regular exponential moving average (EMA) calculation but on a + de-lagged data instead of doing it on the regular data. Data is de-lagged by + removing the data from "lag" days ago thus removing (or attempting to remove) + the cumulative lag effect of the moving average. + + */ + +public class ZLEMA_Series : Single_TSeries_Indicator +{ + private readonly System.Collections.Generic.List _buffer = new(); + private readonly double _k, _k1m; + private double _lastema, _lastlastema; + + public ZLEMA_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; + this._lastema = this._lastlastema = double.NaN; + if (base._data.Count > 0) + { base.Add(base._data); } + } + + public override void Add((System.DateTime t, double v) TValue, bool update) + { + int _lag = (int)((_p - 1) * 0.5); + _lag = (this.Count - _lag < 0) ? 0 : this.Count - _lag; + double _zl = TValue.v + (TValue.v - _data[_lag].v); + double _ema = 0; + if (update) + { this._lastema = this._lastlastema; } + if (this.Count < this._p) + { + if (update) + { this._buffer[this._buffer.Count - 1] = _zl; } + else + { + this._buffer.Add(_zl); + } + if (this._buffer.Count > this._p) + { this._buffer.RemoveAt(0); } + + for (int i = 0; i < this._buffer.Count; i++) + { _ema += this._buffer[i]; } + _ema /= this._buffer.Count; + } + else + { + _ema = TValue.v * this._k + this._lastema * this._k1m; + } + + this._lastlastema = this._lastema; + this._lastema = _ema; + + var ret = (TValue.t, this.Count < this._p - 1 && this._NaN ? double.NaN : _ema); + base.Add(ret, update); + } } \ No newline at end of file diff --git a/Tests/Validations/Pandas_TA.cstemp b/Tests/Validations/Pandas_TA.cstemp index 27c2e9b8..0aa769bd 100644 --- a/Tests/Validations/Pandas_TA.cstemp +++ b/Tests/Validations/Pandas_TA.cstemp @@ -1,120 +1,120 @@ -using Xunit; -using System; -using QuanTAlib; -using Python.Runtime; -using Python.Included; - -namespace Validation; -public class PandasTA -{ - private readonly RND_Feed bars; - private readonly Random rnd = new(); - private readonly int period; - private readonly dynamic ta; - private readonly dynamic df; - - public PandasTA() - { - this.bars = new(1000); - this.period = this.rnd.Next(28) + 3; - - Installer.SetupPython().Wait(); - Installer.TryInstallPip(); - Installer.PipInstallModule("numpy"); - Installer.PipInstallModule("pandas"); - Installer.PipInstallModule("pandas-ta"); - PythonEngine.Initialize(); - this.ta = Py.Import("pandas_ta"); - this.df = this.ta.DataFrame(this.bars.Close.v); - } - - ~PandasTA() - { - PythonEngine.Shutdown(); - } - - [Fact] - void SMA() - { - SMA_Series QL = new(this.bars.Close, this.period, false); - var pta = this.ta.sma(close: this.df[0], length: this.period); - - Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7)); - } - -/* - [Fact] - void EMA() - { - EMA_Series QL = new(this.bars.Close, this.period, false); - var pta = this.ta.ema(close: this.df[0], length: this.period); - - Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7)); - } - - [Fact] - void TEMA() - { - TEMA_Series QL = new(this.bars.Close, this.period, false); - var pta = this.ta.tema(close: this.df[0], length: this.period); - - Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7)); - } - - [Fact] - void ENTP() - { - ENTP_Series QL = new(this.bars.Close, this.period, useNaN:false); - var pta = this.ta.entropy(close: this.df[0], length: this.period); - - Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7)); - } - - - [Fact] - void WMA() - { - WMA_Series QL = new(this.bars.Close, this.period, false); - var pta = this.ta.wma(close: this.df[0], length: this.period); - - Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7)); - } - - [Fact] - void DEMA() - { - DEMA_Series QL = new(this.bars.Close, this.period, false); - var pta = this.ta.dema(close: this.df[0], length: this.period); - - Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7)); - } - - [Fact] - void BIAS() - { - BIAS_Series QL = new(this.bars.Close, this.period, false); - var pta = this.ta.bias(close: this.df[0], length: this.period); - - Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7)); - } - - [Fact] - void KURT() - { - KURT_Series QL = new(this.bars.Close, this.period, useNaN: false); - var pta = this.ta.kurtosis(close: this.df[0], length: this.period); - - Assert.Equal(System.Math.Round((double)pta.tail(1), 4), Math.Round(QL.Last().v, 4)); - } - - [Fact] - void MAD() - { - MAD_Series QL = new(this.bars.Close, this.period, useNaN: false); - var pta = this.ta.mad(close: this.df[0], length: this.period); - - Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7)); - } -*/ - +using Xunit; +using System; +using QuanTAlib; +using Python.Runtime; +using Python.Included; + +namespace Validation; +public class PandasTA +{ + private readonly RND_Feed bars; + private readonly Random rnd = new(); + private readonly int period; + private readonly dynamic ta; + private readonly dynamic df; + + public PandasTA() + { + this.bars = new(1000); + this.period = this.rnd.Next(28) + 3; + + Installer.SetupPython().Wait(); + Installer.TryInstallPip(); + Installer.PipInstallModule("numpy"); + Installer.PipInstallModule("pandas"); + Installer.PipInstallModule("pandas-ta"); + PythonEngine.Initialize(); + this.ta = Py.Import("pandas_ta"); + this.df = this.ta.DataFrame(this.bars.Close.v); + } + + ~PandasTA() + { + PythonEngine.Shutdown(); + } + + [Fact] + void SMA() + { + SMA_Series QL = new(this.bars.Close, this.period, false); + var pta = this.ta.sma(close: this.df[0], length: this.period); + + Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7)); + } + +/* + [Fact] + void EMA() + { + EMA_Series QL = new(this.bars.Close, this.period, false); + var pta = this.ta.ema(close: this.df[0], length: this.period); + + Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7)); + } + + [Fact] + void TEMA() + { + TEMA_Series QL = new(this.bars.Close, this.period, false); + var pta = this.ta.tema(close: this.df[0], length: this.period); + + Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7)); + } + + [Fact] + void ENTP() + { + ENTP_Series QL = new(this.bars.Close, this.period, useNaN:false); + var pta = this.ta.entropy(close: this.df[0], length: this.period); + + Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7)); + } + + + [Fact] + void WMA() + { + WMA_Series QL = new(this.bars.Close, this.period, false); + var pta = this.ta.wma(close: this.df[0], length: this.period); + + Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7)); + } + + [Fact] + void DEMA() + { + DEMA_Series QL = new(this.bars.Close, this.period, false); + var pta = this.ta.dema(close: this.df[0], length: this.period); + + Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7)); + } + + [Fact] + void BIAS() + { + BIAS_Series QL = new(this.bars.Close, this.period, false); + var pta = this.ta.bias(close: this.df[0], length: this.period); + + Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7)); + } + + [Fact] + void KURT() + { + KURT_Series QL = new(this.bars.Close, this.period, useNaN: false); + var pta = this.ta.kurtosis(close: this.df[0], length: this.period); + + Assert.Equal(System.Math.Round((double)pta.tail(1), 4), Math.Round(QL.Last().v, 4)); + } + + [Fact] + void MAD() + { + MAD_Series QL = new(this.bars.Close, this.period, useNaN: false); + var pta = this.ta.mad(close: this.df[0], length: this.period); + + Assert.Equal(System.Math.Round((double)pta.tail(1), 7), Math.Round(QL.Last().v, 7)); + } +*/ + } \ No newline at end of file