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 IEnumerablequotes; + + + 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 + + + + + +## 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 @@ + +# 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": [ - "" - ] - }, - "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": [ - "
index Item1 Item2 0 2022-11-10 00:00:00Z 105.31 2022-11-10 15:47:46Z 293.12 2022-11-10 15:47:46Z 03 2022-11-07 15:47:46Z 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": [ - "
index value 0 105.31 293.12 03 1010" - ] - }, - "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": [ - "" - ] - }, - "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": [ - "
index value 0 Infinity1 0.66666666666666662 0.33333333333333333 0.24 0.142857142857142855 0.11111111111111116 0.090909090909090917 0.076923076923076938 0.066666666666666679 0.05882352941176470510 0.25" - ] - }, - "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": [ + "
index value 0 01 02 03 04 05 06 07 08 09 010 011 012 0.1354358974359001813 -0.0389795435334099314 -0.1773100843141110215 -0.2403067115230409516 -0.0824705567361498817 -0.4789844849024081418 -0.902071504185661519 -1.3489730137363423(51 more) " + ] + }, + "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", + "Listx = 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 @@ + \ 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", + "Listx = 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 @@ + \ 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 @@ - + + - - - + + + +