From c27147c1cdf77af5dde1711bb3adf98b29993db8 Mon Sep 17 00:00:00 2001 From: Dave Skender <8432125+DaveSkender@users.noreply.github.com> Date: Sat, 29 Jun 2024 19:40:13 -0400 Subject: [PATCH] chore: code cleanup --- Stock.Indicators.sln.DotSettings | 2 + docs/pages/utilities.md | 16 +- src/_common/Candles/Candles.Models.cs | 10 +- src/_common/Candles/Candles.Utilities.cs | 2 +- src/_common/Enums.cs | 44 ++--- src/_common/Generics/Pruning.cs | 18 +- src/_common/Generics/Seek.cs | 13 +- src/_common/Math/NullMath.cs | 10 +- src/_common/Math/Numerix.cs | 36 ++-- src/_common/Observables/AbstractCache.cs | 133 ++++++--------- .../Observables/AbstractChainInChainOut.cs | 29 +--- .../Observables/AbstractChainInResultOut.cs | 29 +--- src/_common/Observables/AbstractProvider.cs | 154 +++++++++--------- .../Observables/AbstractQuoteInChainOut.cs | 29 +--- .../Observables/AbstractQuoteInQuoteOut.cs | 30 ++-- .../Observables/AbstractQuoteInResultOut.cs | 29 +--- src/_common/Observables/IStreamCache.cs | 10 +- src/_common/Observables/IStreamObserver.cs | 49 ++++-- src/_common/Observables/IStreamProvider.cs | 80 +++++---- src/_common/Observables/QuoteProvider.cs | 11 +- src/_common/ObsoleteV3.cs | 4 +- src/_common/Quotes/Quote.Aggregates.cs | 38 ++--- src/_common/Quotes/Quote.Converters.cs | 97 ++++++----- src/_common/Quotes/Quote.Models.cs | 4 +- src/_common/Quotes/Quote.Validation.cs | 5 + src/_common/Results/Result.Utilities.cs | 4 +- .../Use (quote converter)/Use.Stream.cs | 8 +- src/a-d/Adl/Adl.Api.cs | 13 +- src/a-d/Adl/Adl.Common.cs | 6 +- src/a-d/Adl/Adl.Series.cs | 2 +- src/a-d/Adl/Adl.Stream.cs | 2 +- src/a-d/Adl/info.xml | 17 -- src/a-d/Adx/Adx.Series.cs | 24 +-- src/a-d/Adx/Adx.Utilities.cs | 2 +- src/a-d/Alligator/Alligator.Series.cs | 10 +- src/a-d/Alligator/Alligator.Stream.cs | 36 ++-- src/a-d/Alma/Alma.Series.cs | 2 +- src/a-d/Aroon/Aroon.Series.cs | 2 +- src/a-d/Atr/Atr.Series.cs | 8 +- src/a-d/AtrStop/AtrStop.Series.cs | 10 +- src/a-d/Awesome/Awesome.Series.cs | 8 +- src/a-d/Beta/Beta.Series.cs | 50 +++--- .../BollingerBands/BollingerBands.Series.cs | 14 +- src/a-d/Bop/Bop.Series.cs | 8 +- src/a-d/Cci/Cci.Series.cs | 6 +- src/a-d/ChaikinOsc/ChaikinOsc.Series.cs | 4 +- src/a-d/Chandelier/Chandelier.Series.cs | 8 +- src/a-d/Chop/Chop.Series.cs | 17 +- src/a-d/Cmf/Cmf.Series.cs | 4 +- src/a-d/Cmo/Cmo.Series.cs | 11 +- src/a-d/ConnorsRsi/ConnorsRsi.Series.cs | 2 +- src/a-d/Correlation/Correlation.Series.cs | 20 +-- src/a-d/Dema/Dema.Series.cs | 10 +- src/a-d/Dema/Dema.Utilities.cs | 2 +- src/a-d/Doji/Doji.Api.cs | 6 - src/a-d/Doji/Doji.Series.cs | 4 +- src/a-d/Donchian/Donchian.Series.cs | 4 +- src/a-d/Dpo/Dpo.Series.cs | 6 +- src/a-d/Dynamic/Dynamic.Series.cs | 8 +- src/e-k/ElderRay/ElderRay.Series.cs | 4 +- src/e-k/Ema/Ema.Common.cs | 2 +- src/e-k/Ema/Ema.Series.cs | 4 +- src/e-k/Ema/Ema.Stream.cs | 7 +- src/e-k/Epma/Epma.Series.cs | 4 +- src/e-k/Fcb/Fcb.Series.cs | 4 +- .../FisherTransform/FisherTransform.Series.cs | 20 +-- src/e-k/ForceIndex/ForceIndex.Series.cs | 18 +- src/e-k/Fractal/Fractal.Series.cs | 12 +- src/e-k/Gator/Gator.Series.cs | 16 +- src/e-k/HeikinAshi/HeikinAshi.Series.cs | 2 +- src/e-k/Hma/Hma.Series.cs | 16 +- src/e-k/HtTrendline/HtTrendline.Series.cs | 51 +++--- src/e-k/Hurst/Hurst.Series.cs | 12 +- src/e-k/Ichimoku/Ichimoku.Series.cs | 103 ++++++------ src/e-k/Kama/Kama.Models.cs | 2 +- src/e-k/Kama/Kama.Series.cs | 18 +- src/e-k/Kama/Kama.Utilities.cs | 2 +- src/e-k/Keltner/Keltner.Series.cs | 6 +- src/e-k/Kvo/Kvo.Series.cs | 24 +-- src/m-r/MaEnvelopes/MaEnvelopes.Api.cs | 2 +- src/m-r/MaEnvelopes/MaEnvelopes.Series.cs | 86 +++++----- src/m-r/Macd/Macd.Series.cs | 4 +- src/m-r/Mama/Mama.Series.cs | 49 +++--- src/m-r/Marubozu/Marubozu.Common.cs | 16 +- src/m-r/Marubozu/Marubozu.Series.cs | 4 +- src/m-r/Mfi/Mfi.Series.cs | 16 +- src/m-r/Obv/Obv.Series.cs | 2 +- src/m-r/ParabolicSar/ParabolicSar.Series.cs | 17 +- src/m-r/PivotPoints/PivotPoints.Models.cs | 6 +- src/m-r/PivotPoints/PivotPoints.Series.cs | 102 ++++++------ src/m-r/PivotPoints/PivotPoints.Utilities.cs | 2 +- src/m-r/Pivots/Pivots.Models.cs | 8 +- src/m-r/Pivots/Pivots.Series.cs | 20 +-- src/m-r/Pmo/Pmo.Series.cs | 8 +- src/m-r/Prs/Prs.Common.cs | 7 +- src/m-r/Prs/Prs.Series.cs | 4 +- src/m-r/Pvo/Pvo.Series.cs | 6 +- src/m-r/Renko/Renko.Series.cs | 17 +- src/m-r/Renko/RenkoAtr.Series.cs | 2 +- src/m-r/Roc/Roc.Series.cs | 6 +- src/m-r/RocWb/RocWb.Series.cs | 4 +- src/m-r/RollingPivots/RollingPivots.Models.cs | 2 +- src/m-r/RollingPivots/RollingPivots.Series.cs | 10 +- .../RollingPivots/RollingPivots.Utilities.cs | 2 +- src/m-r/Rsi/Rsi.Series.cs | 17 +- src/s-z/Slope/Slope.Series.cs | 33 ++-- src/s-z/Sma/Sma.Api.cs | 9 - src/s-z/Sma/Sma.Series.cs | 5 +- src/s-z/Sma/Sma.Stream.cs | 7 +- src/s-z/SmaAnalysis/Sma.Analysis.Api.cs | 16 ++ .../Sma.Analysis.Series.cs} | 6 +- src/s-z/Smi/Smi.Series.cs | 16 +- src/s-z/Smma/Smma.Series.cs | 6 +- src/s-z/StarcBands/StarcBands.Series.cs | 8 +- src/s-z/Stc/Stc.Series.cs | 6 +- src/s-z/StdDev/StdDev.Series.cs | 4 +- .../StdDevChannels/StdDevChannels.Series.cs | 26 +-- src/s-z/Stoch/Stoch.Api.cs | 2 +- src/s-z/Stoch/Stoch.Common.cs | 2 +- src/s-z/Stoch/Stoch.Series.cs | 124 +++++++------- src/s-z/StochRsi/StochRsi.Series.cs | 8 +- src/s-z/SuperTrend/SuperTrend.Series.cs | 8 +- src/s-z/T3/T3.Series.cs | 12 +- src/s-z/Tema/Tema.Series.cs | 12 +- src/s-z/Tema/Tema.Utilities.cs | 2 +- src/s-z/Tr/Tr.Series.cs | 2 +- src/s-z/Trix/Trix.Series.cs | 10 +- src/s-z/Trix/Trix.Utilities.cs | 2 +- src/s-z/Tsi/Tsi.Series.cs | 28 ++-- src/s-z/UlcerIndex/UlcerIndex.Models.cs | 2 +- src/s-z/UlcerIndex/UlcerIndex.Series.cs | 4 +- src/s-z/Ultimate/Ultimate.Series.cs | 36 ++-- .../VolatilityStop/VolatilityStop.Series.cs | 6 +- src/s-z/Vortex/Vortex.Series.cs | 4 +- src/s-z/Vwap/Vwap.Series.cs | 10 +- src/s-z/Vwma/Vwma.Series.cs | 6 +- src/s-z/WilliamsR/WilliamsR.Series.cs | 4 +- src/s-z/Wma/Wma.Series.cs | 4 +- src/s-z/ZigZag/ZigZag.Models.cs | 2 +- src/s-z/ZigZag/ZigZag.Series.cs | 95 +++++------ tests/indicators/TestBase.cs | 53 +++--- .../_common/Candles/Candles.Tests.cs | 12 +- .../_common/Generics/Pruning.Tests.cs | 6 +- .../indicators/_common/Generics/Seek.Tests.cs | 6 +- .../indicators/_common/Generics/Sort.Tests.cs | 20 +-- .../_common/Generics/Transforms.Tests.cs | 2 +- .../indicators/_common/Math/Numerix.Tests.cs | 20 +-- .../Observables/AbstractProvider.Tests.cs | 8 +- .../_common/Observables/Cache.Management.cs | 6 +- .../Observables/ChainProvider.Tests.cs | 8 +- .../Observables/QuoteProvider.Tests.cs | 4 +- .../_common/Quotes/Quote.Aggregates.Tests.cs | 23 +-- .../_common/Quotes/Quote.Converters.Tests.cs | 101 ++++++------ .../_common/Quotes/Quote.Equality.Tests.cs | 10 +- .../_common/Quotes/Quote.Validation.Tests.cs | 22 +-- .../_common/Results/Result.Utilities.Tests.cs | 6 +- .../_common/Use/Use.Series.Tests.cs | 26 +-- tests/indicators/_testdata/Helper.Importer.cs | 2 +- tests/indicators/_testdata/Helper.Random.cs | 30 ++-- tests/indicators/a-d/Adl/Adl.Series.Tests.cs | 14 +- tests/indicators/a-d/Adx/Adx.Tests.cs | 32 ++-- .../a-d/Alligator/Alligator.Series.Tests.cs | 40 ++--- .../a-d/Alligator/Alligator.Stream.Tests.cs | 12 +- tests/indicators/a-d/Alma/Alma.Tests.cs | 38 ++--- tests/indicators/a-d/Aroon/Aroon.Tests.cs | 22 +-- tests/indicators/a-d/Atr/Atr.Tests.cs | 20 +-- tests/indicators/a-d/AtrStop/AtrStop.Tests.cs | 20 +-- tests/indicators/a-d/Awesome/Awesome.Tests.cs | 26 +-- tests/indicators/a-d/Beta/Beta.Tests.cs | 114 +++++++------ .../BollingerBands/BollingerBands.Tests.cs | 22 +-- tests/indicators/a-d/Bop/Bop.Tests.cs | 24 +-- tests/indicators/a-d/Cci/Cci.Tests.cs | 22 +-- .../a-d/ChaikinOsc/ChaikinOsc.Tests.cs | 20 +-- .../a-d/Chandelier/Chandelier.Tests.cs | 26 +-- tests/indicators/a-d/Chop/Chop.Tests.cs | 24 +-- tests/indicators/a-d/Cmf/Cmf.Tests.cs | 24 +-- tests/indicators/a-d/Cmo/Cmo.Tests.cs | 20 +-- .../a-d/ConnorsRsi/ConnorsRsi.Tests.cs | 26 +-- .../a-d/Correlation/Correlation.Tests.cs | 46 +++--- tests/indicators/a-d/Dema/Dema.Tests.cs | 20 +-- tests/indicators/a-d/Doji/Doji.Tests.cs | 18 +- .../indicators/a-d/Donchian/Donchian.Tests.cs | 20 +-- tests/indicators/a-d/Dpo/Dpo.Tests.cs | 22 +-- tests/indicators/a-d/Dynamic/Dynamic.Tests.cs | 22 +-- .../indicators/e-k/ElderRay/ElderRay.Tests.cs | 22 +-- tests/indicators/e-k/Ema/Ema.Series.Tests.cs | 40 ++--- tests/indicators/e-k/Ema/Ema.Stream.Tests.cs | 8 +- tests/indicators/e-k/Epma/Epma.Tests.cs | 20 +-- tests/indicators/e-k/Fcb/Fcb.Tests.cs | 20 +-- .../FisherTransform/FisherTransform.Tests.cs | 26 +-- .../e-k/ForceIndex/ForceIndex.Tests.cs | 18 +- tests/indicators/e-k/Fractal/Fractal.Tests.cs | 18 +- tests/indicators/e-k/Gator/Gator.Tests.cs | 20 +-- .../e-k/HeikinAshi/HeikinAshi.Tests.cs | 12 +- tests/indicators/e-k/Hma/Hma.Tests.cs | 20 +-- .../e-k/HtTrendline/HtTrendline.Tests.cs | 18 +- tests/indicators/e-k/Hurst/Hurst.Tests.cs | 28 ++-- .../indicators/e-k/Ichimoku/Ichimoku.Tests.cs | 24 +-- tests/indicators/e-k/Kama/Kama.Tests.cs | 42 ++--- tests/indicators/e-k/Keltner/Keltner.Tests.cs | 20 +-- tests/indicators/e-k/Kvo/Kvo.Tests.cs | 22 +-- .../m-r/MaEnvelopes/MaEnvelopes.Tests.cs | 66 ++++---- tests/indicators/m-r/Macd/Macd.Tests.cs | 24 +-- tests/indicators/m-r/Mama/Mama.Tests.cs | 24 +-- .../indicators/m-r/Marubozu/Marubozu.Tests.cs | 18 +- tests/indicators/m-r/Mfi/Mfi.Tests.cs | 20 +-- tests/indicators/m-r/Obv/Obv.Tests.cs | 12 +- .../m-r/ParabolicSar/ParabolicSar.Tests.cs | 24 +-- .../m-r/PivotPoints/PivotPoints.Tests.cs | 86 +++++----- tests/indicators/m-r/Pivots/Pivots.Tests.cs | 32 ++-- tests/indicators/m-r/Pmo/Pmo.Tests.cs | 28 ++-- tests/indicators/m-r/Prs/Prs.Tests.cs | 40 ++--- tests/indicators/m-r/Pvo/Pvo.Tests.cs | 20 +-- tests/indicators/m-r/Renko/Renko.Tests.cs | 20 +-- tests/indicators/m-r/Roc/Roc.Tests.cs | 20 +-- tests/indicators/m-r/RocWb/RocWb.Tests.cs | 24 +-- .../m-r/RollingPivots/RollingPivots.Tests.cs | 84 +++++----- tests/indicators/m-r/Rsi/Rsi.Tests.cs | 38 ++--- tests/indicators/s-z/Slope/Slope.Tests.cs | 22 +-- .../indicators/s-z/Sma/Sma.Analysis.Tests.cs | 20 +-- tests/indicators/s-z/Sma/Sma.Series.Tests.cs | 39 ++--- tests/indicators/s-z/Sma/Sma.Stream.Tests.cs | 16 +- tests/indicators/s-z/Smi/Smi.Tests.cs | 34 ++-- tests/indicators/s-z/Smma/Smma.Tests.cs | 20 +-- .../s-z/StarcBands/StarcBands.Tests.cs | 20 +-- tests/indicators/s-z/Stc/Stc.Tests.cs | 28 ++-- tests/indicators/s-z/StdDev/StdDev.Tests.cs | 22 +-- .../StdDevChannels/StdDevChannels.Tests.cs | 28 ++-- tests/indicators/s-z/Stoch/Stoch.Tests.cs | 46 +++--- .../indicators/s-z/StochRsi/StochRsi.Tests.cs | 34 ++-- .../s-z/SuperTrend/SuperTrend.Tests.cs | 22 +-- tests/indicators/s-z/T3/T3.Tests.cs | 22 +-- tests/indicators/s-z/Tema/Tema.Tests.cs | 22 +-- tests/indicators/s-z/Tr/Tr.Tests.cs | 16 +- tests/indicators/s-z/Trix/Trix.Tests.cs | 22 +-- tests/indicators/s-z/Tsi/Tsi.Tests.cs | 42 ++--- .../s-z/UlcerIndex/UlcerIndex.Tests.cs | 30 ++-- .../indicators/s-z/Ultimate/Ultimate.Tests.cs | 24 +-- .../VolatilityStop/VolatilityStop.Tests.cs | 20 +-- tests/indicators/s-z/Vortex/Vortex.Tests.cs | 16 +- tests/indicators/s-z/Vwap/Vwap.Tests.cs | 28 ++-- tests/indicators/s-z/Vwma/Vwma.Tests.cs | 16 +- .../s-z/WilliamsR/WilliamsR.Tests.cs | 29 ++-- tests/indicators/s-z/Wma/Wma.Tests.cs | 24 +-- tests/indicators/s-z/ZigZag/ZigZag.Tests.cs | 26 +-- tests/observe/Program.cs | 33 ++-- tests/other/Convergence.Tests.cs | 151 ++++++++--------- tests/other/CustomIndicator.Tests.cs | 12 +- tests/other/PublicApi.Tests.cs | 41 ++--- tests/performance/Perf.Indicators.Series.cs | 5 +- .../Perf.Indicators.Stream.External.cs | 1 + tests/performance/Perf.Indicators.Stream.cs | 1 + tests/performance/Perf.Library.Helpers.cs | 24 +-- tests/performance/Perf.Library.Internals.cs | 6 +- .../performance/_testdata/Helper.Importer.cs | 2 +- 255 files changed, 2702 insertions(+), 2772 deletions(-) create mode 100644 Stock.Indicators.sln.DotSettings delete mode 100644 src/a-d/Adl/info.xml create mode 100644 src/s-z/SmaAnalysis/Sma.Analysis.Api.cs rename src/s-z/{Sma/Sma.Analysis.cs => SmaAnalysis/Sma.Analysis.Series.cs} (88%) diff --git a/Stock.Indicators.sln.DotSettings b/Stock.Indicators.sln.DotSettings new file mode 100644 index 000000000..73494bca2 --- /dev/null +++ b/Stock.Indicators.sln.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file diff --git a/docs/pages/utilities.md b/docs/pages/utilities.md index 40459183c..34e921c35 100644 --- a/docs/pages/utilities.md +++ b/docs/pages/utilities.md @@ -28,13 +28,9 @@ var results = quotes {% include candlepart-options.md %} -### Using tuple quotes - -`quotes.ToTupleCollection()` is a method for converting any `TQuote` collection to a simple [tuple](https://docs.microsoft.com/dotnet/csharp/language-reference/builtin-types/value-tuples) `(DateTime, double)` formatted `Collection`. Most indicators in our library will accept this tuple format. With that said, there are many indicators that also require the full OHLCV quote format, so it cannot be used universally. - ### Sort quotes -`quotes.ToSortedCollection()` sorts any collection of `TQuote` or tuple `(DateTime, double)` and returns it as a `Collection` sorted by ascending `Timestamp`. You do not need to sort quotes before using library indicators; however, if you are creating [custom indicators]({{site.baseurl}}/custom-indicators/#content) it's important to analyze `quotes` in a proper sequence. +`quotes.ToSortedCollection()` sorts any collection of `TQuote` or `ISeries` and returns it as a `Collection` sorted by ascending `Timestamp`. You do not need to sort quotes before using library indicators; however, if you are creating [custom indicators]({{site.baseurl}}/custom-indicators/#content) it's important to analyze `quotes` in a proper sequence. ### Resize quote history @@ -150,16 +146,6 @@ See [individual indicator pages]({{site.baseurl}}/indicators/#content) for infor > > 🚩 **Warning**: without a specified `removePeriods` value, this utility will reverse-engineer the pruning amount. When there are unusual results or when chaining multiple indicators, there will be an erroneous increase in the amount of pruning. If you want more certainty, use a specific number for `removePeriods`. Using this method on chained indicators without `removePeriods` is strongly discouraged. -### Using tuple results - -`results.ToTupleCollection()` converts results to a simpler `(DateTime Timestamp, double? Value)` [tuple](https://docs.microsoft.com/dotnet/csharp/language-reference/builtin-types/value-tuples) `Collection`. - -`results.ToTupleNaN()` converts results to simpler `(DateTime Timestamp, double Value)` tuple `Collection` with `null` values converted to `double.NaN`. - -`results.ToTupleChainable()` is a specialty converter used to prepare [custom indicators]({{site.baseurl}}/custom-indicators/#content) for chaining by removing `null` warmup periods and converting all remaining `null` values to `double.NaN`. - -> 🚩 **Warning**: warmup periods are pruned when using `.ToTupleChainable()`, resulting in fewer records. - ### Sort results `results.ToSortedCollection()` sorts any collection of indicator results and returns it as a `Collection` sorted by ascending `Timestamp`. Results from the library indicators are already sorted, so you'd only potentially need this if you're creating [custom indicators]({{site.baseurl}}/custom-indicators/#content). diff --git a/src/_common/Candles/Candles.Models.cs b/src/_common/Candles/Candles.Models.cs index 293595f0e..691e020de 100644 --- a/src/_common/Candles/Candles.Models.cs +++ b/src/_common/Candles/Candles.Models.cs @@ -2,7 +2,7 @@ namespace Skender.Stock.Indicators; // CANDLESTICK MODELS -public readonly record struct CandleProperties : IQuote, IReusable +public readonly record struct CandleProperties : IQuote { // base quote properties public DateTime Timestamp { get; init; } @@ -16,14 +16,14 @@ namespace Skender.Stock.Indicators; // raw sizes public decimal? Size => High - Low; - public decimal? Body => (Open > Close) ? (Open - Close) : (Close - Open); + public decimal? Body => Open > Close ? Open - Close : Close - Open; public decimal? UpperWick => High - (Open > Close ? Open : Close); public decimal? LowerWick => (Open > Close ? Close : Open) - Low; // percent sizes - public double? BodyPct => (Size != 0) ? (double?)(Body / Size) : 1; - public double? UpperWickPct => (Size != 0) ? (double?)(UpperWick / Size) : 1; - public double? LowerWickPct => (Size != 0) ? (double?)(LowerWick / Size) : 1; + public double? BodyPct => Size != 0 ? (double?)(Body / Size) : 1; + public double? UpperWickPct => Size != 0 ? (double?)(UpperWick / Size) : 1; + public double? LowerWickPct => Size != 0 ? (double?)(LowerWick / Size) : 1; // directional info public bool IsBullish => Close > Open; diff --git a/src/_common/Candles/Candles.Utilities.cs b/src/_common/Candles/Candles.Utilities.cs index aab413d36..f6f29ad03 100644 --- a/src/_common/Candles/Candles.Utilities.cs +++ b/src/_common/Candles/Candles.Utilities.cs @@ -30,7 +30,7 @@ public static IEnumerable ToCandles( internal static List ToCandleResults( this IEnumerable quotes) where TQuote : IQuote => quotes - .Select(q => new CandleResult() { + .Select(q => new CandleResult { Timestamp = q.Timestamp, Match = Match.None, Candle = q.ToCandle() diff --git a/src/_common/Enums.cs b/src/_common/Enums.cs index 403ab7d10..8e4b32356 100644 --- a/src/_common/Enums.cs +++ b/src/_common/Enums.cs @@ -8,7 +8,7 @@ namespace Skender.Stock.Indicators; /// public enum Act { - AddNew, + AddNew = 0, // default AddOld, Update, Delete, @@ -20,16 +20,16 @@ public enum Act /// public enum CandlePart { + Close = 0, // default Open, High, Low, - Close, Volume, - HL2, - HLC3, - OC2, - OHL3, - OHLC4 + Hl2, + Hlc3, + Oc2, + Ohl3, + Ohlc4 } /// @@ -37,7 +37,7 @@ public enum CandlePart /// public enum EndType { - Close = 0, + Close = 0, // default HighLow = 1 } @@ -50,7 +50,7 @@ public enum Match BullSignal = 100, BullBasis = 10, Neutral = 1, - None = 0, + None = 0, // default BearBasis = -10, BearSignal = -100, BearConfirmed = -200 @@ -61,17 +61,17 @@ public enum Match /// public enum MaType { - ALMA, - DEMA, - EPMA, - EMA, - HMA, - KAMA, - MAMA, - SMA, - SMMA, - TEMA, - WMA + Sma = 0, // default + Alma, + Dema, + Epma, + Ema, + Hma, + Kama, + Mama, + Smma, + Tema, + Wma } /// @@ -80,9 +80,9 @@ public enum MaType /// public enum PeriodSize { - Month, + Day = 0, // default Week, - Day, + Month, FourHours, TwoHours, OneHour, diff --git a/src/_common/Generics/Pruning.cs b/src/_common/Generics/Pruning.cs index ffee2082f..125cdec83 100644 --- a/src/_common/Generics/Pruning.cs +++ b/src/_common/Generics/Pruning.cs @@ -23,17 +23,17 @@ internal static List Remove( { return []; } - else - { - if (removePeriods > 0) - { - for (int i = 0; i < removePeriods; i++) - { - seriesList.RemoveAt(0); - } - } + if (removePeriods <= 0) + { return seriesList; } + + for (int i = 0; i < removePeriods; i++) + { + seriesList.RemoveAt(0); + } + + return seriesList; } } diff --git a/src/_common/Generics/Seek.cs b/src/_common/Generics/Seek.cs index 92dd645df..70727d940 100644 --- a/src/_common/Generics/Seek.cs +++ b/src/_common/Generics/Seek.cs @@ -17,20 +17,19 @@ public static class Seeking /// /// Sequence contains no matching element /// - public static TSeries? Find( + public static TSeries Find( this IEnumerable series, DateTime lookupDate) - where TSeries : ISeries => series - .First(x => x.Timestamp == lookupDate); + where TSeries : ISeries + => series.First(x => x.Timestamp == lookupDate); // TODO: add TryFind(), like TryParse() since struct won't allow null return types. // May just use this (above) with a try/catch and `bool` primary return type. // FIND INDEX by DATE public static int FindIndex( - this List series, + this List? series, DateTime lookupDate) - where TSeries : ISeries => series == null - ? -1 - : series.FindIndex(x => x.Timestamp == lookupDate); + where TSeries : ISeries + => series?.FindIndex(x => x.Timestamp == lookupDate) ?? -1; } diff --git a/src/_common/Math/NullMath.cs b/src/_common/Math/NullMath.cs index 839b3da92..19f483a9c 100644 --- a/src/_common/Math/NullMath.cs +++ b/src/_common/Math/NullMath.cs @@ -7,17 +7,17 @@ namespace Skender.Stock.Indicators; public static class NullMath { public static double? Abs(this double? value) - => (value is null) + => value is null ? null : value < 0 ? (double)-value : (double)value; public static decimal? Round(this decimal? value, int digits) - => (value is null) + => value is null ? null : Math.Round((decimal)value, digits); public static double? Round(this double? value, int digits) - => (value is null) + => value is null ? null : Math.Round((double)value, digits); @@ -31,12 +31,12 @@ public static double Null2NaN(this double? value) => value ?? double.NaN; public static double Null2NaN(this decimal? value) - => (value is null) + => value is null ? double.NaN : (double)value; public static double? NaN2Null(this double? value) - => (value is not null and double.NaN) + => value is double.NaN ? null : value; diff --git a/src/_common/Math/Numerix.cs b/src/_common/Math/Numerix.cs index b41698b0b..14d2bd607 100644 --- a/src/_common/Math/Numerix.cs +++ b/src/_common/Math/Numerix.cs @@ -13,26 +13,28 @@ public static double StdDev(this double[] values) double sd = 0; int n = values.Length; - if (n > 1) + if (n <= 1) { - double sum = 0; - for (int i = 0; i < n; i++) - { - sum += values[i]; - } - - double avg = sum / n; - - double sumSq = 0; - for (int i = 0; i < n; i++) - { - double v = values[i]; - sumSq += (v - avg) * (v - avg); - } - - sd = Math.Sqrt(sumSq / n); + return sd; } + double sum = 0; + for (int i = 0; i < n; i++) + { + sum += values[i]; + } + + double avg = sum / n; + + double sumSq = 0; + for (int i = 0; i < n; i++) + { + double v = values[i]; + sumSq += (v - avg) * (v - avg); + } + + sd = Math.Sqrt(sumSq / n); + return sd; } diff --git a/src/_common/Observables/AbstractCache.cs b/src/_common/Observables/AbstractCache.cs index 7b2ce7c53..788646587 100644 --- a/src/_common/Observables/AbstractCache.cs +++ b/src/_common/Observables/AbstractCache.cs @@ -8,8 +8,6 @@ namespace Skender.Stock.Indicators; public abstract class AbstractCache : IStreamCache where TSeries : struct, ISeries { - #region CONSTRUCTORS - /// /// Default. Use internal cache. /// @@ -17,81 +15,17 @@ protected AbstractCache() { Cache = []; } - #endregion - - # region PROPERTIES public IReadOnlyList Results => Cache; public bool IsFaulted { get; private set; } - internal List Cache { get; private set; } + internal List Cache { get; } - private TSeries LastArrival { get; set; } = new(); + private TSeries LastArrival { get; set; } private int OverflowCount { get; set; } - #endregion - - #region METHODS (UTILITIES) - - // get the cache index based on a timestamp - /// - public int FindIndex(DateTime timeStamp) - => Cache.FindIndex(x => x.Timestamp == timeStamp); - // get a segment of the cache - /// - public IReadOnlyList GetRange(int index, int count) - => Cache.GetRange(index, count); - #endregion - - #region METHODS (CLEAR CACHE) - - // clear entire cache without restore - /// - public void ClearCache() - { - // nothing to do - if (Cache.Count == 0) - { - Cache = []; - return; - } - - // reset all (with handling) - ClearCache(0); - } - - /// - public void ClearCache(DateTime fromTimestamp) - { - // start of range - int s = Cache - .FindIndex(c => c.Timestamp >= fromTimestamp); - - // something to do - if (s != -1) - { - ClearCache(s); - } - } - - /// - public void ClearCache(int fromIndex) - => ClearCache(fromIndex, toIndex: Cache.Count - 1); - - /// - /// Deletes cache entries between index range values. - /// - /// - /// This is overridden/implemented in inheriting class - /// due to unique requirement to notify subscribers. - /// - /// First element to delete - /// Last element to delete - protected abstract void ClearCache( - int fromIndex, int? toIndex = null); - #endregion #region METHODS (CACHE MANAGEMENT) @@ -111,14 +45,13 @@ protected Act CacheWithAnalysis(TSeries item) if (CheckOverflow(item) is Act.DoNothing) { return Act.DoNothing; - }; + } // DETERMINE ACTion INSTRUCTION Act act; - List cache = Cache; - int length = cache.Count; + int length = Cache.Count; // first if (length == 0) @@ -127,7 +60,7 @@ protected Act CacheWithAnalysis(TSeries item) return ModifyCache(act, item); } - TSeries last = cache[length - 1]; + TSeries last = Cache[length - 1]; // newer if (item.Timestamp > last.Timestamp) @@ -139,7 +72,7 @@ protected Act CacheWithAnalysis(TSeries item) else { // seek duplicate - int foundIndex = cache + int foundIndex = Cache .FindIndex(x => x.Timestamp == item.Timestamp); // replace duplicate @@ -166,7 +99,7 @@ protected Act PurgeWithAnalysis(TSeries item) if (CheckOverflow(item) is Act.DoNothing) { return Act.DoNothing; - }; + } // determine if record exists int foundIndex = Cache @@ -314,11 +247,11 @@ protected Act ModifyCache(Act act, TSeries item) if (OverflowCount > 100) { - string msg = """ - A repeated stream update exceeded the 100 attempt threshold. - Check and remove circular chains or check your stream provider. - Provider terminated. - """; + const string msg = """ + A repeated stream update exceeded the 100 attempt threshold. + Check and remove circular chains or check your stream provider. + Provider terminated. + """; IsFaulted = true; @@ -353,4 +286,46 @@ Provider terminated. return act; } #endregion + + #region METHODS (UTILITIES) + + // get the cache index based on a timestamp + /// + public int FindIndex(DateTime timeStamp) + => Cache.FindIndex(x => x.Timestamp == timeStamp); + + // clear entire cache without restore + /// + public void ClearCache() => ClearCache(0); + + /// + public void ClearCache(DateTime fromTimestamp) + { + // start of range + int fromIndex = Cache + .FindIndex(c => c.Timestamp >= fromTimestamp); + + // something to do + if (fromIndex != -1) + { + ClearCache(fromIndex); + } + } + + /// + public void ClearCache(int fromIndex) + => ClearCache(fromIndex, toIndex: Cache.Count - 1); + + /// + /// Deletes cache entries between index range values. + /// + /// + /// This is implemented in inheriting (provider) class + /// due to unique requirement to notify subscribers. + /// + /// First element to delete + /// Last element to delete + protected abstract void ClearCache( + int fromIndex, int toIndex); + #endregion } diff --git a/src/_common/Observables/AbstractChainInChainOut.cs b/src/_common/Observables/AbstractChainInChainOut.cs index bf7314d60..d54976c61 100644 --- a/src/_common/Observables/AbstractChainInChainOut.cs +++ b/src/_common/Observables/AbstractChainInChainOut.cs @@ -7,25 +7,20 @@ public abstract class AbstractChainInChainOut { // observer members only - #region CONSTRUCTORS - internal AbstractChainInChainOut( IChainProvider provider) { Provider = provider; } - #endregion - - #region PROPERTIES - public IChainProvider Provider { get; private set; } + public IChainProvider Provider { get; } public bool IsSubscribed => Subscription is not null; protected IDisposable? Subscription { get; set; } protected IReadOnlyList ProviderCache => Provider.Results; - #endregion + # region METHODS (OBSERVER) @@ -41,20 +36,18 @@ public void OnNext((Act, TIn) value) public void Unsubscribe() => Subscription?.Dispose(); #endregion - #region METHODS (UTILITIES) + #region METHODS (CACHE UTILITIES) - // restart subscription + /// full reset + /// public void Reinitialize() { Unsubscribe(); ClearCache(); - Subscription = Provider.Subscribe(this); } - // rebuild cache - public void RebuildCache() => RebuildCache(0); - + /// build cache from timestamp /// public void RebuildCache( DateTime fromTimestamp) @@ -68,16 +61,12 @@ public void RebuildCache( } } + /// rebuild cache from index /// public void RebuildCache(int fromIndex) - => RebuildCache(fromIndex, toIndex: Cache.Count - 1); - - // rebuild cache from index - protected override void RebuildCache( - int fromIndex, int? toIndex = null) { - ClearCache(fromIndex, toIndex); - Provider.Resend(this, fromIndex, toIndex); + ClearCache(fromIndex); + Provider.Resend(this, fromIndex); } #endregion } diff --git a/src/_common/Observables/AbstractChainInResultOut.cs b/src/_common/Observables/AbstractChainInResultOut.cs index f8b6ee81b..568cac358 100644 --- a/src/_common/Observables/AbstractChainInResultOut.cs +++ b/src/_common/Observables/AbstractChainInResultOut.cs @@ -7,25 +7,20 @@ public abstract class AbstractChainInResultOut { // observer members only - #region CONSTRUCTORS - internal AbstractChainInResultOut( IChainProvider provider) { Provider = provider; } - #endregion - - #region PROPERTIES - public IChainProvider Provider { get; private set; } + public IChainProvider Provider { get; } public bool IsSubscribed => Subscription is not null; protected IDisposable? Subscription { get; set; } protected IReadOnlyList ProviderCache => Provider.Results; - #endregion + # region METHODS (OBSERVER) @@ -41,20 +36,18 @@ public void OnNext((Act, TIn) value) public void Unsubscribe() => Subscription?.Dispose(); #endregion - #region METHODS (UTILITIES) + #region METHODS (CACHE UTILITIES) - // restart subscription + /// full reset + /// public void Reinitialize() { Unsubscribe(); ClearCache(); - Subscription = Provider.Subscribe(this); } - // rebuild cache - public void RebuildCache() => RebuildCache(0); - + /// build cache from timestamp /// public void RebuildCache( DateTime fromTimestamp) @@ -68,16 +61,12 @@ public void RebuildCache( } } + /// rebuild cache from index /// public void RebuildCache(int fromIndex) - => RebuildCache(fromIndex, toIndex: Cache.Count - 1); - - // rebuild cache from index - protected override void RebuildCache( - int fromIndex, int? toIndex = null) { - ClearCache(fromIndex, toIndex); - Provider.Resend(this, fromIndex, toIndex); + ClearCache(fromIndex); + Provider.Resend(this, fromIndex); } #endregion } diff --git a/src/_common/Observables/AbstractProvider.cs b/src/_common/Observables/AbstractProvider.cs index aa7a8776b..1cb97e11a 100644 --- a/src/_common/Observables/AbstractProvider.cs +++ b/src/_common/Observables/AbstractProvider.cs @@ -1,34 +1,7 @@ namespace Skender.Stock.Indicators; // STREAM PROVIDERS (BASE) - -#region interface variants -/// -/// Quote provider (abstract base) -/// -public abstract class AbstractQuoteProvider - : AbstractProvider, IQuoteProvider, IChainProvider - where TQuote : struct, IQuote, IReusable -{ - // string label - public override string ToString() - => $"{Cache.Count} quotes (type: {nameof(TQuote)})"; -} - -/// -/// Chainable result provider (abstract base) -/// -public abstract class AbstractChainProvider - : AbstractProvider, IChainProvider - where TReusableResult : struct, IReusable; - -/// -/// Non-chainable result provider (abstract base) -/// -public abstract class AbstractResultProvider - : AbstractProvider, IResultProvider - where TResult : struct, IResult; -#endregion +// with Quote, Chain, Result variants (at bottom) /// /// Streaming provider (abstract base) @@ -39,26 +12,20 @@ public abstract class AbstractProvider { // provider members only - # region FIELDS & PROPERTIES - - // fields + private readonly HashSet> _observers = []; - private readonly HashSet> Observers = new(); + public bool HasSubscribers => _observers.Count > 0; - // properties + public int SubscriberCount => _observers.Count; - public bool HasSubscribers => Observers.Count > 0; - - public int SubscriberCount => Observers.Count; - #endregion # region METHODS (OBSERVABLE) // subscribe observer public IDisposable Subscribe(IObserver<(Act, TSeries)> observer) { - Observers.Add(observer); - Subscription sub = new(Observers, observer); + _observers.Add(observer); + Subscription sub = new(_observers, observer); Resend(observer, act: Act.AddNew, fromIndex: 0); // catch-up new guy return sub; } @@ -66,22 +33,22 @@ public IDisposable Subscribe(IObserver<(Act, TSeries)> observer) // unsubscribe all observers public void EndTransmission() { - foreach (IObserver<(Act, TSeries)> obs in Observers.ToArray()) + foreach (IObserver<(Act, TSeries)> obs in _observers.ToArray()) { - if (Observers.Contains(obs)) + if (_observers.Contains(obs)) { obs.OnCompleted(); } } - Observers.Clear(); + _observers.Clear(); } /// - /// Sends new item to all subscribers + /// Sends TSeries item to all subscribers /// - /// - /// + /// Caching instruction + /// TSeries item to send protected void NotifyObservers(Act act, TSeries item) { // do not propogate "do nothing" acts @@ -91,11 +58,10 @@ protected void NotifyObservers(Act act, TSeries item) } // send to subscribers - List> obsList = [.. Observers]; + List> obsList = [.. _observers]; - for (int i = 0; i < obsList.Count; i++) + foreach (IObserver<(Act, TSeries)> obs in obsList) { - IObserver<(Act, TSeries)> obs = obsList[i]; obs.OnNext((act, item)); } } @@ -121,9 +87,10 @@ private class Subscription( #region METHODS (UTILITIES) - // string label + /// string label public abstract override string ToString(); + /// resend newer to an observer (from timestamp) /// public void Resend( IObserver<(Act, TSeries)> toObserver, @@ -141,42 +108,54 @@ public void Resend( Resend(toObserver, fromIndex); } - // resend to an observer + /// resend newer to an observer (from index) + /// + public void Resend( + IObserver<(Act, TSeries)> toObserver, + int fromIndex) + => Resend(toObserver, fromIndex, Cache.Count - 1); + + /// resends values in a range to a requesting observer /// public void Resend( IObserver<(Act, TSeries)> toObserver, int fromIndex, - int? toIndex = null) - => Resend(toObserver, fromIndex, default, toIndex); + int toIndex) + => Resend(toObserver, Act.AddOld, fromIndex, toIndex); - // resend to an observer (defined Act) + /// + /// Resends values in a range to a requesting observer, + /// between the provided indexes (inclusive), with a specific act. + /// + /// Subscription identity + /// Starting index, inclusive + /// Ending index, inclusive + /// Caching instruction private void Resend( IObserver<(Act, TSeries)> toObserver, - int fromIndex, Act act, + int fromIndex, int? toIndex = null) { - if (toObserver is not null && Observers.Contains(toObserver)) + if (toObserver is null || !_observers.Contains(toObserver)) { - // determine start/end of range - int fr = Math.Max(0, fromIndex); - int to = Math.Min(toIndex ?? Cache.Count, Cache.Count); + return; + } - for (int i = fr; i < to; i++) - { - toObserver.OnNext((act, Cache[i])); - } + // determine start/end of range + int fr = Math.Max(0, fromIndex); + int to = Math.Min(toIndex ?? Cache.Count, Cache.Count); + + for (int i = fr; i < to; i++) + { + toObserver.OnNext((act, Cache[i])); } } - // clears cache segment + /// clears cache segment /// - /// - /// Since upstream allows +/- offset, the arguments - /// need to be evaluated to determine start/end of range. - /// protected override void ClearCache( - int fromIndex, int? toIndex = null) + int fromIndex, int toIndex) { if (Cache.Count is 0) { @@ -185,7 +164,7 @@ protected override void ClearCache( // determine start/end of range int fr = Math.Max(fromIndex, 0); - int to = Math.Min(toIndex ?? Cache.Count - 1, Cache.Count - 1); + int to = Math.Min(toIndex, Cache.Count - 1); // delete and deliver instruction in reverse // order to prevent recursive recompositions @@ -196,13 +175,34 @@ protected override void ClearCache( NotifyObservers(act, r); } } - - /// - /// Rebuild cache from provider. - /// - /// start position - /// stop position - protected abstract void RebuildCache( - int fromIndex, int? toIndex = null); #endregion } + +#region QUOTE, CHAIN, RESULT PROVIDERS + +/// +/// Quote provider (abstract base) +/// +public abstract class AbstractQuoteProvider + : AbstractProvider, IQuoteProvider, IChainProvider + where TQuote : struct, IQuote, IReusable +{ + // string label + public override string ToString() + => $"{Cache.Count} quotes (type: {nameof(TQuote)})"; +} + +/// +/// Chainable result provider (abstract base) +/// +public abstract class AbstractChainProvider + : AbstractProvider, IChainProvider + where TReusableResult : struct, IReusable; + +/// +/// Non-chainable result provider (abstract base) +/// +public abstract class AbstractResultProvider + : AbstractProvider, IResultProvider + where TResult : struct, IResult; +#endregion diff --git a/src/_common/Observables/AbstractQuoteInChainOut.cs b/src/_common/Observables/AbstractQuoteInChainOut.cs index ada0053da..d6883e1a7 100644 --- a/src/_common/Observables/AbstractQuoteInChainOut.cs +++ b/src/_common/Observables/AbstractQuoteInChainOut.cs @@ -7,25 +7,20 @@ public abstract class AbstractQuoteInChainOut { // observer members only - #region CONSTRUCTORS - internal AbstractQuoteInChainOut( IQuoteProvider provider) { Provider = provider; } - #endregion - - # region PROPERTIES - public IQuoteProvider Provider { get; private set; } + public IQuoteProvider Provider { get; } public bool IsSubscribed => Subscription is not null; protected IDisposable? Subscription { get; set; } protected IReadOnlyList ProviderCache => Provider.Results; - #endregion + # region METHODS (OBSERVER) @@ -41,20 +36,18 @@ public void OnNext((Act, TIn) value) public void Unsubscribe() => Subscription?.Dispose(); #endregion - #region METHODS (UTILITIES) + #region METHODS (CACHE UTILITIES) - // restart subscription + /// full reset + /// public void Reinitialize() { Unsubscribe(); ClearCache(); - Subscription = Provider.Subscribe(this); } - // rebuild cache - public void RebuildCache() => RebuildCache(0); - + /// build cache from timestamp /// public void RebuildCache( DateTime fromTimestamp) @@ -68,16 +61,12 @@ public void RebuildCache( } } + /// rebuild cache from index /// public void RebuildCache(int fromIndex) - => RebuildCache(fromIndex, toIndex: Cache.Count - 1); - - // rebuild cache from index - protected override void RebuildCache( - int fromIndex, int? toIndex = null) { - ClearCache(fromIndex, toIndex); - Provider.Resend(this, fromIndex, toIndex); + ClearCache(fromIndex); + Provider.Resend(this, fromIndex); } #endregion } diff --git a/src/_common/Observables/AbstractQuoteInQuoteOut.cs b/src/_common/Observables/AbstractQuoteInQuoteOut.cs index 9b850f738..e56f4be33 100644 --- a/src/_common/Observables/AbstractQuoteInQuoteOut.cs +++ b/src/_common/Observables/AbstractQuoteInQuoteOut.cs @@ -10,25 +10,20 @@ public abstract class AbstractQuoteInQuoteOut { // observer members only - #region CONSTRUCTORS - internal AbstractQuoteInQuoteOut( IQuoteProvider provider) { Provider = provider; } - #endregion - - # region PROPERTIES - public IQuoteProvider Provider { get; private set; } + public IQuoteProvider Provider { get; } public bool IsSubscribed => Subscription is not null; protected IDisposable? Subscription { get; set; } protected IReadOnlyList ProviderCache => Provider.Results; - #endregion + # region METHODS (OBSERVER) @@ -42,19 +37,20 @@ public void OnNext((Act, TIn) value) public void OnCompleted() => Unsubscribe(); public void Unsubscribe() => Subscription?.Dispose(); + #endregion - // restart subscription + #region METHODS (CACHE UTILITIES) + + /// full reset + /// public void Reinitialize() { Unsubscribe(); ClearCache(); - Subscription = Provider.Subscribe(this); } - // rebuild cache - public void RebuildCache() => RebuildCache(0); - + /// build cache from timestamp /// public void RebuildCache( DateTime fromTimestamp) @@ -68,16 +64,12 @@ public void RebuildCache( } } + /// rebuild cache from index /// public void RebuildCache(int fromIndex) - => RebuildCache(fromIndex, toIndex: Cache.Count - 1); - - // rebuild cache from index - protected override void RebuildCache( - int fromIndex, int? toIndex = null) { - ClearCache(fromIndex, toIndex); - Provider.Resend(this, fromIndex, toIndex); + ClearCache(fromIndex); + Provider.Resend(this, fromIndex); } #endregion } diff --git a/src/_common/Observables/AbstractQuoteInResultOut.cs b/src/_common/Observables/AbstractQuoteInResultOut.cs index 6345c4c58..c632c0441 100644 --- a/src/_common/Observables/AbstractQuoteInResultOut.cs +++ b/src/_common/Observables/AbstractQuoteInResultOut.cs @@ -9,25 +9,20 @@ public abstract class AbstractQuoteInResultOut { // observer members only - #region CONSTRUCTORS - internal AbstractQuoteInResultOut( IQuoteProvider provider) { Provider = provider; } - #endregion - - # region PROPERTIES - public IQuoteProvider Provider { get; private set; } + public IQuoteProvider Provider { get; } public bool IsSubscribed => Subscription is not null; protected IDisposable? Subscription { get; set; } protected IReadOnlyList ProviderCache => Provider.Results; - #endregion + # region METHODS (OBSERVER) @@ -43,20 +38,18 @@ public void OnNext((Act, TIn) value) public void Unsubscribe() => Subscription?.Dispose(); #endregion - #region METHODS (UTILITIES) + #region METHODS (CACHE UTILITIES) - // restart subscription + /// full reset + /// public void Reinitialize() { Unsubscribe(); ClearCache(); - Subscription = Provider.Subscribe(this); } - // rebuild cache - public void RebuildCache() => RebuildCache(0); - + /// build cache from timestamp /// public void RebuildCache( DateTime fromTimestamp) @@ -70,16 +63,12 @@ public void RebuildCache( } } + /// rebuild cache from index /// public void RebuildCache(int fromIndex) - => RebuildCache(fromIndex, toIndex: Cache.Count - 1); - - // rebuild cache from index - protected override void RebuildCache( - int fromIndex, int? toIndex = null) { - ClearCache(fromIndex, toIndex); - Provider.Resend(this, fromIndex, toIndex); + ClearCache(fromIndex); + Provider.Resend(this, fromIndex); } #endregion } diff --git a/src/_common/Observables/IStreamCache.cs b/src/_common/Observables/IStreamCache.cs index b3e160ef2..43f934550 100644 --- a/src/_common/Observables/IStreamCache.cs +++ b/src/_common/Observables/IStreamCache.cs @@ -5,7 +5,7 @@ namespace Skender.Stock.Indicators; /// /// Cache of stored values and related management /// -public interface IStreamCache +public interface IStreamCache where TSeries : struct, ISeries { /// @@ -26,12 +26,6 @@ public interface IStreamCache /// Index value or -1 when not found int FindIndex(DateTime timeStamp); - /// - /// Get a segment (window) of cached values. - /// - /// - IReadOnlyList GetRange(int index, int count); // TODO: is this used? - /// /// Deletes all cached time-series records, /// without restore. When applicable, @@ -41,7 +35,7 @@ public interface IStreamCache /// For observers, if your intention is to rebuild from a provider, /// use alternate . /// - void ClearCache(); + void ClearCache() => ClearCache(0); /// /// Deletes newer cached records from point in time, diff --git a/src/_common/Observables/IStreamObserver.cs b/src/_common/Observables/IStreamObserver.cs index bb6927cd7..8a34b15d1 100644 --- a/src/_common/Observables/IStreamObserver.cs +++ b/src/_common/Observables/IStreamObserver.cs @@ -3,25 +3,46 @@ namespace Skender.Stock.Indicators; // STREAM OBSERVER INTERFACES /// -/// Observer of a streamed quote source +/// Observer of a streamed quote source. /// +/// +/// This is used internal to the library, +/// but can be implemented to build your own observers. +/// /// public interface IQuoteObserver : IStreamObserver, IObserver<(Act act, TQuote quote)> - where TQuote : struct, IQuote; + where TQuote : struct, IQuote +{ + IQuoteProvider Provider { get; } +} /// -/// Observer of a streamed chain source +/// Observer of a streamed chain source. /// -/// -public interface IChainObserver : IStreamObserver, IObserver<(Act act, TResult result)> - where TResult : struct, IReusable; +/// +/// This is used internal to the library, +/// but can be implemented to build your own observers. +/// +/// +public interface IChainObserver : IStreamObserver, IObserver<(Act act, TReusable result)> + where TReusable : struct, IReusable +{ + IChainProvider Provider { get; } +} /// -/// Observer of a unchainable result source +/// Observer of a unchainable result source. /// +/// +/// This is not used internally by the library, +/// but can be implemented to build your own observers. +/// /// public interface IResultObserver : IStreamObserver, IObserver<(Act act, TResult result)> - where TResult : struct, IResult; + where TResult : struct, IResult +{ + IResultProvider Provider { get; } +} /// /// Observer of streamed chain or quote sources @@ -42,7 +63,7 @@ public interface IStreamObserver /// Full reset of the provider subscription. /// /// This unsubscribes from the provider, - /// clears cache, cascading deletes to subscribers, + /// clears cache, cascades deletes to subscribers, /// then re-subscribes to the provider (with rebuild). /// /// @@ -57,11 +78,11 @@ public interface IStreamObserver /// This is different from . /// It does not reset the provider subscription. /// - void RebuildCache(); + void RebuildCache() => RebuildCache(0); /// - /// Reset the entire results cache from a known point in time - /// and rebuild it from provider sources, + /// Reset the entire results cache from a point in time + /// and rebuilds it from provider sources, /// with cascading updates to subscribers. /// /// @@ -71,8 +92,8 @@ public interface IStreamObserver void RebuildCache(DateTime fromTimestamp); /// - /// Reset the entire results cache from a known index position - /// and rebuild it from provider sources, + /// Reset the entire results cache from an index position + /// and rebuilds it from provider sources, /// with cascading updates to subscribers. /// /// diff --git a/src/_common/Observables/IStreamProvider.cs b/src/_common/Observables/IStreamProvider.cs index d7f79eb29..f1e9c5fc2 100644 --- a/src/_common/Observables/IStreamProvider.cs +++ b/src/_common/Observables/IStreamProvider.cs @@ -1,27 +1,7 @@ namespace Skender.Stock.Indicators; // STREAM OBSERVABLE INTERFACES (PROVIDERS) - -/// -/// Quote provider interface (observable) -/// -/// -public interface IQuoteProvider : IStreamProvider - where TQuote : struct, IQuote; - -/// -/// Chainable provider interface (observable) -/// -/// -public interface IChainProvider : IStreamProvider - where TResult : struct, IReusable; - -/// -/// Non-chainable provider interface (observable) -/// -/// -public interface IResultProvider : IStreamProvider - where TResult : struct, IResult; +// with Quote, Chain, Result variants (at bottom) /// /// Streaming provider interface (observable) @@ -46,10 +26,10 @@ public interface IStreamProvider : IObservable<(Act, TSeries)> IReadOnlyList Results { get; } /// - /// Returns a short formatted label + /// Returns a short text label /// with parameter values, e.g. EMA(10) /// - /// Indicator or quote label + /// String label string ToString(); /// @@ -58,33 +38,65 @@ public interface IStreamProvider : IObservable<(Act, TSeries)> void EndTransmission(); /// - /// Finds the index position in the cache, of the provided timestamp + /// Finds cache index position of the provided timestamp /// /// /// Index value or -1 when not found int FindIndex(DateTime timeStamp); /// - /// Resends historical cached values to a requesting observer, + /// Resends all newer values to a requesting observer, /// starting from a specific timestamp. /// - /// Subscriber identity. - /// First period to resend. + /// Subscribtion identity + /// From timestamp, inclusive void Resend( IObserver<(Act, TSeries)> toObserver, DateTime fromTimestamp); /// - /// Resends historical cached values to a requesting observer, + /// Resends all newer values to a requesting observer, /// starting at an index position. /// - /// Subscriber identity. - /// First periods to resend. - /// - /// The last period to include, or all (default). - /// + /// Subscribtion identity + /// From index, inclusive + void Resend( + IObserver<(Act, TSeries)> toObserver, + int fromIndex); + + /// + /// Resends all values in a range to a requesting observer, + /// starting and ending at an index position. + /// + /// Subscribtion identity + /// Starting index, inclusive + /// Ending index, inclusive void Resend( IObserver<(Act, TSeries)> toObserver, int fromIndex, - int? toIndex = null); + int toIndex); } + +#region QUOTE, CHAIN, RESULT PROVIDERS + +/// +/// Quote provider interface (observable) +/// +/// +public interface IQuoteProvider : IStreamProvider + where TQuote : struct, IQuote; + +/// +/// Chainable provider interface (observable) +/// +/// +public interface IChainProvider : IStreamProvider + where TResult : struct, IReusable; + +/// +/// Non-chainable provider interface (observable) +/// +/// +public interface IResultProvider : IStreamProvider + where TResult : struct, IResult; +#endregion diff --git a/src/_common/Observables/QuoteProvider.cs b/src/_common/Observables/QuoteProvider.cs index d7e475d0a..7f459aea4 100644 --- a/src/_common/Observables/QuoteProvider.cs +++ b/src/_common/Observables/QuoteProvider.cs @@ -43,12 +43,9 @@ public Act Add(TQuote quote) /// public void Add(IEnumerable quotes) { - List added = quotes - .ToSortedList(); - - for (int i = 0; i < added.Count; i++) + foreach (TQuote quote in quotes.ToSortedList()) { - Add(added[i]); + Add(quote); } } @@ -72,8 +69,4 @@ public Act Delete(TQuote quote) throw; } } - - protected override void RebuildCache( - int fromIndex, int? toIndex = null) - => throw new InvalidOperationException("Does not apply."); } diff --git a/src/_common/ObsoleteV3.cs b/src/_common/ObsoleteV3.cs index 7ed058b1a..639997250 100644 --- a/src/_common/ObsoleteV3.cs +++ b/src/_common/ObsoleteV3.cs @@ -1,6 +1,8 @@ using System.Collections.ObjectModel; using System.Diagnostics.CodeAnalysis; +// ReSharper disable all + namespace Skender.Stock.Indicators; // OBSOLETE IN v3 @@ -82,7 +84,7 @@ public static IEnumerable GetTrix( } [Obsolete("Rename `IReusableResult` to `IReusable`", true)] // v3.0.0 -public interface IReusableResult : IReusable { } +public interface IReusableResult : IReusable; [ExcludeFromCodeCoverage] [Obsolete("Rename `BasicData` to `Reusable`", true)] // v3.0.0 diff --git a/src/_common/Quotes/Quote.Aggregates.cs b/src/_common/Quotes/Quote.Aggregates.cs index ebcf24daf..8dd87abd6 100644 --- a/src/_common/Quotes/Quote.Aggregates.cs +++ b/src/_common/Quotes/Quote.Aggregates.cs @@ -12,28 +12,28 @@ public static IEnumerable Aggregate( PeriodSize newSize) where TQuote : IQuote { - if (newSize != PeriodSize.Month) - { - // parameter conversion - TimeSpan newTimeSpan = newSize.ToTimeSpan(); - - // convert - return quotes.Aggregate(newTimeSpan); - } - else // month + if (newSize == PeriodSize.Month) { return quotes - .OrderBy(x => x.Timestamp) - .GroupBy(x => new DateTime(x.Timestamp.Year, x.Timestamp.Month, 1)) - .Select(x => new Quote { - Timestamp = x.Key, - Open = x.First().Open, - High = x.Max(t => t.High), - Low = x.Min(t => t.Low), - Close = x.Last().Close, - Volume = x.Sum(t => t.Volume) - }); + .OrderBy(x => x.Timestamp) + .GroupBy(x => new DateTime(x.Timestamp.Year, x.Timestamp.Month, 1)) + .Select(x => new Quote { + Timestamp = x.Key, + Open = x.First().Open, + High = x.Max(t => t.High), + Low = x.Min(t => t.Low), + Close = x.Last().Close, + Volume = x.Sum(t => t.Volume) + }); } + + // parameter conversion + TimeSpan newTimeSpan = newSize.ToTimeSpan(); + + // convert + return quotes.Aggregate(newTimeSpan); + + // month } // aggregation (quantization) using TimeSpan diff --git a/src/_common/Quotes/Quote.Converters.cs b/src/_common/Quotes/Quote.Converters.cs index 7e1571611..f83d8c165 100644 --- a/src/_common/Quotes/Quote.Converters.cs +++ b/src/_common/Quotes/Quote.Converters.cs @@ -8,52 +8,66 @@ public static partial class QuoteUtility { private static readonly CultureInfo NativeCulture = Thread.CurrentThread.CurrentUICulture; - // DOUBLE QUOTES + /* LISTS */ - // convert to quotes in double precision - internal static QuoteD ToQuoteD( - this TQuote quote) - where TQuote : IQuote => new( - Timestamp: quote.Timestamp, - Open: (double)quote.Open, - High: (double)quote.High, - Low: (double)quote.Low, - Close: (double)quote.Close, - Volume: (double)quote.Volume); + // convert TQuote type list to built-in Quote type list + public static IReadOnlyList ToQuoteList( + this IEnumerable quotes) + where TQuote : IQuote + => quotes + .OrderBy(x => x.Timestamp) + .Select(x => x.ToQuote()) + .ToList(); + // convert TQuote type list to QuoteD type list internal static List ToQuoteD( this IEnumerable quotes) - where TQuote : IQuote => quotes - .Select(x => new QuoteD( - Timestamp: x.Timestamp, - Open: (double)x.Open, - High: (double)x.High, - Low: (double)x.Low, - Close: (double)x.Close, - Volume: (double)x.Volume)) + where TQuote : IQuote + => quotes .OrderBy(x => x.Timestamp) + .Select(x => x.ToQuoteD()) .ToList(); - // convert quoteD type list to reusable list - internal static List ToReusableList( - this List qdList, + // convert IQuote type list to Reusable list + public static IReadOnlyList ToReusableList( + this IEnumerable quotes, CandlePart candlePart) - => qdList + where TQuote : IQuote + => quotes .OrderBy(x => x.Timestamp) .Select(x => x.ToReusable(candlePart)) .ToList(); - // convert IQuote type list to reusable list - internal static List ToReusableList( - this IEnumerable quotes, + // convert QuoteD type list to Reusable list + internal static List ToReusableList( + this List qdList, CandlePart candlePart) - where TQuote : IQuote - => quotes + => qdList .OrderBy(x => x.Timestamp) .Select(x => x.ToReusable(candlePart)) .ToList(); - /* ELEMENTS */ + /* TYPES */ + + // convert any IQuote type to native Quote type + public static Quote ToQuote(this TQuote quote) + where TQuote : IQuote => new( + Timestamp: quote.Timestamp, + Open: quote.Open, + High: quote.High, + Low: quote.Low, + Close: quote.Close, + Volume: quote.Volume); + + // convert to quote in double precision + private static QuoteD ToQuoteD(this IQuote quote) + => new( + Timestamp: quote.Timestamp, + Open: (double)quote.Open, + High: (double)quote.High, + Low: (double)quote.Low, + Close: (double)quote.Close, + Volume: (double)quote.Volume); // convert TQuote element to a basic chainable class internal static Reusable ToReusable( @@ -66,14 +80,14 @@ internal static Reusable ToReusable( CandlePart.Low => new(q.Timestamp, (double)q.Low), CandlePart.Close => new(q.Timestamp, (double)q.Close), CandlePart.Volume => new(q.Timestamp, (double)q.Volume), - CandlePart.HL2 => new(q.Timestamp, (double)(q.High + q.Low) / 2), - CandlePart.HLC3 => new(q.Timestamp, (double)(q.High + q.Low + q.Close) / 3), - CandlePart.OC2 => new(q.Timestamp, (double)(q.Open + q.Close) / 2), - CandlePart.OHL3 => new(q.Timestamp, (double)(q.Open + q.High + q.Low) / 3), - CandlePart.OHLC4 => new(q.Timestamp, (double)(q.Open + q.High + q.Low + q.Close) / 4), + CandlePart.Hl2 => new(q.Timestamp, (double)(q.High + q.Low) / 2), + CandlePart.Hlc3 => new(q.Timestamp, (double)(q.High + q.Low + q.Close) / 3), + CandlePart.Oc2 => new(q.Timestamp, (double)(q.Open + q.Close) / 2), + CandlePart.Ohl3 => new(q.Timestamp, (double)(q.Open + q.High + q.Low) / 3), + CandlePart.Ohlc4 => new(q.Timestamp, (double)(q.Open + q.High + q.Low + q.Close) / 4), _ => throw new ArgumentOutOfRangeException( - nameof(candlePart), candlePart, "Invalid candlePart provided."), + nameof(candlePart), candlePart, "Invalid candlePart provided.") }; // convert quoteD element to reusable type @@ -81,18 +95,19 @@ internal static Reusable ToReusable( this QuoteD q, CandlePart candlePart) => candlePart switch { + CandlePart.Open => new(q.Timestamp, q.Open), CandlePart.High => new(q.Timestamp, q.High), CandlePart.Low => new(q.Timestamp, q.Low), CandlePart.Close => new(q.Timestamp, q.Close), CandlePart.Volume => new(q.Timestamp, q.Volume), - CandlePart.HL2 => new(q.Timestamp, (q.High + q.Low) / 2), - CandlePart.HLC3 => new(q.Timestamp, (q.High + q.Low + q.Close) / 3), - CandlePart.OC2 => new(q.Timestamp, (q.Open + q.Close) / 2), - CandlePart.OHL3 => new(q.Timestamp, (q.Open + q.High + q.Low) / 3), - CandlePart.OHLC4 => new(q.Timestamp, (q.Open + q.High + q.Low + q.Close) / 4), + CandlePart.Hl2 => new(q.Timestamp, (q.High + q.Low) / 2), + CandlePart.Hlc3 => new(q.Timestamp, (q.High + q.Low + q.Close) / 3), + CandlePart.Oc2 => new(q.Timestamp, (q.Open + q.Close) / 2), + CandlePart.Ohl3 => new(q.Timestamp, (q.Open + q.High + q.Low) / 3), + CandlePart.Ohlc4 => new(q.Timestamp, (q.Open + q.High + q.Low + q.Close) / 4), _ => throw new ArgumentOutOfRangeException( - nameof(candlePart), candlePart, "Invalid candlePart provided."), + nameof(candlePart), candlePart, "Invalid candlePart provided.") }; } diff --git a/src/_common/Quotes/Quote.Models.cs b/src/_common/Quotes/Quote.Models.cs index b26b8f1b5..5c4b8aa1f 100644 --- a/src/_common/Quotes/Quote.Models.cs +++ b/src/_common/Quotes/Quote.Models.cs @@ -11,7 +11,9 @@ namespace Skender.Stock.Indicators; /// /// /// (A) For streaming compatibility, define it as a -/// value-based type. +/// value-based type. Add +/// the keyword modifier for +/// slightly better memory performance. /// /// /// (B) For chaining compatibility ( diff --git a/src/_common/Quotes/Quote.Validation.cs b/src/_common/Quotes/Quote.Validation.cs index 30ab58d02..e8e24fdf2 100644 --- a/src/_common/Quotes/Quote.Validation.cs +++ b/src/_common/Quotes/Quote.Validation.cs @@ -30,4 +30,9 @@ public static IEnumerable Validate( return quotesList; } + + // public static TQuote Validate(TQuote quote) where TQuote : IQuote + // { + // + // } } diff --git a/src/_common/Results/Result.Utilities.cs b/src/_common/Results/Result.Utilities.cs index 81e6df677..c42279943 100644 --- a/src/_common/Results/Result.Utilities.cs +++ b/src/_common/Results/Result.Utilities.cs @@ -1,10 +1,8 @@ -using System.Collections.ObjectModel; - namespace Skender.Stock.Indicators; // RESULTS UTILITIES -public static partial class ResultUtility +public static class ResultUtility { // CONDENSE (REMOVE null and NaN results) /// diff --git a/src/_common/Use (quote converter)/Use.Stream.cs b/src/_common/Use (quote converter)/Use.Stream.cs index 91cc2187c..e9884abed 100644 --- a/src/_common/Use (quote converter)/Use.Stream.cs +++ b/src/_common/Use (quote converter)/Use.Stream.cs @@ -6,8 +6,6 @@ public class Use : AbstractQuoteInChainOut, IUse where TQuote : struct, IQuote { - #region CONSTRUCTORS - public Use( IQuoteProvider provider, CandlePart candlePart) : base(provider) @@ -19,12 +17,8 @@ public Use( ? throw new ArgumentNullException(nameof(provider)) : provider.Subscribe(this); } - #endregion - # region PROPERTIES - - public CandlePart CandlePartSelection { get; private set; } - #endregion + public CandlePart CandlePartSelection { get; } # region METHODS diff --git a/src/a-d/Adl/Adl.Api.cs b/src/a-d/Adl/Adl.Api.cs index 8eaea2d37..879522287 100644 --- a/src/a-d/Adl/Adl.Api.cs +++ b/src/a-d/Adl/Adl.Api.cs @@ -5,8 +5,17 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { // SERIES, from TQuote - /// - /// + /// + ///Accumulation / Distribution Line(ADL) is a rolling accumulation of Chaikin Money Flow Volume. + /// + ///See + /// documentation + ///for more information. + /// + /// + /// Configurable Quote type. See Guide for more information. + ///Historical price quotes. + ///Time series of ADL values. public static IEnumerable GetAdl( this IEnumerable quotes) where TQuote : IQuote diff --git a/src/a-d/Adl/Adl.Common.cs b/src/a-d/Adl/Adl.Common.cs index a3d7c0521..85956b450 100644 --- a/src/a-d/Adl/Adl.Common.cs +++ b/src/a-d/Adl/Adl.Common.cs @@ -5,7 +5,7 @@ namespace Skender.Stock.Indicators; /// See the /// Stock Indicators for .NET online guide for more information. -public static partial class Adl +public static class Adl { // increment calculation /// Get the next incremental Accumulation/Distribution Line(ADL) value. @@ -30,11 +30,11 @@ public static AdlResult Increment( double close, double volume) { - double mfm = (high == low) ? 0 : (close - low - (high - close)) / (high - low); + double mfm = high - low == 0 ? 0 : (close - low - (high - close)) / (high - low); double mfv = mfm * volume; double adl = mfv + prevAdl; - return new AdlResult( + return new( Timestamp: timestamp, Adl: adl, MoneyFlowMultiplier: mfm, diff --git a/src/a-d/Adl/Adl.Series.cs b/src/a-d/Adl/Adl.Series.cs index 7a14579d2..12d9c9f8d 100644 --- a/src/a-d/Adl/Adl.Series.cs +++ b/src/a-d/Adl/Adl.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcAdl( + private static List CalcAdl( this List qdList) { // initialize diff --git a/src/a-d/Adl/Adl.Stream.cs b/src/a-d/Adl/Adl.Stream.cs index 07652091f..bb815886c 100644 --- a/src/a-d/Adl/Adl.Stream.cs +++ b/src/a-d/Adl/Adl.Stream.cs @@ -2,7 +2,7 @@ namespace Skender.Stock.Indicators; // ACCUMULATION/DISTRIBUTION LINE (STREAM) -public partial class Adl : AbstractQuoteInChainOut, IAdl +public class Adl : AbstractQuoteInChainOut, IAdl where TQuote : struct, IQuote { #region CONSTRUCTORS diff --git a/src/a-d/Adl/info.xml b/src/a-d/Adl/info.xml deleted file mode 100644 index cb124315a..000000000 --- a/src/a-d/Adl/info.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - Accumulation/Distribution Line (ADL) is a rolling accumulation of Chaikin Money Flow Volume. - - See - documentation - for more information. - - - Configurable Quote type. See Guide for more information. - Historical price quotes. - Time series of ADL values. - - diff --git a/src/a-d/Adx/Adx.Series.cs b/src/a-d/Adx/Adx.Series.cs index 02fe473f8..fefab13e7 100644 --- a/src/a-d/Adx/Adx.Series.cs +++ b/src/a-d/Adx/Adx.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcAdx( + private static List CalcAdx( this List qdList, int lookbackPeriods) { @@ -40,7 +40,7 @@ internal static List CalcAdx( prevLow = q.Low; prevClose = q.Close; - results.Add(new AdxResult(Timestamp: q.Timestamp)); + results.Add(new(Timestamp: q.Timestamp)); continue; } @@ -69,7 +69,7 @@ internal static List CalcAdx( // skip DM initialization period if (i < lookbackPeriods) { - results.Add(new AdxResult(Timestamp: q.Timestamp)); + results.Add(new(Timestamp: q.Timestamp)); continue; } @@ -87,9 +87,9 @@ internal static List CalcAdx( } else { - trs = prevTrs - (prevTrs / lookbackPeriods) + tr; - pdm = prevPdm - (prevPdm / lookbackPeriods) + pdm1; - mdm = prevMdm - (prevMdm / lookbackPeriods) + mdm1; + trs = prevTrs - prevTrs / lookbackPeriods + tr; + pdm = prevPdm - prevPdm / lookbackPeriods + pdm1; + mdm = prevMdm - prevMdm / lookbackPeriods + mdm1; } prevTrs = trs; @@ -98,7 +98,7 @@ internal static List CalcAdx( if (trs is 0) { - results.Add(new AdxResult(Timestamp: q.Timestamp)); + results.Add(new(Timestamp: q.Timestamp)); continue; } @@ -107,18 +107,18 @@ internal static List CalcAdx( double mdi = 100 * mdm / trs; // calculate ADX - double dx = (pdi == mdi) + double dx = pdi - mdi == 0 ? 0 - : (pdi + mdi != 0) + : pdi + mdi != 0 ? 100 * Math.Abs(pdi - mdi) / (pdi + mdi) : double.NaN; double adx = double.NaN; double adxr = double.NaN; - if (i > (2 * lookbackPeriods) - 1) + if (i > 2 * lookbackPeriods - 1) { - adx = ((prevAdx * (lookbackPeriods - 1)) + dx) / lookbackPeriods; + adx = (prevAdx * (lookbackPeriods - 1) + dx) / lookbackPeriods; double priorAdx = results[i - lookbackPeriods + 1].Adx.Null2NaN(); @@ -127,7 +127,7 @@ internal static List CalcAdx( } // initial ADX - else if (i == (2 * lookbackPeriods) - 1) + else if (i == 2 * lookbackPeriods - 1) { sumDx += dx; adx = sumDx / lookbackPeriods; diff --git a/src/a-d/Adx/Adx.Utilities.cs b/src/a-d/Adx/Adx.Utilities.cs index 9f815a1ac..f6029d37e 100644 --- a/src/a-d/Adx/Adx.Utilities.cs +++ b/src/a-d/Adx/Adx.Utilities.cs @@ -12,6 +12,6 @@ public static IEnumerable RemoveWarmupPeriods( .ToList() .FindIndex(x => x.Pdi != null); - return results.Remove((2 * n) + 100); + return results.Remove(2 * n + 100); } } diff --git a/src/a-d/Alligator/Alligator.Series.cs b/src/a-d/Alligator/Alligator.Series.cs index fcc278b08..0c4f6033f 100644 --- a/src/a-d/Alligator/Alligator.Series.cs +++ b/src/a-d/Alligator/Alligator.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcAlligator( + private static List CalcAlligator( this List source, int jawPeriods, int jawOffset, @@ -29,7 +29,7 @@ List feed ? source .Cast() - .Use(CandlePart.HL2) + .Use(CandlePart.Hl2) .Cast() .ToSortedList() @@ -68,7 +68,7 @@ List feed // remaining values: SMMA else { - jaw = ((prevJaw * (jawPeriods - 1)) + feed[i - jawOffset].Value) / jawPeriods; + jaw = (prevJaw * (jawPeriods - 1) + feed[i - jawOffset].Value) / jawPeriods; } } @@ -92,7 +92,7 @@ List feed // remaining values: SMMA else { - teeth = ((prevTooth * (teethPeriods - 1)) + feed[i - teethOffset].Value) / teethPeriods; + teeth = (prevTooth * (teethPeriods - 1) + feed[i - teethOffset].Value) / teethPeriods; } } @@ -116,7 +116,7 @@ List feed // remaining values: SMMA else { - lips = ((prevLips * (lipsPeriods - 1)) + feed[i - lipsOffset].Value) / lipsPeriods; + lips = (prevLips * (lipsPeriods - 1) + feed[i - lipsOffset].Value) / lipsPeriods; } } diff --git a/src/a-d/Alligator/Alligator.Stream.cs b/src/a-d/Alligator/Alligator.Stream.cs index 8bf339e7f..2776bf44a 100644 --- a/src/a-d/Alligator/Alligator.Stream.cs +++ b/src/a-d/Alligator/Alligator.Stream.cs @@ -40,12 +40,12 @@ public Alligator( # region PROPERTIES - public int JawPeriods { get; private set; } - public int JawOffset { get; private set; } - public int TeethPeriods { get; private set; } - public int TeethOffset { get; private set; } - public int LipsPeriods { get; private set; } - public int LipsOffset { get; private set; } + public int JawPeriods { get; } + public int JawOffset { get; } + public int TeethPeriods { get; } + public int TeethOffset { get; } + public int LipsPeriods { get; } + public int LipsOffset { get; } #endregion # region METHODS @@ -97,7 +97,7 @@ protected override void OnNextArrival(Act act, TIn inbound) double sum = 0; for (int p = i - JawPeriods - JawOffset + 1; p <= i - JawOffset; p++) { - sum += ToValue(ProviderCache[p]); + sum += _toValue(ProviderCache[p]); } jaw = sum / JawPeriods; @@ -106,8 +106,8 @@ protected override void OnNextArrival(Act act, TIn inbound) // remaining values: SMMA else { - double newVal = ToValue(ProviderCache[i - JawOffset]); - jaw = ((prevJaw * (JawPeriods - 1)) + newVal) / JawPeriods; + double newVal = _toValue(ProviderCache[i - JawOffset]); + jaw = (prevJaw * (JawPeriods - 1) + newVal) / JawPeriods; } } @@ -122,7 +122,7 @@ protected override void OnNextArrival(Act act, TIn inbound) double sum = 0; for (int p = i - TeethPeriods - TeethOffset + 1; p <= i - TeethOffset; p++) { - sum += ToValue(ProviderCache[p]); + sum += _toValue(ProviderCache[p]); } teeth = sum / TeethPeriods; @@ -131,8 +131,8 @@ protected override void OnNextArrival(Act act, TIn inbound) // remaining values: SMMA else { - double newVal = ToValue(ProviderCache[i - TeethOffset]); - teeth = ((prevTooth * (TeethPeriods - 1)) + newVal) / TeethPeriods; + double newVal = _toValue(ProviderCache[i - TeethOffset]); + teeth = (prevTooth * (TeethPeriods - 1) + newVal) / TeethPeriods; } } @@ -147,7 +147,7 @@ protected override void OnNextArrival(Act act, TIn inbound) double sum = 0; for (int p = i - LipsPeriods - LipsOffset + 1; p <= i - LipsOffset; p++) { - sum += ToValue(ProviderCache[p]); + sum += _toValue(ProviderCache[p]); } lips = sum / LipsPeriods; @@ -156,8 +156,8 @@ protected override void OnNextArrival(Act act, TIn inbound) // remaining values: SMMA else { - double newVal = ToValue(ProviderCache[i - LipsOffset]); - lips = ((prevLips * (LipsPeriods - 1)) + newVal) / LipsPeriods; + double newVal = _toValue(ProviderCache[i - LipsOffset]); + lips = (prevLips * (LipsPeriods - 1) + newVal) / LipsPeriods; } } } @@ -187,8 +187,8 @@ protected override void OnNextArrival(Act act, TIn inbound) #endregion // convert provider IQuotes to HL2, if needed - private readonly Func ToValue - = (input) => input is IQuote quote - ? quote.ToReusable(CandlePart.HL2).Value + private readonly Func _toValue + = input => input is IQuote quote + ? quote.ToReusable(CandlePart.Hl2).Value : input.Value; } diff --git a/src/a-d/Alma/Alma.Series.cs b/src/a-d/Alma/Alma.Series.cs index dde7ebd54..59e6f1c75 100644 --- a/src/a-d/Alma/Alma.Series.cs +++ b/src/a-d/Alma/Alma.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcAlma( + private static List CalcAlma( this List source, int lookbackPeriods, double offset, diff --git a/src/a-d/Aroon/Aroon.Series.cs b/src/a-d/Aroon/Aroon.Series.cs index 536641949..572b55d09 100644 --- a/src/a-d/Aroon/Aroon.Series.cs +++ b/src/a-d/Aroon/Aroon.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcAroon( + private static List CalcAroon( this List qdList, int lookbackPeriods) { diff --git a/src/a-d/Atr/Atr.Series.cs b/src/a-d/Atr/Atr.Series.cs index 9c86116a9..4268e8a06 100644 --- a/src/a-d/Atr/Atr.Series.cs +++ b/src/a-d/Atr/Atr.Series.cs @@ -5,7 +5,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { // calculate series - internal static List CalcAtr( + private static List CalcAtr( this List qdList, int lookbackPeriods) { @@ -43,8 +43,8 @@ internal static List CalcAtr( if (i > lookbackPeriods) { // calculate ATR - atr = ((prevAtr * (lookbackPeriods - 1)) + tr) / lookbackPeriods; - atrp = (q.Close == 0) ? null : atr / q.Close * 100; + atr = (prevAtr * (lookbackPeriods - 1) + tr) / lookbackPeriods; + atrp = q.Close == 0 ? null : atr / q.Close * 100; prevAtr = atr; } @@ -54,7 +54,7 @@ internal static List CalcAtr( // initialize ATR sumTr += tr; atr = sumTr / lookbackPeriods; - atrp = (q.Close == 0) ? null : atr / q.Close * 100; + atrp = q.Close == 0 ? null : atr / q.Close * 100; prevAtr = atr; } diff --git a/src/a-d/AtrStop/AtrStop.Series.cs b/src/a-d/AtrStop/AtrStop.Series.cs index 63a768c5b..d0fd90fb9 100644 --- a/src/a-d/AtrStop/AtrStop.Series.cs +++ b/src/a-d/AtrStop/AtrStop.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcAtrStop( + private static List CalcAtrStop( this List qdList, int lookbackPeriods, double multiplier, @@ -42,15 +42,15 @@ internal static List CalcAtrStop( // potential bands for CLOSE if (endType == EndType.Close) { - upperEval = q.Close + (multiplier * atr); - lowerEval = q.Close - (multiplier * atr); + upperEval = q.Close + multiplier * atr; + lowerEval = q.Close - multiplier * atr; } // potential bands for HIGH/LOW else { - upperEval = q.High + (multiplier * atr); - lowerEval = q.Low - (multiplier * atr); + upperEval = q.High + multiplier * atr; + lowerEval = q.Low - multiplier * atr; } // initial values diff --git a/src/a-d/Awesome/Awesome.Series.cs b/src/a-d/Awesome/Awesome.Series.cs index eab0edc4d..3376e73b2 100644 --- a/src/a-d/Awesome/Awesome.Series.cs +++ b/src/a-d/Awesome/Awesome.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcAwesome( + private static List CalcAwesome( this List source, int fastPeriods, int slowPeriods) @@ -19,7 +19,7 @@ List feed ? source .Cast() - .Use(CandlePart.HL2) + .Use(CandlePart.Hl2) .Cast() .ToSortedList() @@ -56,8 +56,8 @@ List feed } } - oscillator = ((sumFast / fastPeriods) - (sumSlow / slowPeriods)).NaN2Null(); - normalized = (pr[i] != 0) ? 100 * oscillator / pr[i] : null; + oscillator = (sumFast / fastPeriods - sumSlow / slowPeriods).NaN2Null(); + normalized = pr[i] != 0 ? 100 * oscillator / pr[i] : null; } AwesomeResult r = new( diff --git a/src/a-d/Beta/Beta.Series.cs b/src/a-d/Beta/Beta.Series.cs index f9b29a8f7..126cfc0c3 100644 --- a/src/a-d/Beta/Beta.Series.cs +++ b/src/a-d/Beta/Beta.Series.cs @@ -5,7 +5,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { // NOTE: sequence swapped from API - internal static List CalcBeta( + private static List CalcBeta( List sourceEval, List sourceMrkt, int lookbackPeriods, @@ -40,8 +40,8 @@ internal static List CalcBeta( "Timestamp sequence does not match. Beta requires matching dates in provided quotes."); } - evalReturns[i] = prevE != 0 ? (eval.Value / prevE) - 1d : 0; - mrktReturns[i] = prevM != 0 ? (mrkt.Value / prevM) - 1d : 0; + evalReturns[i] = prevE != 0 ? eval.Value / prevE - 1d : 0; + mrktReturns[i] = prevM != 0 ? mrkt.Value / prevM - 1d : 0; prevE = eval.Value; prevM = mrkt.Value; @@ -56,7 +56,7 @@ internal static List CalcBeta( if (i < lookbackPeriods) { results.Add( - new BetaResult( + new( Timestamp: eval.Timestamp, ReturnsEval: evalReturns[i], ReturnsMrkt: mrktReturns[i])); @@ -92,12 +92,12 @@ internal static List CalcBeta( // ratio and convexity if (type == BetaType.All && betaUp != null && betaDown != null) { - ratio = (betaDown != 0) ? betaUp / betaDown : null; + ratio = betaDown != 0 ? betaUp / betaDown : null; convexity = (betaUp - betaDown) * (betaUp - betaDown); } results.Add( - new BetaResult( + new( Timestamp: eval.Timestamp, ReturnsEval: evalReturns[i], ReturnsMrkt: mrktReturns[i], @@ -131,28 +131,32 @@ internal static List CalcBeta( double a = mrktReturns[p]; double b = evalReturns[p]; - if (type is BetaType.Standard - || (type is BetaType.Down && a < 0) - || (type is BetaType.Up && a > 0)) + if (type is not BetaType.Standard + && (type is not BetaType.Down || !(a < 0)) + && (type is not BetaType.Up || !(a > 0))) { - dataA.Add(a); - dataB.Add(b); + continue; } + + dataA.Add(a); + dataB.Add(b); } - if (dataA.Count > 0) + if (dataA.Count <= 0) { - // calculate correlation, covariance, and variance - CorrResult c = PeriodCorrelation( - default, - [.. dataA], - [.. dataB]); - - // calculate beta - if (c.Covariance != null && c.VarianceA != null && c.VarianceA != 0) - { - beta = (c.Covariance / c.VarianceA).NaN2Null(); - } + return beta; + } + + // calculate correlation, covariance, and variance + CorrResult c = PeriodCorrelation( + default, + [.. dataA], + [.. dataB]); + + // calculate beta + if (c is { Covariance: not null, VarianceA: not null } && c.VarianceA != 0) + { + beta = (c.Covariance / c.VarianceA).NaN2Null(); } return beta; diff --git a/src/a-d/BollingerBands/BollingerBands.Series.cs b/src/a-d/BollingerBands/BollingerBands.Series.cs index 57add4513..96361c2fc 100644 --- a/src/a-d/BollingerBands/BollingerBands.Series.cs +++ b/src/a-d/BollingerBands/BollingerBands.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcBollingerBands( + private static List CalcBollingerBands( this List source, int lookbackPeriods, double standardDeviations) @@ -38,10 +38,10 @@ internal static List CalcBollingerBands( double? sma = (sum / lookbackPeriods).NaN2Null(); double? stdDev = window.StdDev().NaN2Null(); - double? upperBand = sma + (standardDeviations * stdDev); - double? lowerBand = sma - (standardDeviations * stdDev); + double? upperBand = sma + standardDeviations * stdDev; + double? lowerBand = sma - standardDeviations * stdDev; - results.Add(new BollingerBandsResult( + results.Add(new( Timestamp: s.Timestamp, @@ -49,11 +49,11 @@ internal static List CalcBollingerBands( UpperBand: upperBand, LowerBand: lowerBand, - PercentB: (upperBand == lowerBand) ? null + PercentB: upperBand - lowerBand == 0 ? null : (s.Value - lowerBand) / (upperBand - lowerBand), - ZScore: (stdDev == 0) ? null : (s.Value - sma) / stdDev, - Width: (sma == 0) ? null : (upperBand - lowerBand) / sma + ZScore: stdDev == 0 ? null : (s.Value - sma) / stdDev, + Width: sma == 0 ? null : (upperBand - lowerBand) / sma )); } diff --git a/src/a-d/Bop/Bop.Series.cs b/src/a-d/Bop/Bop.Series.cs index 7632ea263..892df24d2 100644 --- a/src/a-d/Bop/Bop.Series.cs +++ b/src/a-d/Bop/Bop.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcBop( + private static List CalcBop( this List qdList, int smoothPeriods) { @@ -16,8 +16,8 @@ internal static List CalcBop( List results = new(length); double[] raw = qdList - .Select(x => (x.High != x.Low) ? - ((x.Close - x.Open) / (x.High - x.Low)) : double.NaN) + .Select(x => x.High - x.Low != 0 ? + (x.Close - x.Open) / (x.High - x.Low) : double.NaN) .ToArray(); // roll through quotes @@ -36,7 +36,7 @@ internal static List CalcBop( bop = (sum / smoothPeriods).NaN2Null(); } - results.Add(new BopResult( + results.Add(new( Timestamp: qdList[i].Timestamp, Bop: bop)); } diff --git a/src/a-d/Cci/Cci.Series.cs b/src/a-d/Cci/Cci.Series.cs index 9ace7e887..cec7550eb 100644 --- a/src/a-d/Cci/Cci.Series.cs +++ b/src/a-d/Cci/Cci.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcCci( + private static List CalcCci( this List qdList, int lookbackPeriods) { @@ -44,11 +44,11 @@ internal static List CalcCci( avgDv /= lookbackPeriods; - cci = (avgDv == 0) ? null + cci = avgDv == 0 ? null : ((tp[i] - avgTp) / (0.015 * avgDv)).NaN2Null(); } - results.Add(new CciResult( + results.Add(new( Timestamp: q.Timestamp, Cci: cci)); } diff --git a/src/a-d/ChaikinOsc/ChaikinOsc.Series.cs b/src/a-d/ChaikinOsc/ChaikinOsc.Series.cs index 4c93436a1..daa4eed82 100644 --- a/src/a-d/ChaikinOsc/ChaikinOsc.Series.cs +++ b/src/a-d/ChaikinOsc/ChaikinOsc.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcChaikinOsc( + private static List CalcChaikinOsc( this List qdList, int fastPeriods, int slowPeriods) @@ -30,7 +30,7 @@ internal static List CalcChaikinOsc( EmaResult f = adlEmaFast[i]; EmaResult s = adlEmaSlow[i]; - results.Add(new ChaikinOscResult( + results.Add(new( Timestamp: a.Timestamp, MoneyFlowMultiplier: a.MoneyFlowMultiplier, MoneyFlowVolume: a.MoneyFlowVolume, diff --git a/src/a-d/Chandelier/Chandelier.Series.cs b/src/a-d/Chandelier/Chandelier.Series.cs index 338df8cf7..28e434e7c 100644 --- a/src/a-d/Chandelier/Chandelier.Series.cs +++ b/src/a-d/Chandelier/Chandelier.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcChandelier( + private static List CalcChandelier( this List qdList, int lookbackPeriods, double multiplier, @@ -46,7 +46,7 @@ internal static List CalcChandelier( } } - exit = maxHigh - (atr * multiplier); + exit = maxHigh - atr * multiplier; break; case ChandelierType.Short: @@ -61,7 +61,7 @@ internal static List CalcChandelier( } } - exit = minLow + (atr * multiplier); + exit = minLow + atr * multiplier; break; default: @@ -69,7 +69,7 @@ internal static List CalcChandelier( } } - results.Add(new ChandelierResult( + results.Add(new( Timestamp: q.Timestamp, ChandelierExit: exit)); } diff --git a/src/a-d/Chop/Chop.Series.cs b/src/a-d/Chop/Chop.Series.cs index e1ccba813..c80a338fa 100644 --- a/src/a-d/Chop/Chop.Series.cs +++ b/src/a-d/Chop/Chop.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcChop( + private static List CalcChop( this List qdList, int lookbackPeriods) { @@ -12,11 +12,6 @@ internal static List CalcChop( Chop.Validate(lookbackPeriods); // initialize - double sum; - double high; - double low; - double range; - int length = qdList.Count; List results = new(length); double[] trueHigh = new double[length]; @@ -39,9 +34,9 @@ internal static List CalcChop( if (i >= lookbackPeriods) { // reset measurements - sum = trueRange[i]; - high = trueHigh[i]; - low = trueLow[i]; + double sum = trueRange[i]; + double high = trueHigh[i]; + double low = trueLow[i]; // iterate over lookback window for (int j = 1; j < lookbackPeriods; j++) @@ -51,7 +46,7 @@ internal static List CalcChop( low = Math.Min(low, trueLow[i - j]); } - range = high - low; + double range = high - low; // calculate CHOP if (range != 0) @@ -61,7 +56,7 @@ internal static List CalcChop( } } - results.Add(new ChopResult( + results.Add(new( Timestamp: qdList[i].Timestamp, Chop: chop)); } diff --git a/src/a-d/Cmf/Cmf.Series.cs b/src/a-d/Cmf/Cmf.Series.cs index c1c14a5e0..d8c546fc1 100644 --- a/src/a-d/Cmf/Cmf.Series.cs +++ b/src/a-d/Cmf/Cmf.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcCmf( + private static List CalcCmf( this List qdList, int lookbackPeriods) { @@ -49,7 +49,7 @@ List source } } - results.Add(new CmfResult( + results.Add(new( Timestamp: adl.Timestamp, MoneyFlowMultiplier: adl.MoneyFlowMultiplier, MoneyFlowVolume: adl.MoneyFlowVolume, diff --git a/src/a-d/Cmo/Cmo.Series.cs b/src/a-d/Cmo/Cmo.Series.cs index 1111993a0..1a467286c 100644 --- a/src/a-d/Cmo/Cmo.Series.cs +++ b/src/a-d/Cmo/Cmo.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcCmo( + private static List CalcCmo( this List source, int lookbackPeriods) where T : IReusable @@ -26,7 +26,7 @@ internal static List CalcCmo( // initialize, add first records double prevValue = source[0].Value; - results.Add(new CmoResult { Timestamp = source[0].Timestamp }); + results.Add(new() { Timestamp = source[0].Timestamp }); ticks.Add((null, double.NaN)); // roll through remaining prices @@ -63,7 +63,8 @@ internal static List CalcCmo( } // up - else if (isUp == true) + + if (isUp == true) { sH += pDiff; } @@ -75,12 +76,12 @@ internal static List CalcCmo( } } - cmo = (sH + sL != 0) + cmo = sH + sL != 0 ? (100 * (sH - sL) / (sH + sL)).NaN2Null() : null; } - results.Add(new CmoResult( + results.Add(new( Timestamp: s.Timestamp, Cmo: cmo)); diff --git a/src/a-d/ConnorsRsi/ConnorsRsi.Series.cs b/src/a-d/ConnorsRsi/ConnorsRsi.Series.cs index 73bd30d7c..d2cdb3be8 100644 --- a/src/a-d/ConnorsRsi/ConnorsRsi.Series.cs +++ b/src/a-d/ConnorsRsi/ConnorsRsi.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcConnorsRsi( + private static List CalcConnorsRsi( this List source, int rsiPeriods, int streakPeriods, diff --git a/src/a-d/Correlation/Correlation.Series.cs b/src/a-d/Correlation/Correlation.Series.cs index 539795440..459c05454 100644 --- a/src/a-d/Correlation/Correlation.Series.cs +++ b/src/a-d/Correlation/Correlation.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcCorrelation( + private static List CalcCorrelation( this List sourceA, List sourceB, int lookbackPeriods) @@ -50,7 +50,7 @@ internal static List CalcCorrelation( } else { - r = new CorrResult(Timestamp: a.Timestamp); + r = new(Timestamp: a.Timestamp); } results.Add(r); @@ -70,7 +70,7 @@ private static CorrResult PeriodCorrelation( double sumB = 0; double sumA2 = 0; double sumB2 = 0; - double sumAB = 0; + double sumAb = 0; for (int i = 0; i < length; i++) { @@ -81,25 +81,25 @@ private static CorrResult PeriodCorrelation( sumB += b; sumA2 += a * a; sumB2 += b * b; - sumAB += a * b; + sumAb += a * b; } double avgA = sumA / length; double avgB = sumB / length; double avgA2 = sumA2 / length; double avgB2 = sumB2 / length; - double avgAB = sumAB / length; + double avgAb = sumAb / length; - double varA = avgA2 - (avgA * avgA); - double varB = avgB2 - (avgB * avgB); - double cov = avgAB - (avgA * avgB); + double varA = avgA2 - avgA * avgA; + double varB = avgB2 - avgB * avgB; + double cov = avgAb - avgA * avgB; double divisor = Math.Sqrt(varA * varB); - double? corr = (divisor == 0) + double? corr = divisor == 0 ? null : (cov / divisor).NaN2Null(); - return new CorrResult( + return new( Timestamp: timestamp, VarianceA: varA.NaN2Null(), VarianceB: varB.NaN2Null(), diff --git a/src/a-d/Dema/Dema.Series.cs b/src/a-d/Dema/Dema.Series.cs index 36732f7e3..8d655ff59 100644 --- a/src/a-d/Dema/Dema.Series.cs +++ b/src/a-d/Dema/Dema.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcDema( + private static List CalcDema( this List source, int lookbackPeriods) where T : IReusable @@ -51,13 +51,13 @@ internal static List CalcDema( // normal DEMA else { - ema1 = lastEma1 + (k * (s.Value - lastEma1)); - ema2 = lastEma2 + (k * (ema1 - lastEma2)); + ema1 = lastEma1 + k * (s.Value - lastEma1); + ema2 = lastEma2 + k * (ema1 - lastEma2); } - results.Add(new DemaResult( + results.Add(new( Timestamp: s.Timestamp, - Dema: ((2d * ema1) - ema2).NaN2Null())); + Dema: (2d * ema1 - ema2).NaN2Null())); lastEma1 = ema1; lastEma2 = ema2; diff --git a/src/a-d/Dema/Dema.Utilities.cs b/src/a-d/Dema/Dema.Utilities.cs index 34641fa54..bc68c5f81 100644 --- a/src/a-d/Dema/Dema.Utilities.cs +++ b/src/a-d/Dema/Dema.Utilities.cs @@ -12,6 +12,6 @@ public static IEnumerable RemoveWarmupPeriods( .ToList() .FindIndex(x => x.Dema != null) + 1; - return results.Remove((2 * n) + 100); + return results.Remove(2 * n + 100); } } diff --git a/src/a-d/Doji/Doji.Api.cs b/src/a-d/Doji/Doji.Api.cs index 9dfb7ae80..b44560a6f 100644 --- a/src/a-d/Doji/Doji.Api.cs +++ b/src/a-d/Doji/Doji.Api.cs @@ -1,9 +1,3 @@ -using System; -using System.Diagnostics; -using System.Reflection.Metadata; -using System.Runtime.InteropServices; -using System.Runtime.Intrinsics.X86; - namespace Skender.Stock.Indicators; // DOJI (API) diff --git a/src/a-d/Doji/Doji.Series.cs b/src/a-d/Doji/Doji.Series.cs index bfeca876e..1faa829c4 100644 --- a/src/a-d/Doji/Doji.Series.cs +++ b/src/a-d/Doji/Doji.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcDoji( + private static List CalcDoji( this List quotesList, double maxPriceChangePercent) where TQuote : IQuote @@ -33,7 +33,7 @@ internal static List CalcDoji( matchType = Match.Neutral; } - results.Add(new CandleResult( + results.Add(new( timestamp: q.Timestamp, quote: q, match: matchType, diff --git a/src/a-d/Donchian/Donchian.Series.cs b/src/a-d/Donchian/Donchian.Series.cs index a74bdc520..10de7c16c 100644 --- a/src/a-d/Donchian/Donchian.Series.cs +++ b/src/a-d/Donchian/Donchian.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcDonchian( + private static List CalcDonchian( this List quotesList, int lookbackPeriods) where TQuote : IQuote @@ -46,7 +46,7 @@ internal static List CalcDonchian( decimal l = lowLow; decimal c = (u + l) / 2m; - results.Add(new DonchianResult( + results.Add(new( Timestamp: q.Timestamp, UpperBand: u, LowerBand: l, diff --git a/src/a-d/Dpo/Dpo.Series.cs b/src/a-d/Dpo/Dpo.Series.cs index 2d8ac7266..2db7af319 100644 --- a/src/a-d/Dpo/Dpo.Series.cs +++ b/src/a-d/Dpo/Dpo.Series.cs @@ -5,7 +5,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { // calculate series - internal static List CalcDpo( + private static List CalcDpo( this List tpList, int lookbackPeriods) where T : IReusable @@ -15,7 +15,7 @@ internal static List CalcDpo( // initialize int length = tpList.Count; - int offset = (lookbackPeriods / 2) + 1; + int offset = lookbackPeriods / 2 + 1; List sma = tpList.GetSma(lookbackPeriods).ToList(); List results = new(length); @@ -31,7 +31,7 @@ internal static List CalcDpo( { SmaResult s = sma[i + offset]; dpoSma = s.Sma; - dpoVal = s.Sma is null ? null : (src.Value - s.Sma); + dpoVal = s.Sma is null ? null : src.Value - s.Sma; } DpoResult r = new( diff --git a/src/a-d/Dynamic/Dynamic.Series.cs b/src/a-d/Dynamic/Dynamic.Series.cs index 9568c7cba..2eb6b2cf3 100644 --- a/src/a-d/Dynamic/Dynamic.Series.cs +++ b/src/a-d/Dynamic/Dynamic.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcDynamic( + private static List CalcDynamic( this List source, int lookbackPeriods, double kFactor) @@ -35,13 +35,13 @@ internal static List CalcDynamic( // normal Dynamic else { - dyn = prevDyn + ((s.Value - prevDyn) / - (kFactor * lookbackPeriods * Math.Pow(s.Value / prevDyn, 4))); + dyn = prevDyn + (s.Value - prevDyn) / + (kFactor * lookbackPeriods * Math.Pow(s.Value / prevDyn, 4)); prevDyn = dyn; } - results.Add(new DynamicResult( + results.Add(new( Timestamp: s.Timestamp, Dynamic: dyn.NaN2Null())); } diff --git a/src/e-k/ElderRay/ElderRay.Series.cs b/src/e-k/ElderRay/ElderRay.Series.cs index 706538948..84a9a4418 100644 --- a/src/e-k/ElderRay/ElderRay.Series.cs +++ b/src/e-k/ElderRay/ElderRay.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcElderRay( + private static List CalcElderRay( this List qdList, int lookbackPeriods) { @@ -25,7 +25,7 @@ List emaResults QuoteD q = qdList[i]; EmaResult e = emaResults[i]; - results.Add(new ElderRayResult( + results.Add(new( Timestamp: e.Timestamp, Ema: e.Ema, BullPower: q.High - e.Ema, diff --git a/src/e-k/Ema/Ema.Common.cs b/src/e-k/Ema/Ema.Common.cs index cf290a4b5..4f2375346 100644 --- a/src/e-k/Ema/Ema.Common.cs +++ b/src/e-k/Ema/Ema.Common.cs @@ -15,7 +15,7 @@ public static double Increment( double k, double lastEma, double newPrice) - => lastEma + (k * (newPrice - lastEma)); + => lastEma + k * (newPrice - lastEma); /// /// diff --git a/src/e-k/Ema/Ema.Series.cs b/src/e-k/Ema/Ema.Series.cs index 67c823b0c..11ae1681a 100644 --- a/src/e-k/Ema/Ema.Series.cs +++ b/src/e-k/Ema/Ema.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcEma( + private static List CalcEma( this List source, int lookbackPeriods) where T : IReusable @@ -27,7 +27,7 @@ internal static List CalcEma( // skip incalculable periods if (i < lookbackPeriods - 1) { - results.Add(new EmaResult(Timestamp: s.Timestamp)); + results.Add(new(Timestamp: s.Timestamp)); continue; } diff --git a/src/e-k/Ema/Ema.Stream.cs b/src/e-k/Ema/Ema.Stream.cs index 0bbc17019..e7ed9e991 100644 --- a/src/e-k/Ema/Ema.Stream.cs +++ b/src/e-k/Ema/Ema.Stream.cs @@ -27,8 +27,8 @@ public Ema( # region PROPERTIES - public int LookbackPeriods { get; private set; } - public double K { get; private set; } + public int LookbackPeriods { get; } + public double K { get; } #endregion # region METHODS @@ -63,7 +63,8 @@ protected override void OnNextArrival(Act act, TIn inbound) } // normal - else if (i >= LookbackPeriods - 1) + + if (i >= LookbackPeriods - 1) { IReusable last = Cache[i - 1]; // prior EMA diff --git a/src/e-k/Epma/Epma.Series.cs b/src/e-k/Epma/Epma.Series.cs index cfae9bd00..23b6ddcf8 100644 --- a/src/e-k/Epma/Epma.Series.cs +++ b/src/e-k/Epma/Epma.Series.cs @@ -5,7 +5,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { // calculate series - internal static List CalcEpma( + private static List CalcEpma( this List source, int lookbackPeriods) where T : IReusable @@ -28,7 +28,7 @@ internal static List CalcEpma( EpmaResult r = new() { Timestamp = s.Timestamp, - Epma = ((s.Slope * (i + 1)) + s.Intercept).NaN2Null() + Epma = (s.Slope * (i + 1) + s.Intercept).NaN2Null() }; results.Add(r); diff --git a/src/e-k/Fcb/Fcb.Series.cs b/src/e-k/Fcb/Fcb.Series.cs index 535a12378..816275f27 100644 --- a/src/e-k/Fcb/Fcb.Series.cs +++ b/src/e-k/Fcb/Fcb.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcFcb( + private static List CalcFcb( this List quotesList, int windowSpan) where TQuote : IQuote @@ -35,7 +35,7 @@ internal static List CalcFcb( lowerLine = fp.FractalBull ?? lowerLine; } - results.Add(new FcbResult( + results.Add(new( Timestamp: f.Timestamp, UpperBand: upperLine, LowerBand: lowerLine)); diff --git a/src/e-k/FisherTransform/FisherTransform.Series.cs b/src/e-k/FisherTransform/FisherTransform.Series.cs index 2f1fad42a..007827ec6 100644 --- a/src/e-k/FisherTransform/FisherTransform.Series.cs +++ b/src/e-k/FisherTransform/FisherTransform.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcFisherTransform( + private static List CalcFisherTransform( this List source, int lookbackPeriods) where T : IReusable @@ -18,7 +18,7 @@ List feed ? source .Cast() - .Use(CandlePart.HL2) + .Use(CandlePart.Hl2) .Cast() .ToSortedList() @@ -52,16 +52,16 @@ List feed if (i > 0) { - xv[i] = maxPrice != minPrice - ? (0.33 * 2 * (((pr[i] - minPrice) / (maxPrice - minPrice)) - 0.5)) - + (0.67 * xv[i - 1]) + xv[i] = maxPrice - minPrice != 0 + ? 0.33 * 2 * ((pr[i] - minPrice) / (maxPrice - minPrice) - 0.5) + + 0.67 * xv[i - 1] : 0; - xv[i] = (xv[i] > 0.99) ? 0.999 : xv[i]; - xv[i] = (xv[i] < -0.99) ? -0.999 : xv[i]; + xv[i] = xv[i] > 0.99 ? 0.999 : xv[i]; + xv[i] = xv[i] < -0.99 ? -0.999 : xv[i]; - fisher = ((0.5 * Math.Log((1 + xv[i]) / (1 - xv[i]))) - + (0.5 * results[i - 1].Fisher)).NaN2Null(); + fisher = (0.5 * Math.Log((1 + xv[i]) / (1 - xv[i])) + + 0.5 * results[i - 1].Fisher).NaN2Null(); trigger = results[i - 1].Fisher; } @@ -71,7 +71,7 @@ List feed fisher = 0; } - results.Add(new FisherTransformResult( + results.Add(new( Timestamp: s.Timestamp, Trigger: trigger, Fisher: fisher)); diff --git a/src/e-k/ForceIndex/ForceIndex.Series.cs b/src/e-k/ForceIndex/ForceIndex.Series.cs index cae86cf6e..6f429f04d 100644 --- a/src/e-k/ForceIndex/ForceIndex.Series.cs +++ b/src/e-k/ForceIndex/ForceIndex.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcForceIndex( + private static List CalcForceIndex( this List qdList, int lookbackPeriods) { @@ -14,8 +14,8 @@ internal static List CalcForceIndex( // initialize int length = qdList.Count; List results = new(length); - double? prevFI = null; - double? sumRawFI = 0; + double? prevFi = null; + double? sumRawFi = 0; double k = 2d / (lookbackPeriods + 1); // skip first period @@ -31,32 +31,32 @@ internal static List CalcForceIndex( double? fi = null; // raw Force Index - double? rawFI = q.Volume * (q.Close - qdList[i - 1].Close); + double? rawFi = q.Volume * (q.Close - qdList[i - 1].Close); // calculate EMA if (i > lookbackPeriods) { - fi = prevFI + (k * (rawFI - prevFI)); + fi = prevFi + k * (rawFi - prevFi); } // initialization period // TODO: update healing, without requiring specific indexing else { - sumRawFI += rawFI; + sumRawFi += rawFi; // first EMA value if (i == lookbackPeriods) { - fi = sumRawFI / lookbackPeriods; + fi = sumRawFi / lookbackPeriods; } } - results.Add(new ForceIndexResult( + results.Add(new( Timestamp: q.Timestamp, ForceIndex: fi)); - prevFI = fi; + prevFi = fi; } return results; diff --git a/src/e-k/Fractal/Fractal.Series.cs b/src/e-k/Fractal/Fractal.Series.cs index f35c003d6..64ba0cd23 100644 --- a/src/e-k/Fractal/Fractal.Series.cs +++ b/src/e-k/Fractal/Fractal.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcFractal( + private static List CalcFractal( this List quotesList, int leftSpan, int rightSpan, @@ -30,10 +30,10 @@ internal static List CalcFractal( bool isHigh = true; bool isLow = true; - decimal evalHigh = (endType == EndType.Close) ? + decimal evalHigh = endType == EndType.Close ? q.Close : q.High; - decimal evalLow = (endType == EndType.Close) ? + decimal evalLow = endType == EndType.Close ? q.Close : q.Low; // compare today with wings @@ -48,10 +48,10 @@ internal static List CalcFractal( // evaluate wing periods TQuote wing = quotesList[p]; - decimal wingHigh = (endType == EndType.Close) ? + decimal wingHigh = endType == EndType.Close ? wing.Close : wing.High; - decimal wingLow = (endType == EndType.Close) ? + decimal wingLow = endType == EndType.Close ? wing.Close : wing.Low; if (evalHigh <= wingHigh) @@ -78,7 +78,7 @@ internal static List CalcFractal( } } - results.Add(new FractalResult( + results.Add(new( Timestamp: q.Timestamp, FractalBear: fractalBear, FractalBull: fractalBull)); diff --git a/src/e-k/Gator/Gator.Series.cs b/src/e-k/Gator/Gator.Series.cs index 195221dce..f150e5462 100644 --- a/src/e-k/Gator/Gator.Series.cs +++ b/src/e-k/Gator/Gator.Series.cs @@ -4,16 +4,16 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcGator( + private static List CalcGator( this List alligator) { // initialize int length = alligator.Count; - List results = new(); + List results = []; if (length > 0) { - results.Add(new() { Timestamp = alligator[0].Timestamp, }); + results.Add(new() { Timestamp = alligator[0].Timestamp }); } // roll through quotes @@ -22,10 +22,10 @@ internal static List CalcGator( AlligatorResult a = alligator[i]; GatorResult p = results[i - 1]; - double? upper = NullMath.Abs(a.Jaw - a.Teeth); - double? lower = -NullMath.Abs(a.Teeth - a.Lips); + double? upper = (a.Jaw - a.Teeth).Abs(); + double? lower = -(a.Teeth - a.Lips).Abs(); - results.Add(new GatorResult( + results.Add(new( Timestamp: a.Timestamp, @@ -35,11 +35,11 @@ internal static List CalcGator( // directional information UpperIsExpanding: p.Upper is not null - ? (upper > p.Upper) + ? upper > p.Upper : null, LowerIsExpanding: p.Lower is not null - ? (lower < p.Lower) + ? lower < p.Lower : null)); } diff --git a/src/e-k/HeikinAshi/HeikinAshi.Series.cs b/src/e-k/HeikinAshi/HeikinAshi.Series.cs index 3cd51e1ba..d46c54e97 100644 --- a/src/e-k/HeikinAshi/HeikinAshi.Series.cs +++ b/src/e-k/HeikinAshi/HeikinAshi.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcHeikinAshi( + private static List CalcHeikinAshi( this List quotesList) where TQuote : IQuote { diff --git a/src/e-k/Hma/Hma.Series.cs b/src/e-k/Hma/Hma.Series.cs index 4691a8e68..94d264900 100644 --- a/src/e-k/Hma/Hma.Series.cs +++ b/src/e-k/Hma/Hma.Series.cs @@ -5,7 +5,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { // calculate series - internal static List CalcHma( + private static List CalcHma( this List source, int lookbackPeriods) where T : IReusable @@ -28,14 +28,16 @@ internal static List CalcHma( WmaResult w1 = wmaN1[i]; WmaResult w2 = wmaN2[i]; - if (i >= shiftQty) + if (i < shiftQty) { - Reusable sh = new( - Timestamp: s.Timestamp, - Value: (w2.Wma.Null2NaN() * 2d) - w1.Wma.Null2NaN()); - - synthHistory.Add(sh); + continue; } + + Reusable sh = new( + Timestamp: s.Timestamp, + Value: w2.Wma.Null2NaN() * 2d - w1.Wma.Null2NaN()); + + synthHistory.Add(sh); } // add back truncated null results diff --git a/src/e-k/HtTrendline/HtTrendline.Series.cs b/src/e-k/HtTrendline/HtTrendline.Series.cs index 79fb89114..78fe38892 100644 --- a/src/e-k/HtTrendline/HtTrendline.Series.cs +++ b/src/e-k/HtTrendline/HtTrendline.Series.cs @@ -3,7 +3,7 @@ namespace Skender.Stock.Indicators; // HILBERT TRANSFORM - INSTANTANEOUS TRENDLINE (SERIES) public static partial class Indicator { - internal static List CalcHtTrendline( + private static List CalcHtTrendline( this List source) where T : IReusable { @@ -13,7 +13,7 @@ List feed ? source .Cast() - .Use(CandlePart.HL2) + .Use(CandlePart.Hl2) .Cast() .ToSortedList() @@ -33,9 +33,6 @@ List feed double[] q1 = new double[length]; // quadrature double[] i1 = new double[length]; // in-phase - double jI; - double jQ; - double[] q2 = new double[length]; // adj. quadrature double[] i2 = new double[length]; // adj. in-phase @@ -53,33 +50,33 @@ List feed if (i > 5) { - double adj = (0.075 * pd[i - 1]) + 0.54; + double adj = 0.075 * pd[i - 1] + 0.54; // smooth and detrender - sp[i] = ((4 * pr[i]) + (3 * pr[i - 1]) + (2 * pr[i - 2]) + pr[i - 3]) / 10; - dt[i] = ((0.0962 * sp[i]) + (0.5769 * sp[i - 2]) - (0.5769 * sp[i - 4]) - (0.0962 * sp[i - 6])) * adj; + sp[i] = (4 * pr[i] + 3 * pr[i - 1] + 2 * pr[i - 2] + pr[i - 3]) / 10; + dt[i] = (0.0962 * sp[i] + 0.5769 * sp[i - 2] - 0.5769 * sp[i - 4] - 0.0962 * sp[i - 6]) * adj; // in-phase and quadrature - q1[i] = ((0.0962 * dt[i]) + (0.5769 * dt[i - 2]) - (0.5769 * dt[i - 4]) - (0.0962 * dt[i - 6])) * adj; + q1[i] = (0.0962 * dt[i] + 0.5769 * dt[i - 2] - 0.5769 * dt[i - 4] - 0.0962 * dt[i - 6]) * adj; i1[i] = dt[i - 3]; // advance the phases by 90 degrees - jI = ((0.0962 * i1[i]) + (0.5769 * i1[i - 2]) - (0.5769 * i1[i - 4]) - (0.0962 * i1[i - 6])) * adj; - jQ = ((0.0962 * q1[i]) + (0.5769 * q1[i - 2]) - (0.5769 * q1[i - 4]) - (0.0962 * q1[i - 6])) * adj; + double jI = (0.0962 * i1[i] + 0.5769 * i1[i - 2] - 0.5769 * i1[i - 4] - 0.0962 * i1[i - 6]) * adj; + double jQ = (0.0962 * q1[i] + 0.5769 * q1[i - 2] - 0.5769 * q1[i - 4] - 0.0962 * q1[i - 6]) * adj; // phasor addition for 3-bar averaging i2[i] = i1[i] - jQ; q2[i] = q1[i] + jI; - i2[i] = (0.2 * i2[i]) + (0.8 * i2[i - 1]); // smoothing it - q2[i] = (0.2 * q2[i]) + (0.8 * q2[i - 1]); + i2[i] = 0.2 * i2[i] + 0.8 * i2[i - 1]; // smoothing it + q2[i] = 0.2 * q2[i] + 0.8 * q2[i - 1]; // homodyne discriminator - re[i] = (i2[i] * i2[i - 1]) + (q2[i] * q2[i - 1]); - im[i] = (i2[i] * q2[i - 1]) - (q2[i] * i2[i - 1]); + re[i] = i2[i] * i2[i - 1] + q2[i] * q2[i - 1]; + im[i] = i2[i] * q2[i - 1] - q2[i] * i2[i - 1]; - re[i] = (0.2 * re[i]) + (0.8 * re[i - 1]); // smoothing it - im[i] = (0.2 * im[i]) + (0.8 * im[i - 1]); + re[i] = 0.2 * re[i] + 0.8 * re[i - 1]; // smoothing it + im[i] = 0.2 * im[i] + 0.8 * im[i - 1]; // calculate period pd[i] = im[i] != 0 && re[i] != 0 @@ -87,14 +84,14 @@ List feed : 0d; // adjust period to thresholds - pd[i] = (pd[i] > 1.5 * pd[i - 1]) ? 1.5 * pd[i - 1] : pd[i]; - pd[i] = (pd[i] < 0.67 * pd[i - 1]) ? 0.67 * pd[i - 1] : pd[i]; - pd[i] = (pd[i] < 6d) ? 6d : pd[i]; - pd[i] = (pd[i] > 50d) ? 50d : pd[i]; + pd[i] = pd[i] > 1.5 * pd[i - 1] ? 1.5 * pd[i - 1] : pd[i]; + pd[i] = pd[i] < 0.67 * pd[i - 1] ? 0.67 * pd[i - 1] : pd[i]; + pd[i] = pd[i] < 6d ? 6d : pd[i]; + pd[i] = pd[i] > 50d ? 50d : pd[i]; // smooth the period - pd[i] = (0.2 * pd[i]) + (0.8 * pd[i - 1]); - sd[i] = (0.33 * pd[i]) + (0.67 * sd[i - 1]); + pd[i] = 0.2 * pd[i] + 0.8 * pd[i - 1]; + sd[i] = 0.33 * pd[i] + 0.67 * sd[i - 1]; // smooth dominant cycle period int dcPeriods = (int)(double.IsNaN(sd[i]) ? 0 : sd[i] + 0.5); @@ -116,22 +113,22 @@ List feed it[i] = dcPeriods > 0 ? sumPr / dcPeriods : pr[i]; // final indicators - results.Add(new HtlResult( + results.Add(new( Timestamp: s.Timestamp, DcPeriods: dcPeriods > 0 ? dcPeriods : null, Trendline: i >= 11 // 12th bar - ? (((4 * it[i]) + (3 * it[i - 1]) + (2 * it[i - 2]) + it[i - 3]) / 10d).NaN2Null() + ? ((4 * it[i] + 3 * it[i - 1] + 2 * it[i - 2] + it[i - 3]) / 10d).NaN2Null() : pr[i].NaN2Null(), - SmoothPrice: (((4 * pr[i]) + (3 * pr[i - 1]) + (2 * pr[i - 2]) + pr[i - 3]) / 10d).NaN2Null())); + SmoothPrice: ((4 * pr[i] + 3 * pr[i - 1] + 2 * pr[i - 2] + pr[i - 3]) / 10d).NaN2Null())); } // initialization period else { - results.Add(new HtlResult( + results.Add(new( Timestamp: s.Timestamp, DcPeriods: null, Trendline: pr[i].NaN2Null(), diff --git a/src/e-k/Hurst/Hurst.Series.cs b/src/e-k/Hurst/Hurst.Series.cs index 887e7d5b1..1c69773d1 100644 --- a/src/e-k/Hurst/Hurst.Series.cs +++ b/src/e-k/Hurst/Hurst.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcHurst( + private static List CalcHurst( this List source, int lookbackPeriods) where T : IReusable @@ -35,7 +35,7 @@ internal static List CalcHurst( T ps = source[p]; // return values - values[x] = l != 0 ? (ps.Value / l) - 1 : double.NaN; + values[x] = l != 0 ? ps.Value / l - 1 : double.NaN; l = ps.Value; x++; @@ -45,7 +45,7 @@ internal static List CalcHurst( h = CalcHurstWindow(values).NaN2Null(); } - results.Add(new HurstResult( + results.Add(new( Timestamp: s.Timestamp, HurstExponent: h)); } @@ -89,7 +89,7 @@ private static double CalcHurstWindow(double[] values) // starting index position used to skip // observations to enforce same-sized chunks - int startIndex = totalSize - (chunkSize * chunkQty); + int startIndex = totalSize - chunkSize * chunkQty; // analyze chunks in set for (int chunkNum = 1; chunkNum <= chunkQty; chunkNum++) @@ -112,8 +112,8 @@ private static double CalcHurstWindow(double[] values) { double y = values[i] - chunkMean; sumY += y; - minY = (sumY < minY) ? sumY : minY; - maxY = (sumY > maxY) ? sumY : maxY; + minY = sumY < minY ? sumY : minY; + maxY = sumY > maxY ? sumY : maxY; sumSq += y * y; } diff --git a/src/e-k/Ichimoku/Ichimoku.Series.cs b/src/e-k/Ichimoku/Ichimoku.Series.cs index b697d3b40..520286eac 100644 --- a/src/e-k/Ichimoku/Ichimoku.Series.cs +++ b/src/e-k/Ichimoku/Ichimoku.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcIchimoku( + private static List CalcIchimoku( this List quotesList, int tenkanPeriods, int kijunPeriods, @@ -70,7 +70,7 @@ internal static List CalcIchimoku( chikouSpan = quotesList[i + chikouOffset].Close; } - results.Add(new IchimokuResult( + results.Add(new( Timestamp: q.Timestamp, TenkanSen: tenkanSen, KijunSen: kijunSen, @@ -86,30 +86,31 @@ internal static List CalcIchimoku( int i, List quotesList, int tenkanPeriods) where TQuote : IQuote { - if (i >= tenkanPeriods - 1) + if (i < tenkanPeriods - 1) { - decimal max = 0; - decimal min = decimal.MaxValue; + return null; + } - for (int p = i - tenkanPeriods + 1; p <= i; p++) - { - TQuote d = quotesList[p]; + decimal max = 0; + decimal min = decimal.MaxValue; - if (d.High > max) - { - max = d.High; - } + for (int p = i - tenkanPeriods + 1; p <= i; p++) + { + TQuote d = quotesList[p]; - if (d.Low < min) - { - min = d.Low; - } + if (d.High > max) + { + max = d.High; } - return (min == decimal.MaxValue) ? null : (min + max) / 2; + if (d.Low < min) + { + min = d.Low; + } } - return null; + return min == decimal.MaxValue ? null : (min + max) / 2; + } private static decimal? CalcIchimokuKijunSen( @@ -118,30 +119,30 @@ internal static List CalcIchimoku( int kijunPeriods) where TQuote : IQuote { - if (i >= kijunPeriods - 1) + if (i < kijunPeriods - 1) { - decimal max = 0; - decimal min = decimal.MaxValue; + return null; + } - for (int p = i - kijunPeriods + 1; p <= i; p++) - { - TQuote d = quotesList[p]; + decimal max = 0; + decimal min = decimal.MaxValue; - if (d.High > max) - { - max = d.High; - } + for (int p = i - kijunPeriods + 1; p <= i; p++) + { + TQuote d = quotesList[p]; - if (d.Low < min) - { - min = d.Low; - } + if (d.High > max) + { + max = d.High; } - return (min == decimal.MaxValue) ? null : (min + max) / 2; + if (d.Low < min) + { + min = d.Low; + } } - return null; + return min == decimal.MaxValue ? null : (min + max) / 2; } private static decimal? CalcIchimokuSenkouB( @@ -151,30 +152,30 @@ internal static List CalcIchimoku( int senkouBPeriods) where TQuote : IQuote { - if (i >= senkouOffset + senkouBPeriods - 1) + if (i < senkouOffset + senkouBPeriods - 1) { - decimal max = 0; - decimal min = decimal.MaxValue; + return null; + } - for (int p = i - senkouOffset - senkouBPeriods + 1; - p <= i - senkouOffset; p++) - { - TQuote d = quotesList[p]; + decimal max = 0; + decimal min = decimal.MaxValue; - if (d.High > max) - { - max = d.High; - } + for (int p = i - senkouOffset - senkouBPeriods + 1; + p <= i - senkouOffset; p++) + { + TQuote d = quotesList[p]; - if (d.Low < min) - { - min = d.Low; - } + if (d.High > max) + { + max = d.High; } - return (min == decimal.MaxValue) ? null : (min + max) / 2; + if (d.Low < min) + { + min = d.Low; + } } - return null; + return min == decimal.MaxValue ? null : (min + max) / 2; } } diff --git a/src/e-k/Kama/Kama.Models.cs b/src/e-k/Kama/Kama.Models.cs index 2e7a80a0b..dd0f17ba7 100644 --- a/src/e-k/Kama/Kama.Models.cs +++ b/src/e-k/Kama/Kama.Models.cs @@ -3,7 +3,7 @@ namespace Skender.Stock.Indicators; public readonly record struct KamaResult ( DateTime Timestamp, - double? ER, + double? Er, double? Kama ) : IReusable { diff --git a/src/e-k/Kama/Kama.Series.cs b/src/e-k/Kama/Kama.Series.cs index c42076333..6ab58aa02 100644 --- a/src/e-k/Kama/Kama.Series.cs +++ b/src/e-k/Kama/Kama.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcKama( + private static List CalcKama( this List source, int erPeriods, int fastPeriods, @@ -49,22 +49,22 @@ internal static List CalcKama( double change = Math.Abs(s.Value - source[i - erPeriods].Value); // volatility - double sumPV = 0; + double sumPv = 0; for (int p = i - erPeriods + 1; p <= i; p++) { - sumPV += Math.Abs(source[p].Value - source[p - 1].Value); + sumPv += Math.Abs(source[p].Value - source[p - 1].Value); } - if (sumPV != 0) + if (sumPv != 0) { // efficiency ratio - er = change / sumPV; + er = change / sumPv; // smoothing constant - double sc = (er * (scFast - scSlow)) + scSlow; // squared later + double sc = er * (scFast - scSlow) + scSlow; // squared later // kama calculation - kama = prevKama + (sc * sc * (s.Value - prevKama)); + kama = prevKama + sc * sc * (s.Value - prevKama); } // handle flatline case @@ -75,9 +75,9 @@ internal static List CalcKama( } } - results.Add(new KamaResult( + results.Add(new( Timestamp: s.Timestamp, - ER: er.NaN2Null(), + Er: er.NaN2Null(), Kama: kama.NaN2Null())); prevKama = kama; diff --git a/src/e-k/Kama/Kama.Utilities.cs b/src/e-k/Kama/Kama.Utilities.cs index 2e3493944..ba757e4ff 100644 --- a/src/e-k/Kama/Kama.Utilities.cs +++ b/src/e-k/Kama/Kama.Utilities.cs @@ -10,7 +10,7 @@ public static IEnumerable RemoveWarmupPeriods( { int erPeriods = results .ToList() - .FindIndex(x => x.ER != null); + .FindIndex(x => x.Er != null); return results.Remove(Math.Max(erPeriods + 100, 10 * erPeriods)); } diff --git a/src/e-k/Keltner/Keltner.Series.cs b/src/e-k/Keltner/Keltner.Series.cs index 6bb0ace4a..5589993a0 100644 --- a/src/e-k/Keltner/Keltner.Series.cs +++ b/src/e-k/Keltner/Keltner.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcKeltner( + private static List CalcKeltner( this List qdList, int emaPeriods, double multiplier, @@ -38,12 +38,12 @@ internal static List CalcKeltner( AtrResult atr = atrResults[i]; double? atrSpan = atr.Atr * multiplier; - results.Add(new KeltnerResult( + results.Add(new( Timestamp: q.Timestamp, UpperBand: ema.Ema + atrSpan, LowerBand: ema.Ema - atrSpan, Centerline: ema.Ema, - Width: (ema.Ema == 0) ? null : 2 * atrSpan / ema.Ema)); + Width: ema.Ema == 0 ? null : 2 * atrSpan / ema.Ema)); } else { diff --git a/src/e-k/Kvo/Kvo.Series.cs b/src/e-k/Kvo/Kvo.Series.cs index d51c87a24..79936d372 100644 --- a/src/e-k/Kvo/Kvo.Series.cs +++ b/src/e-k/Kvo/Kvo.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcKvo( + private static List CalcKvo( this List qdList, int fastPeriods, int slowPeriods, @@ -51,7 +51,7 @@ internal static List CalcKvo( } // trend direction - t[i] = (hlc[i] > hlc[i - 1]) ? 1 : -1; + t[i] = hlc[i] > hlc[i - 1] ? 1 : -1; if (i <= 1) { @@ -61,19 +61,19 @@ internal static List CalcKvo( } // cumulative measurement - cm[i] = (t[i] == t[i - 1]) ? - (cm[i - 1] + dm[i]) : (dm[i - 1] + dm[i]); + cm[i] = t[i] == t[i - 1] ? + cm[i - 1] + dm[i] : dm[i - 1] + dm[i]; // volume force (VF) - vf[i] = (dm[i] == cm[i] || q.Volume == 0) ? 0 - : (dm[i] == 0) ? q.Volume * 2d * t[i] * 100d - : (cm[i] != 0) ? q.Volume * Math.Abs(2d * ((dm[i] / cm[i]) - 1)) * t[i] * 100d + vf[i] = dm[i] == cm[i] || q.Volume == 0 ? 0 + : dm[i] == 0 ? q.Volume * 2d * t[i] * 100d + : cm[i] != 0 ? q.Volume * Math.Abs(2d * (dm[i] / cm[i] - 1)) * t[i] * 100d : vf[i - 1]; // fast-period EMA of VF if (i > fastPeriods + 1) { - vfFastEma[i] = (vf[i] * kFast) + (vfFastEma[i - 1] * (1 - kFast)); + vfFastEma[i] = vf[i] * kFast + vfFastEma[i - 1] * (1 - kFast); } // TODO: update healing, without requiring specific indexing @@ -91,7 +91,7 @@ internal static List CalcKvo( // slow-period EMA of VF if (i > slowPeriods + 1) { - vfSlowEma[i] = (vf[i] * kSlow) + (vfSlowEma[i - 1] * (1 - kSlow)); + vfSlowEma[i] = vf[i] * kSlow + vfSlowEma[i - 1] * (1 - kSlow); } // TODO: update healing, without requiring specific indexing @@ -114,8 +114,8 @@ internal static List CalcKvo( // Signal if (i > slowPeriods + signalPeriods) { - sig = (kvo * kSignal) - + (results[i - 1].Signal * (1 - kSignal)); + sig = kvo * kSignal + + results[i - 1].Signal * (1 - kSignal); } // TODO: update healing, without requiring specific indexing @@ -131,7 +131,7 @@ internal static List CalcKvo( } } - results.Add(new KvoResult( + results.Add(new( Timestamp: q.Timestamp, Oscillator: kvo, Signal: sig)); diff --git a/src/m-r/MaEnvelopes/MaEnvelopes.Api.cs b/src/m-r/MaEnvelopes/MaEnvelopes.Api.cs index 39e32525a..ae66bdbe9 100644 --- a/src/m-r/MaEnvelopes/MaEnvelopes.Api.cs +++ b/src/m-r/MaEnvelopes/MaEnvelopes.Api.cs @@ -8,7 +8,7 @@ public static IEnumerable GetMaEnvelopes( this IEnumerable results, int lookbackPeriods, double percentOffset = 2.5, - MaType movingAverageType = MaType.SMA) + MaType movingAverageType = MaType.Sma) where T : IReusable => results .ToSortedList() diff --git a/src/m-r/MaEnvelopes/MaEnvelopes.Series.cs b/src/m-r/MaEnvelopes/MaEnvelopes.Series.cs index 476cee016..3c1ad9b53 100644 --- a/src/m-r/MaEnvelopes/MaEnvelopes.Series.cs +++ b/src/m-r/MaEnvelopes/MaEnvelopes.Series.cs @@ -5,8 +5,8 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { // calculate series - internal static IEnumerable CalcMaEnvelopes( - this List tpList, + private static IEnumerable CalcMaEnvelopes( + this List source, int lookbackPeriods, double percentOffset, MaType movingAverageType) @@ -21,15 +21,15 @@ internal static IEnumerable CalcMaEnvelopes( // get envelopes variant return movingAverageType switch { - MaType.ALMA => tpList.MaEnvAlma(lookbackPeriods, offsetRatio), - MaType.DEMA => tpList.MaEnvDema(lookbackPeriods, offsetRatio), - MaType.EMA => tpList.MaEnvEma(lookbackPeriods, offsetRatio), - MaType.EPMA => tpList.MaEnvEpma(lookbackPeriods, offsetRatio), - MaType.HMA => tpList.MaEnvHma(lookbackPeriods, offsetRatio), - MaType.SMA => tpList.MaEnvSma(lookbackPeriods, offsetRatio), - MaType.SMMA => tpList.MaEnvSmma(lookbackPeriods, offsetRatio), - MaType.TEMA => tpList.MaEnvTema(lookbackPeriods, offsetRatio), - MaType.WMA => tpList.MaEnvWma(lookbackPeriods, offsetRatio), + MaType.Alma => source.MaEnvAlma(lookbackPeriods, offsetRatio), + MaType.Dema => source.MaEnvDema(lookbackPeriods, offsetRatio), + MaType.Ema => source.MaEnvEma(lookbackPeriods, offsetRatio), + MaType.Epma => source.MaEnvEpma(lookbackPeriods, offsetRatio), + MaType.Hma => source.MaEnvHma(lookbackPeriods, offsetRatio), + MaType.Sma => source.MaEnvSma(lookbackPeriods, offsetRatio), + MaType.Smma => source.MaEnvSmma(lookbackPeriods, offsetRatio), + MaType.Tema => source.MaEnvTema(lookbackPeriods, offsetRatio), + MaType.Wma => source.MaEnvWma(lookbackPeriods, offsetRatio), _ => throw new ArgumentOutOfRangeException( nameof(movingAverageType), movingAverageType, @@ -41,95 +41,95 @@ internal static IEnumerable CalcMaEnvelopes( } private static IEnumerable MaEnvAlma( - this List tpList, + this List source, int lookbackPeriods, double offsetRatio) where T : IReusable - => tpList.GetAlma(lookbackPeriods) + => source.GetAlma(lookbackPeriods) .Select(x => new MaEnvelopeResult { Timestamp = x.Timestamp, Centerline = x.Alma, - UpperEnvelope = x.Alma + (x.Alma * offsetRatio), - LowerEnvelope = x.Alma - (x.Alma * offsetRatio) + UpperEnvelope = x.Alma + x.Alma * offsetRatio, + LowerEnvelope = x.Alma - x.Alma * offsetRatio }); private static IEnumerable MaEnvDema( - this List tpList, + this List source, int lookbackPeriods, double offsetRatio) where T : IReusable - => tpList.GetDema(lookbackPeriods) + => source.GetDema(lookbackPeriods) .Select(x => new MaEnvelopeResult { Timestamp = x.Timestamp, Centerline = x.Dema, - UpperEnvelope = x.Dema + (x.Dema * offsetRatio), - LowerEnvelope = x.Dema - (x.Dema * offsetRatio) + UpperEnvelope = x.Dema + x.Dema * offsetRatio, + LowerEnvelope = x.Dema - x.Dema * offsetRatio }); private static IEnumerable MaEnvEma( - this List tpList, + this List source, int lookbackPeriods, double offsetRatio) where T : IReusable - => tpList + => source .GetEma(lookbackPeriods) .Select(x => new MaEnvelopeResult { Timestamp = x.Timestamp, Centerline = x.Ema, - UpperEnvelope = x.Ema + (x.Ema * offsetRatio), - LowerEnvelope = x.Ema - (x.Ema * offsetRatio) + UpperEnvelope = x.Ema + x.Ema * offsetRatio, + LowerEnvelope = x.Ema - x.Ema * offsetRatio }); private static IEnumerable MaEnvEpma( - this List tpList, + this List source, int lookbackPeriods, double offsetRatio) where T : IReusable - => tpList.GetEpma(lookbackPeriods) + => source.GetEpma(lookbackPeriods) .Select(x => new MaEnvelopeResult { Timestamp = x.Timestamp, Centerline = x.Epma, - UpperEnvelope = x.Epma + (x.Epma * offsetRatio), - LowerEnvelope = x.Epma - (x.Epma * offsetRatio) + UpperEnvelope = x.Epma + x.Epma * offsetRatio, + LowerEnvelope = x.Epma - x.Epma * offsetRatio }); private static IEnumerable MaEnvHma( - this List tpList, + this List source, int lookbackPeriods, double offsetRatio) where T : IReusable - => tpList.GetHma(lookbackPeriods) + => source.GetHma(lookbackPeriods) .Select(x => new MaEnvelopeResult { Timestamp = x.Timestamp, Centerline = x.Hma, - UpperEnvelope = x.Hma + (x.Hma * offsetRatio), - LowerEnvelope = x.Hma - (x.Hma * offsetRatio) + UpperEnvelope = x.Hma + x.Hma * offsetRatio, + LowerEnvelope = x.Hma - x.Hma * offsetRatio }); private static IEnumerable MaEnvSma( - this List tpList, + this List source, int lookbackPeriods, double offsetRatio) where T : IReusable - => tpList.GetSma(lookbackPeriods) + => source.GetSma(lookbackPeriods) .Select(x => new MaEnvelopeResult { Timestamp = x.Timestamp, Centerline = x.Sma, - UpperEnvelope = x.Sma + (x.Sma * offsetRatio), - LowerEnvelope = x.Sma - (x.Sma * offsetRatio) + UpperEnvelope = x.Sma + x.Sma * offsetRatio, + LowerEnvelope = x.Sma - x.Sma * offsetRatio }); private static IEnumerable MaEnvSmma( - this List tpList, + this List source, int lookbackPeriods, double offsetRatio) where T : IReusable - => tpList.GetSmma(lookbackPeriods) + => source.GetSmma(lookbackPeriods) .Select(x => new MaEnvelopeResult { Timestamp = x.Timestamp, Centerline = x.Smma, - UpperEnvelope = x.Smma + (x.Smma * offsetRatio), - LowerEnvelope = x.Smma - (x.Smma * offsetRatio) + UpperEnvelope = x.Smma + x.Smma * offsetRatio, + LowerEnvelope = x.Smma - x.Smma * offsetRatio }); private static IEnumerable MaEnvTema( @@ -141,8 +141,8 @@ private static IEnumerable MaEnvTema( .Select(x => new MaEnvelopeResult { Timestamp = x.Timestamp, Centerline = x.Tema, - UpperEnvelope = x.Tema + (x.Tema * offsetRatio), - LowerEnvelope = x.Tema - (x.Tema * offsetRatio) + UpperEnvelope = x.Tema + x.Tema * offsetRatio, + LowerEnvelope = x.Tema - x.Tema * offsetRatio }); private static IEnumerable MaEnvWma( @@ -154,7 +154,7 @@ private static IEnumerable MaEnvWma( .Select(x => new MaEnvelopeResult { Timestamp = x.Timestamp, Centerline = x.Wma, - UpperEnvelope = x.Wma + (x.Wma * offsetRatio), - LowerEnvelope = x.Wma - (x.Wma * offsetRatio) + UpperEnvelope = x.Wma + x.Wma * offsetRatio, + LowerEnvelope = x.Wma - x.Wma * offsetRatio }); } diff --git a/src/m-r/Macd/Macd.Series.cs b/src/m-r/Macd/Macd.Series.cs index bcb63ea2c..f103a121d 100644 --- a/src/m-r/Macd/Macd.Series.cs +++ b/src/m-r/Macd/Macd.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcMacd( + private static List CalcMacd( this List source, int fastPeriods, int slowPeriods, @@ -93,7 +93,7 @@ internal static List CalcMacd( } // write results - results.Add(new MacdResult( + results.Add(new( Timestamp: s.Timestamp, Macd: macd.NaN2Null(), Signal: signal.NaN2Null(), diff --git a/src/m-r/Mama/Mama.Series.cs b/src/m-r/Mama/Mama.Series.cs index 4ae9954f0..83178ea06 100644 --- a/src/m-r/Mama/Mama.Series.cs +++ b/src/m-r/Mama/Mama.Series.cs @@ -3,7 +3,7 @@ namespace Skender.Stock.Indicators; // MOTHER of ADAPTIVE MOVING AVERAGES (SERIES) public static partial class Indicator { - internal static List CalcMama( + private static List CalcMama( this List source, double fastLimit, double slowLimit) @@ -15,7 +15,7 @@ List feed ? source .Cast() - .Use(CandlePart.HL2) + .Use(CandlePart.Hl2) .Cast() .ToSortedList() @@ -41,9 +41,6 @@ List feed double[] q1 = new double[length]; // quadrature double[] i1 = new double[length]; // in-phase - double jI; - double jQ; - double[] q2 = new double[length]; // adj. quadrature double[] i2 = new double[length]; // adj. in-phase @@ -97,33 +94,33 @@ List feed // normal MAMA else { - double adj = (0.075 * pd[i - 1]) + 0.54; + double adj = 0.075 * pd[i - 1] + 0.54; // smooth and detrender - sm[i] = ((4 * pr[i]) + (3 * pr[i - 1]) + (2 * pr[i - 2]) + pr[i - 3]) / 10; - dt[i] = ((0.0962 * sm[i]) + (0.5769 * sm[i - 2]) - (0.5769 * sm[i - 4]) - (0.0962 * sm[i - 6])) * adj; + sm[i] = (4 * pr[i] + 3 * pr[i - 1] + 2 * pr[i - 2] + pr[i - 3]) / 10; + dt[i] = (0.0962 * sm[i] + 0.5769 * sm[i - 2] - 0.5769 * sm[i - 4] - 0.0962 * sm[i - 6]) * adj; // in-phase and quadrature - q1[i] = ((0.0962 * dt[i]) + (0.5769 * dt[i - 2]) - (0.5769 * dt[i - 4]) - (0.0962 * dt[i - 6])) * adj; + q1[i] = (0.0962 * dt[i] + 0.5769 * dt[i - 2] - 0.5769 * dt[i - 4] - 0.0962 * dt[i - 6]) * adj; i1[i] = dt[i - 3]; // advance the phases by 90 degrees - jI = ((0.0962 * i1[i]) + (0.5769 * i1[i - 2]) - (0.5769 * i1[i - 4]) - (0.0962 * i1[i - 6])) * adj; - jQ = ((0.0962 * q1[i]) + (0.5769 * q1[i - 2]) - (0.5769 * q1[i - 4]) - (0.0962 * q1[i - 6])) * adj; + double jI = (0.0962 * i1[i] + 0.5769 * i1[i - 2] - 0.5769 * i1[i - 4] - 0.0962 * i1[i - 6]) * adj; + double jQ = (0.0962 * q1[i] + 0.5769 * q1[i - 2] - 0.5769 * q1[i - 4] - 0.0962 * q1[i - 6]) * adj; // phasor addition for 3-bar averaging i2[i] = i1[i] - jQ; q2[i] = q1[i] + jI; - i2[i] = (0.2 * i2[i]) + (0.8 * i2[i - 1]); // smoothing it - q2[i] = (0.2 * q2[i]) + (0.8 * q2[i - 1]); + i2[i] = 0.2 * i2[i] + 0.8 * i2[i - 1]; // smoothing it + q2[i] = 0.2 * q2[i] + 0.8 * q2[i - 1]; // homodyne discriminator - re[i] = (i2[i] * i2[i - 1]) + (q2[i] * q2[i - 1]); - im[i] = (i2[i] * q2[i - 1]) - (q2[i] * i2[i - 1]); + re[i] = i2[i] * i2[i - 1] + q2[i] * q2[i - 1]; + im[i] = i2[i] * q2[i - 1] - q2[i] * i2[i - 1]; - re[i] = (0.2 * re[i]) + (0.8 * re[i - 1]); // smoothing it - im[i] = (0.2 * im[i]) + (0.8 * im[i - 1]); + re[i] = 0.2 * re[i] + 0.8 * re[i - 1]; // smoothing it + im[i] = 0.2 * im[i] + 0.8 * im[i - 1]; // calculate period pd[i] = im[i] != 0 && re[i] != 0 @@ -131,16 +128,16 @@ List feed : 0; // adjust period to thresholds - pd[i] = (pd[i] > 1.5 * pd[i - 1]) ? 1.5 * pd[i - 1] : pd[i]; - pd[i] = (pd[i] < 0.67 * pd[i - 1]) ? 0.67 * pd[i - 1] : pd[i]; - pd[i] = (pd[i] < 6) ? 6 : pd[i]; - pd[i] = (pd[i] > 50) ? 50 : pd[i]; + pd[i] = pd[i] > 1.5 * pd[i - 1] ? 1.5 * pd[i - 1] : pd[i]; + pd[i] = pd[i] < 0.67 * pd[i - 1] ? 0.67 * pd[i - 1] : pd[i]; + pd[i] = pd[i] < 6 ? 6 : pd[i]; + pd[i] = pd[i] > 50 ? 50 : pd[i]; // smooth the period - pd[i] = (0.2 * pd[i]) + (0.8 * pd[i - 1]); + pd[i] = 0.2 * pd[i] + 0.8 * pd[i - 1]; // determine phase position - ph[i] = (i1[i] != 0) ? Math.Atan(q1[i] / i1[i]) * 180 / Math.PI : 0; + ph[i] = i1[i] != 0 ? Math.Atan(q1[i] / i1[i]) * 180 / Math.PI : 0; // change in phase double delta = Math.Max(ph[i - 1] - ph[i], 1); @@ -149,11 +146,11 @@ List feed double alpha = Math.Max(fastLimit / delta, slowLimit); // final indicators - mama = (alpha * pr[i]) + ((1d - alpha) * prevMama); - fama = (0.5 * alpha * mama) + ((1d - (0.5 * alpha)) * prevFama); + mama = alpha * pr[i] + (1d - alpha) * prevMama; + fama = 0.5 * alpha * mama + (1d - 0.5 * alpha) * prevFama; } - results.Add(new MamaResult( + results.Add(new( Timestamp: s.Timestamp, Mama: mama.NaN2Null(), Fama: fama.NaN2Null())); diff --git a/src/m-r/Marubozu/Marubozu.Common.cs b/src/m-r/Marubozu/Marubozu.Common.cs index cbae46612..daf9d13e6 100644 --- a/src/m-r/Marubozu/Marubozu.Common.cs +++ b/src/m-r/Marubozu/Marubozu.Common.cs @@ -9,16 +9,14 @@ internal static void Validate( double minBodyPercent) { // check parameter arguments - if (minBodyPercent > 100) + switch (minBodyPercent) { - throw new ArgumentOutOfRangeException(nameof(minBodyPercent), minBodyPercent, - "Minimum Body Percent must be less than 100 for Marubozu (<=100%)."); - } - - if (minBodyPercent < 80) - { - throw new ArgumentOutOfRangeException(nameof(minBodyPercent), minBodyPercent, - "Minimum Body Percent must at least 80 (80%) for Marubozu and is usually greater than 90 (90%)."); + case > 100: + throw new ArgumentOutOfRangeException(nameof(minBodyPercent), minBodyPercent, + "Minimum Body Percent must be less than 100 for Marubozu (<=100%)."); + case < 80: + throw new ArgumentOutOfRangeException(nameof(minBodyPercent), minBodyPercent, + "Minimum Body Percent must at least 80 (80%) for Marubozu and is usually greater than 90 (90%)."); } } diff --git a/src/m-r/Marubozu/Marubozu.Series.cs b/src/m-r/Marubozu/Marubozu.Series.cs index d3ce06a17..59f3ca219 100644 --- a/src/m-r/Marubozu/Marubozu.Series.cs +++ b/src/m-r/Marubozu/Marubozu.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcMarubozu( + private static List CalcMarubozu( this List quotesList, double minBodyPercent) where TQuote : IQuote @@ -33,7 +33,7 @@ internal static List CalcMarubozu( matchType = candle.IsBullish ? Match.BullSignal : Match.BearSignal; } - results.Add(new CandleResult( + results.Add(new( timestamp: q.Timestamp, candle: candle, match: matchType, diff --git a/src/m-r/Mfi/Mfi.Series.cs b/src/m-r/Mfi/Mfi.Series.cs index 218336f07..1e13379ca 100644 --- a/src/m-r/Mfi/Mfi.Series.cs +++ b/src/m-r/Mfi/Mfi.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcMfi( + private static List CalcMfi( this List qdList, int lookbackPeriods) { @@ -19,7 +19,7 @@ internal static List CalcMfi( double[] mf = new double[length]; // raw MF value int[] direction = new int[length]; // direction - double? prevTP = null; + double? prevTp = null; // roll through quotes, to get preliminary data for (int i = 0; i < length; i++) @@ -34,15 +34,15 @@ internal static List CalcMfi( mf[i] = tp[i] * q.Volume; // direction - if (prevTP == null || tp[i] == prevTP) + if (prevTp == null || tp[i] == prevTp) { direction[i] = 0; } - else if (tp[i] > prevTP) + else if (tp[i] > prevTp) { direction[i] = 1; } - else if (tp[i] < prevTP) + else if (tp[i] < prevTp) { direction[i] = -1; } @@ -69,7 +69,7 @@ internal static List CalcMfi( if (sumNegMFs != 0) { double mfRatio = sumPosMFs / sumNegMFs; - mfi = 100 - (100 / (1 + mfRatio)); + mfi = 100 - 100 / (1 + mfRatio); } // handle no negative case @@ -83,11 +83,11 @@ internal static List CalcMfi( mfi = double.NaN; } - results.Add(new MfiResult( + results.Add(new( Timestamp: q.Timestamp, Mfi: mfi.NaN2Null())); - prevTP = tp[i]; + prevTp = tp[i]; } return results; diff --git a/src/m-r/Obv/Obv.Series.cs b/src/m-r/Obv/Obv.Series.cs index 9e16b1b87..cf6b6ea0f 100644 --- a/src/m-r/Obv/Obv.Series.cs +++ b/src/m-r/Obv/Obv.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcObv( + private static List CalcObv( this List qdList) { // initialize diff --git a/src/m-r/ParabolicSar/ParabolicSar.Series.cs b/src/m-r/ParabolicSar/ParabolicSar.Series.cs index 78aebd9e8..a61733632 100644 --- a/src/m-r/ParabolicSar/ParabolicSar.Series.cs +++ b/src/m-r/ParabolicSar/ParabolicSar.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcParabolicSar( + private static List CalcParabolicSar( this List qdList, double accelerationStep, double maxAccelerationFactor, @@ -17,16 +17,13 @@ internal static List CalcParabolicSar( // initialize int length = qdList.Count; List results = new(length); - QuoteD q0; if (length == 0) { return results; } - else - { - q0 = qdList[0]; - } + + QuoteD q0 = qdList[0]; double accelerationFactor = initialFactor; double extremePoint = q0.High; @@ -38,7 +35,7 @@ internal static List CalcParabolicSar( { QuoteD q = qdList[i]; - bool? isReversal = null; + bool? isReversal; double psar; // skip first one @@ -52,7 +49,7 @@ internal static List CalcParabolicSar( if (isRising) { double sar = - priorSar + (accelerationFactor * (extremePoint - priorSar)); + priorSar + accelerationFactor * (extremePoint - priorSar); // SAR cannot be higher than last two lows if (i >= 2) @@ -98,7 +95,7 @@ internal static List CalcParabolicSar( else { double sar - = priorSar - (accelerationFactor * (priorSar - extremePoint)); + = priorSar - accelerationFactor * (priorSar - extremePoint); // SAR cannot be lower than last two highs if (i >= 2) @@ -139,7 +136,7 @@ double sar } } - results.Add(new ParabolicSarResult( + results.Add(new( Timestamp: q.Timestamp, Sar: psar.NaN2Null(), IsReversal: isReversal)); diff --git a/src/m-r/PivotPoints/PivotPoints.Models.cs b/src/m-r/PivotPoints/PivotPoints.Models.cs index bfe0a14ec..d8faea747 100644 --- a/src/m-r/PivotPoints/PivotPoints.Models.cs +++ b/src/m-r/PivotPoints/PivotPoints.Models.cs @@ -6,7 +6,7 @@ internal interface IPivotPoint decimal? R3 { get; } decimal? R2 { get; } decimal? R1 { get; } - decimal? PP { get; } + decimal? Pp { get; } decimal? S1 { get; } decimal? S2 { get; } decimal? S3 { get; } @@ -17,7 +17,7 @@ internal interface IPivotPoint { public DateTime Timestamp { get; init; } - public decimal? PP { get; init; } + public decimal? Pp { get; init; } public decimal? S1 { get; init; } public decimal? S2 { get; init; } @@ -32,7 +32,7 @@ internal interface IPivotPoint internal record WindowPoint : IPivotPoint { - public decimal? PP { get; init; } + public decimal? Pp { get; init; } public decimal? S1 { get; init; } public decimal? S2 { get; init; } diff --git a/src/m-r/PivotPoints/PivotPoints.Series.cs b/src/m-r/PivotPoints/PivotPoints.Series.cs index fc2c442f6..50f5c4a00 100644 --- a/src/m-r/PivotPoints/PivotPoints.Series.cs +++ b/src/m-r/PivotPoints/PivotPoints.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcPivotPoints( + private static List CalcPivotPoints( this List quotesList, PeriodSize windowSize, PivotPointType pointType) @@ -15,20 +15,16 @@ internal static List CalcPivotPoints( List results = new(length); WindowPoint windowPoint = new(); - TQuote h0; if (length == 0) { return results; } - else - { - h0 = quotesList[0]; - } + + TQuote h0 = quotesList[0]; int windowId = GetWindowNumber(h0.Timestamp, windowSize); - int windowEval; bool firstWindow = true; decimal windowHigh = h0.High; @@ -42,7 +38,7 @@ internal static List CalcPivotPoints( TQuote q = quotesList[i]; // new window evaluation - windowEval = GetWindowNumber(q.Timestamp, windowSize); + int windowEval = GetWindowNumber(q.Timestamp, windowSize); if (windowEval != windowId) { @@ -72,7 +68,7 @@ PivotPointsResult r Timestamp = q.Timestamp, // pivot point - PP = windowPoint.PP, + Pp = windowPoint.Pp, // support S1 = windowPoint.S1, @@ -84,17 +80,17 @@ PivotPointsResult r R1 = windowPoint.R1, R2 = windowPoint.R2, R3 = windowPoint.R3, - R4 = windowPoint.R4, + R4 = windowPoint.R4 } - : new() { + : new PivotPointsResult { Timestamp = q.Timestamp }; results.Add(r); // capture window threholds (for next iteration) - windowHigh = (q.High > windowHigh) ? q.High : windowHigh; - windowLow = (q.Low < windowLow) ? q.Low : windowLow; + windowHigh = q.High > windowHigh ? q.High : windowHigh; + windowLow = q.Low < windowLow ? q.Low : windowLow; windowClose = q.Close; } @@ -102,103 +98,107 @@ PivotPointsResult r } // internals - internal static WindowPoint GetPivotPointStandard( + private static WindowPoint GetPivotPointStandard( decimal high, decimal low, decimal close) { decimal pp = (high + low + close) / 3; return new() { - PP = pp, - S1 = (pp * 2) - high, + Pp = pp, + S1 = pp * 2 - high, S2 = pp - (high - low), - S3 = low - (2 * (high - pp)), - R1 = (pp * 2) - low, + S3 = low - 2 * (high - pp), + R1 = pp * 2 - low, R2 = pp + (high - low), - R3 = high + (2 * (pp - low)) + R3 = high + 2 * (pp - low) }; } - internal static WindowPoint GetPivotPointCamarilla( + private static WindowPoint GetPivotPointCamarilla( decimal high, decimal low, decimal close) => new() { - PP = close, - S1 = close - (1.1m / 12 * (high - low)), - S2 = close - (1.1m / 6 * (high - low)), - S3 = close - (1.1m / 4 * (high - low)), - S4 = close - (1.1m / 2 * (high - low)), - R1 = close + (1.1m / 12 * (high - low)), - R2 = close + (1.1m / 6 * (high - low)), - R3 = close + (1.1m / 4 * (high - low)), - R4 = close + (1.1m / 2 * (high - low)) + Pp = close, + S1 = close - 1.1m / 12 * (high - low), + S2 = close - 1.1m / 6 * (high - low), + S3 = close - 1.1m / 4 * (high - low), + S4 = close - 1.1m / 2 * (high - low), + R1 = close + 1.1m / 12 * (high - low), + R2 = close + 1.1m / 6 * (high - low), + R3 = close + 1.1m / 4 * (high - low), + R4 = close + 1.1m / 2 * (high - low) }; internal static WindowPoint GetPivotPointDemark( decimal open, decimal high, decimal low, decimal close) { decimal x = close < open - ? high + (2 * low) + close + ? high + 2 * low + close : close > open - ? (2 * high) + low + close - : high + low + (2 * close); + ? 2 * high + low + close + : high + low + 2 * close; return new() { - PP = x / 4, - S1 = (x / 2) - high, - R1 = (x / 2) - low + Pp = x / 4, + S1 = x / 2 - high, + R1 = x / 2 - low }; } - internal static WindowPoint GetPivotPointFibonacci( + private static WindowPoint GetPivotPointFibonacci( decimal high, decimal low, decimal close) { decimal pp = (high + low + close) / 3; return new() { - PP = pp, - S1 = pp - (0.382m * (high - low)), - S2 = pp - (0.618m * (high - low)), - S3 = pp - (1.000m * (high - low)), - R1 = pp + (0.382m * (high - low)), - R2 = pp + (0.618m * (high - low)), - R3 = pp + (1.000m * (high - low)) + Pp = pp, + S1 = pp - 0.382m * (high - low), + S2 = pp - 0.618m * (high - low), + S3 = pp - 1.000m * (high - low), + R1 = pp + 0.382m * (high - low), + R2 = pp + 0.618m * (high - low), + R3 = pp + 1.000m * (high - low) }; } - internal static WindowPoint GetPivotPointWoodie( + private static WindowPoint GetPivotPointWoodie( decimal currentOpen, decimal high, decimal low) { - decimal pp = (high + low + (2 * currentOpen)) / 4; + decimal pp = (high + low + 2 * currentOpen) / 4; return new() { - PP = pp, - S1 = (pp * 2) - high, + Pp = pp, + S1 = pp * 2 - high, S2 = pp - high + low, - S3 = low - (2 * (high - pp)), - R1 = (pp * 2) - low, + S3 = low - 2 * (high - pp), + R1 = pp * 2 - low, R2 = pp + high - low, - R3 = high + (2 * (pp - low)), + R3 = high + 2 * (pp - low) }; } // pivot type lookup - internal static WindowPoint GetPivotPoint( + private static WindowPoint GetPivotPoint( PivotPointType pointType, decimal open, decimal high, decimal low, decimal close) => pointType switch { + PivotPointType.Standard => GetPivotPointStandard(high, low, close), PivotPointType.Camarilla => GetPivotPointCamarilla(high, low, close), PivotPointType.Demark => GetPivotPointDemark(open, high, low, close), PivotPointType.Fibonacci => GetPivotPointFibonacci(high, low, close), PivotPointType.Woodie => GetPivotPointWoodie(open, high, low), + _ => throw new ArgumentOutOfRangeException(nameof(pointType), pointType, "Invalid pointType provided.") }; // window size lookup private static int GetWindowNumber(DateTime d, PeriodSize windowSize) => windowSize switch { + PeriodSize.Month => d.Month, PeriodSize.Week => EnglishCalendar.GetWeekOfYear(d, EnglishCalendarWeekRule, EnglishFirstDayOfWeek), PeriodSize.Day => d.Day, PeriodSize.OneHour => d.Hour, + _ => throw new ArgumentOutOfRangeException(nameof(windowSize), windowSize, string.Format( EnglishCulture, diff --git a/src/m-r/PivotPoints/PivotPoints.Utilities.cs b/src/m-r/PivotPoints/PivotPoints.Utilities.cs index bbd81b5c2..55815cd44 100644 --- a/src/m-r/PivotPoints/PivotPoints.Utilities.cs +++ b/src/m-r/PivotPoints/PivotPoints.Utilities.cs @@ -11,7 +11,7 @@ public static IEnumerable RemoveWarmupPeriods( { int removePeriods = results .ToList() - .FindIndex(x => x.PP != null); + .FindIndex(x => x.Pp != null); return results.Remove(removePeriods); } diff --git a/src/m-r/Pivots/Pivots.Models.cs b/src/m-r/Pivots/Pivots.Models.cs index fa99453b2..c2ad4b103 100644 --- a/src/m-r/Pivots/Pivots.Models.cs +++ b/src/m-r/Pivots/Pivots.Models.cs @@ -13,8 +13,8 @@ public record struct PivotsResult public enum PivotTrend { - HH, // higher high - LH, // lower high - HL, // higher low - LL // lower low + Hh, // higher high + Lh, // lower high + Hl, // higher low + Ll // lower low } diff --git a/src/m-r/Pivots/Pivots.Series.cs b/src/m-r/Pivots/Pivots.Series.cs index f235af04b..6a2672123 100644 --- a/src/m-r/Pivots/Pivots.Series.cs +++ b/src/m-r/Pivots/Pivots.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcPivots( + private static List CalcPivots( this List quotesList, int leftSpan, int rightSpan, @@ -59,9 +59,9 @@ internal static List CalcPivots( // repaint trend if (lastHighIndex != null && highPoint != lastHighValue) { - PivotTrend trend = (highPoint > lastHighValue) - ? PivotTrend.HH - : PivotTrend.LH; + PivotTrend trend = highPoint > lastHighValue + ? PivotTrend.Hh + : PivotTrend.Lh; highLine[(int)lastHighIndex] = lastHighValue; @@ -71,7 +71,7 @@ internal static List CalcPivots( for (int t = (int)lastHighIndex + 1; t <= i; t++) { highTrend[t] = trend; - highLine[t] = highPoint + (incr * (t - i)); + highLine[t] = highPoint + incr * (t - i); } } @@ -86,9 +86,9 @@ internal static List CalcPivots( // repaint trend if (lastLowIndex != null && lowPoint != lastLowValue) { - PivotTrend trend = (lowPoint > lastLowValue) - ? PivotTrend.HL - : PivotTrend.LL; + PivotTrend trend = lowPoint > lastLowValue + ? PivotTrend.Hl + : PivotTrend.Ll; lowLine[(int)lastLowIndex] = lastLowValue; @@ -98,7 +98,7 @@ internal static List CalcPivots( for (int t = (int)lastLowIndex + 1; t <= i; t++) { lowTrend[t] = trend; - lowLine[t] = lowPoint + (incr * (t - i)); + lowLine[t] = lowPoint + incr * (t - i); } } @@ -125,7 +125,7 @@ internal static List CalcPivots( PivotTrend? ht = highTrend[i]; PivotTrend? lt = lowTrend[i]; - results.Add(new PivotsResult( + results.Add(new( Timestamp: q.Timestamp, HighPoint: highPoint, LowPoint: lowPoint, diff --git a/src/m-r/Pmo/Pmo.Series.cs b/src/m-r/Pmo/Pmo.Series.cs index 6e26edcc6..6945f23e2 100644 --- a/src/m-r/Pmo/Pmo.Series.cs +++ b/src/m-r/Pmo/Pmo.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcPmo( + private static List CalcPmo( this List source, int timePeriods, int smoothPeriods, @@ -36,7 +36,7 @@ internal static List CalcPmo( T s = source[i]; // rate of change (ROC) - rc[i] = prevPrice == 0 ? double.NaN : 100 * ((s.Value / prevPrice) - 1); + rc[i] = prevPrice == 0 ? double.NaN : 100 * (s.Value / prevPrice - 1); prevPrice = s.Value; // ROC smoothed moving average @@ -53,7 +53,7 @@ internal static List CalcPmo( } else { - rocEma = prevRocEma + (smoothingConstant2 * (rc[i] - prevRocEma)); + rocEma = prevRocEma + smoothingConstant2 * (rc[i] - prevRocEma); } re[i] = rocEma * 10; @@ -73,7 +73,7 @@ internal static List CalcPmo( } else { - pmo = prevPmo + (smoothingConstant1 * (re[i] - prevPmo)); + pmo = prevPmo + smoothingConstant1 * (re[i] - prevPmo); } prevPmo = pm[i] = pmo; diff --git a/src/m-r/Prs/Prs.Common.cs b/src/m-r/Prs/Prs.Common.cs index e786f959e..55e71e8ee 100644 --- a/src/m-r/Prs/Prs.Common.cs +++ b/src/m-r/Prs/Prs.Common.cs @@ -16,7 +16,7 @@ internal static void Validate( where T : ISeries { // check parameter arguments - if (lookbackPeriods is not null and <= 0) + if (lookbackPeriods is <= 0) { throw new ArgumentOutOfRangeException( nameof(lookbackPeriods), lookbackPeriods, @@ -27,14 +27,13 @@ internal static void Validate( int qtyHistoryEval = quotesEval.Count; int qtyHistoryBase = quotesBase.Count; - int? minHistory = lookbackPeriods; - if (minHistory != null && qtyHistoryEval < minHistory) + if (qtyHistoryEval < lookbackPeriods) { string message = "Insufficient quotes provided for Price Relative Strength. " + string.Format( EnglishCulture, "You provided {0} periods of quotes when at least {1} are required.", - qtyHistoryEval, minHistory); + qtyHistoryEval, lookbackPeriods); throw new InvalidQuotesException(nameof(quotesEval), message); } diff --git a/src/m-r/Prs/Prs.Series.cs b/src/m-r/Prs/Prs.Series.cs index 42ad2b81e..8a649fe6b 100644 --- a/src/m-r/Prs/Prs.Series.cs +++ b/src/m-r/Prs/Prs.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcPrs( + private static List CalcPrs( List listEval, List listBase, int? lookbackPeriods = null) @@ -50,7 +50,7 @@ internal static List CalcPrs( PrsResult r = new() { Timestamp = e.Timestamp, - Prs = (b.Value == 0) + Prs = b.Value == 0 ? null : (e.Value / b.Value).NaN2Null(), // relative strength ratio diff --git a/src/m-r/Pvo/Pvo.Series.cs b/src/m-r/Pvo/Pvo.Series.cs index d2a25fd9c..6232b2e2d 100644 --- a/src/m-r/Pvo/Pvo.Series.cs +++ b/src/m-r/Pvo/Pvo.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcPvo( + private static List CalcPvo( this List source, // volume int fastPeriods, int slowPeriods, @@ -71,7 +71,7 @@ internal static List CalcPvo( .Increment(kSlow, lastEmaSlow, s.Value); } - double pvo = (emaSlow != 0) ? + double pvo = emaSlow != 0 ? 100 * ((emaFast - emaSlow) / emaSlow) : double.NaN; // re-initialize Signal EMA @@ -94,7 +94,7 @@ internal static List CalcPvo( } // write results - results.Add(new PvoResult( + results.Add(new( Timestamp: s.Timestamp, Pvo: pvo.NaN2Null(), Signal: signal.NaN2Null(), diff --git a/src/m-r/Renko/Renko.Series.cs b/src/m-r/Renko/Renko.Series.cs index e76701898..703ed6dfd 100644 --- a/src/m-r/Renko/Renko.Series.cs +++ b/src/m-r/Renko/Renko.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcRenko( + private static List CalcRenko( this List quotesList, decimal brickSize, EndType endType) @@ -16,18 +16,15 @@ internal static List CalcRenko( // initialize int length = quotesList.Count; List results = new(length); - TQuote q0; if (length == 0) { return results; } - else - { - q0 = quotesList[0]; - } - bool resetHLV = true; + TQuote q0 = quotesList[0]; + + bool resetHlv = true; int decimals = brickSize.GetDecimalPlaces(); decimal baseline = Math.Round(q0.Close, Math.Max(decimals - 1, 0)); @@ -47,7 +44,7 @@ internal static List CalcRenko( TQuote q = quotesList[i]; // accumulate brick info - if (resetHLV) + if (resetHlv) { // reset h = q.High; @@ -97,7 +94,7 @@ internal static List CalcRenko( } // init next brick(s) - resetHLV = absQty != 0; + resetHlv = absQty != 0; } return results; @@ -135,7 +132,7 @@ private static int GetNewBricks( decimal hQty = (q.High - upper) / brickSize; decimal lQty = (lower - q.Low) / brickSize; - bricks = (int)((hQty >= lQty) ? hQty : -lQty); + bricks = (int)(hQty >= lQty ? hQty : -lQty); break; default: diff --git a/src/m-r/Renko/RenkoAtr.Series.cs b/src/m-r/Renko/RenkoAtr.Series.cs index 245e57444..859b71ff5 100644 --- a/src/m-r/Renko/RenkoAtr.Series.cs +++ b/src/m-r/Renko/RenkoAtr.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcRenkoAtr( + private static List CalcRenkoAtr( this List quotesList, int atrPeriods, EndType endType = EndType.Close) diff --git a/src/m-r/Roc/Roc.Series.cs b/src/m-r/Roc/Roc.Series.cs index 9bc5eae13..e95cf4eed 100644 --- a/src/m-r/Roc/Roc.Series.cs +++ b/src/m-r/Roc/Roc.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcRoc( + private static List CalcRoc( this List source, int lookbackPeriods) where T : IReusable @@ -30,9 +30,9 @@ internal static List CalcRoc( momentum = s.Value - back.Value; - roc = (back.Value == 0) + roc = back.Value == 0 ? double.NaN - : (100d * momentum / back.Value); + : 100d * momentum / back.Value; } else { diff --git a/src/m-r/RocWb/RocWb.Series.cs b/src/m-r/RocWb/RocWb.Series.cs index 7ea58edda..3340c2939 100644 --- a/src/m-r/RocWb/RocWb.Series.cs +++ b/src/m-r/RocWb/RocWb.Series.cs @@ -3,7 +3,7 @@ namespace Skender.Stock.Indicators; // RATE OF CHANGE (ROC) WITH BANDS (SERIES) public static partial class Indicator { - internal static List CalcRocWb( + private static List CalcRocWb( this List source, int lookbackPeriods, int emaPeriods, @@ -70,7 +70,7 @@ internal static List CalcRocWb( rocDev = Math.Sqrt(sum / stdDevPeriods).NaN2Null(); } - results.Add(new RocWbResult( + results.Add(new( Timestamp: roc.Timestamp, Roc: roc.Value.NaN2Null(), RocEma: ema[i].NaN2Null(), diff --git a/src/m-r/RollingPivots/RollingPivots.Models.cs b/src/m-r/RollingPivots/RollingPivots.Models.cs index b89e5f9f0..e151ff5c1 100644 --- a/src/m-r/RollingPivots/RollingPivots.Models.cs +++ b/src/m-r/RollingPivots/RollingPivots.Models.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; { public DateTime Timestamp { get; init; } - public decimal? PP { get; init; } + public decimal? Pp { get; init; } public decimal? S1 { get; init; } public decimal? S2 { get; init; } diff --git a/src/m-r/RollingPivots/RollingPivots.Series.cs b/src/m-r/RollingPivots/RollingPivots.Series.cs index 2ca6be522..558cd3ab8 100644 --- a/src/m-r/RollingPivots/RollingPivots.Series.cs +++ b/src/m-r/RollingPivots/RollingPivots.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcRollingPivots( + private static List CalcRollingPivots( this List quotesList, int windowPeriods, int offsetPeriods, @@ -38,20 +38,20 @@ internal static List CalcRollingPivots( for (int p = s; p <= i - offsetPeriods - 1; p++) { TQuote d = quotesList[p]; - windowHigh = (d.High > windowHigh) ? d.High : windowHigh; - windowLow = (d.Low < windowLow) ? d.Low : windowLow; + windowHigh = d.High > windowHigh ? d.High : windowHigh; + windowLow = d.Low < windowLow ? d.Low : windowLow; } // pivot points WindowPoint wp = GetPivotPoint( pointType, q.Open, windowHigh, windowLow, windowClose); - r = new RollingPivotsResult { + r = new() { Timestamp = q.Timestamp, // pivot point - PP = wp.PP, + Pp = wp.Pp, // support S1 = wp.S1, diff --git a/src/m-r/RollingPivots/RollingPivots.Utilities.cs b/src/m-r/RollingPivots/RollingPivots.Utilities.cs index 6c897032f..9421f597a 100644 --- a/src/m-r/RollingPivots/RollingPivots.Utilities.cs +++ b/src/m-r/RollingPivots/RollingPivots.Utilities.cs @@ -10,7 +10,7 @@ public static IEnumerable RemoveWarmupPeriods( { int removePeriods = results .ToList() - .FindIndex(x => x.PP != null); + .FindIndex(x => x.Pp != null); return results.Remove(removePeriods); } diff --git a/src/m-r/Rsi/Rsi.Series.cs b/src/m-r/Rsi/Rsi.Series.cs index cae0ee59e..7538b5418 100644 --- a/src/m-r/Rsi/Rsi.Series.cs +++ b/src/m-r/Rsi/Rsi.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcRsi( + private static List CalcRsi( this List source, int lookbackPeriods) where T : IReusable @@ -20,14 +20,13 @@ internal static List CalcRsi( List results = new(length); double[] gain = new double[length]; // gain double[] loss = new double[length]; // loss - double prevValue; if (length == 0) { return results; } - prevValue = source[0].Value; + double prevValue = source[0].Value; // roll through quotes for (int i = 0; i < length; i++) @@ -40,8 +39,8 @@ internal static List CalcRsi( } else { - gain[i] = (s.Value > prevValue) ? s.Value - prevValue : 0; - loss[i] = (s.Value < prevValue) ? prevValue - s.Value : 0; + gain[i] = s.Value > prevValue ? s.Value - prevValue : 0; + loss[i] = s.Value < prevValue ? prevValue - s.Value : 0; } double? rsi = null; @@ -63,20 +62,20 @@ internal static List CalcRsi( avgLoss = sumLoss / lookbackPeriods; rsi = !double.IsNaN(avgGain / avgLoss) - ? (avgLoss > 0) ? 100 - (100 / (1 + (avgGain / avgLoss))) : 100 + ? avgLoss > 0 ? 100 - 100 / (1 + avgGain / avgLoss) : 100 : null; } // calculate RSI normally else if (i > lookbackPeriods) { - avgGain = ((avgGain * (lookbackPeriods - 1)) + gain[i]) / lookbackPeriods; - avgLoss = ((avgLoss * (lookbackPeriods - 1)) + loss[i]) / lookbackPeriods; + avgGain = (avgGain * (lookbackPeriods - 1) + gain[i]) / lookbackPeriods; + avgLoss = (avgLoss * (lookbackPeriods - 1) + loss[i]) / lookbackPeriods; if (avgLoss > 0) { double rs = avgGain / avgLoss; - rsi = 100 - (100 / (1 + rs)); + rsi = 100 - 100 / (1 + rs); } else { diff --git a/src/s-z/Slope/Slope.Series.cs b/src/s-z/Slope/Slope.Series.cs index a7ed76fe1..368ee5cd5 100644 --- a/src/s-z/Slope/Slope.Series.cs +++ b/src/s-z/Slope/Slope.Series.cs @@ -5,7 +5,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { // calculate series - internal static List CalcSlope( + private static List CalcSlope( this List source, int lookbackPeriods) where T : IReusable @@ -47,7 +47,7 @@ internal static List CalcSlope( // least squares method double sumSqX = 0; double sumSqY = 0; - double sumSqXY = 0; + double sumSqXy = 0; for (int p = i - lookbackPeriods + 1; p <= i; p++) { @@ -58,11 +58,11 @@ internal static List CalcSlope( sumSqX += devX * devX; sumSqY += devY * devY; - sumSqXY += devX * devY; + sumSqXy += devX * devY; } - double? slope = (sumSqXY / sumSqX).NaN2Null(); - double? intercept = (avgY - (slope * avgX)).NaN2Null(); + double? slope = (sumSqXy / sumSqX).NaN2Null(); + double? intercept = (avgY - slope * avgX).NaN2Null(); // calculate Standard Deviation and R-Squared double stdDevX = Math.Sqrt(sumSqX / lookbackPeriods); @@ -72,7 +72,7 @@ internal static List CalcSlope( if (stdDevX * stdDevY != 0) { - double arrr = sumSqXY / (stdDevX * stdDevY) / lookbackPeriods; + double arrr = sumSqXy / (stdDevX * stdDevY) / lookbackPeriods; rSquared = (arrr * arrr).NaN2Null(); } @@ -87,18 +87,21 @@ internal static List CalcSlope( results.Add(r); } + // insufficient length for last line + if (length < lookbackPeriods) + { + return results; + } + // add last Line (y = mx + b) - if (length >= lookbackPeriods) + SlopeResult last = results.LastOrDefault(); + for (int p = length - lookbackPeriods; p < length; p++) { - SlopeResult last = results.LastOrDefault(); - for (int p = length - lookbackPeriods; p < length; p++) - { - SlopeResult d = results[p]; + SlopeResult d = results[p]; - results[p] = d with { - Line = (decimal?)((last.Slope * (p + 1)) + last.Intercept).NaN2Null() - }; - } + results[p] = d with { + Line = (decimal?)(last.Slope * (p + 1) + last.Intercept).NaN2Null() + }; } return results; diff --git a/src/s-z/Sma/Sma.Api.cs b/src/s-z/Sma/Sma.Api.cs index f53e96e2d..f44a01c7c 100644 --- a/src/s-z/Sma/Sma.Api.cs +++ b/src/s-z/Sma/Sma.Api.cs @@ -13,15 +13,6 @@ public static IEnumerable GetSma( .ToSortedList() .CalcSma(lookbackPeriods); - // ANALYSIS, from CHAIN - public static IEnumerable GetSmaAnalysis( - this IEnumerable source, - int lookbackPeriods) - where T : IReusable - => source - .ToSortedList() - .CalcSmaAnalysis(lookbackPeriods); - // OBSERVER, from Chain Provider public static Sma ToSma( this IChainProvider chainProvider, diff --git a/src/s-z/Sma/Sma.Series.cs b/src/s-z/Sma/Sma.Series.cs index 83bb4559b..033710730 100644 --- a/src/s-z/Sma/Sma.Series.cs +++ b/src/s-z/Sma/Sma.Series.cs @@ -4,10 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - // TODO: discontinue converting to Tuple, - // everywhere. It's unneeded overhead; use IReusableResult. - - internal static List CalcSma( + private static List CalcSma( this List source, int lookbackPeriods) where T : IReusable diff --git a/src/s-z/Sma/Sma.Stream.cs b/src/s-z/Sma/Sma.Stream.cs index 81cd6c55c..49cecdcaf 100644 --- a/src/s-z/Sma/Sma.Stream.cs +++ b/src/s-z/Sma/Sma.Stream.cs @@ -2,7 +2,7 @@ namespace Skender.Stock.Indicators; // SIMPLE MOVING AVERAGE (STREAMING) -public partial class Sma : AbstractChainInChainOut, ISma +public class Sma : AbstractChainInChainOut, ISma where TIn : struct, IReusable { #region CONSTRUCTORS @@ -25,7 +25,7 @@ public Sma( # region PROPERTIES - public int LookbackPeriods { get; private set; } + public int LookbackPeriods { get; } #endregion # region METHODS @@ -61,7 +61,8 @@ protected override void OnNextArrival(Act act, TIn inbound) } // normal - else if (i >= LookbackPeriods - 1) + + if (i >= LookbackPeriods - 1) { double sum = 0; for (int w = i - LookbackPeriods + 1; w <= i; w++) diff --git a/src/s-z/SmaAnalysis/Sma.Analysis.Api.cs b/src/s-z/SmaAnalysis/Sma.Analysis.Api.cs new file mode 100644 index 000000000..b1c9a815d --- /dev/null +++ b/src/s-z/SmaAnalysis/Sma.Analysis.Api.cs @@ -0,0 +1,16 @@ +namespace Skender.Stock.Indicators; + +// SIMPLE MOVING AVERAGE (API) +// with extended analysis + +public static partial class Indicator +{ + // ANALYSIS, from CHAIN + public static IEnumerable GetSmaAnalysis( + this IEnumerable source, + int lookbackPeriods) + where T : IReusable + => source + .ToSortedList() + .CalcSmaAnalysis(lookbackPeriods); +} diff --git a/src/s-z/Sma/Sma.Analysis.cs b/src/s-z/SmaAnalysis/Sma.Analysis.Series.cs similarity index 88% rename from src/s-z/Sma/Sma.Analysis.cs rename to src/s-z/SmaAnalysis/Sma.Analysis.Series.cs index e3fd66b0b..554c907db 100644 --- a/src/s-z/Sma/Sma.Analysis.cs +++ b/src/s-z/SmaAnalysis/Sma.Analysis.Series.cs @@ -3,7 +3,7 @@ namespace Skender.Stock.Indicators; // SIMPLE MOVING AVERAGE (ANALYSIS) public static partial class Indicator { - internal static IEnumerable CalcSmaAnalysis( + private static List CalcSmaAnalysis( this List source, int lookbackPeriods) where T : IReusable @@ -21,7 +21,7 @@ internal static IEnumerable CalcSmaAnalysis( for (int i = lookbackPeriods - 1; i < results.Count; i++) { SmaAnalysis r = results[i]; - double sma = (r.Sma == null) ? double.NaN : (double)r.Sma; + double sma = r.Sma ?? double.NaN; double sumMad = 0; double sumMse = 0; @@ -34,7 +34,7 @@ internal static IEnumerable CalcSmaAnalysis( sumMad += Math.Abs(s.Value - sma); sumMse += (s.Value - sma) * (s.Value - sma); - sumMape += (s.Value == 0) ? double.NaN + sumMape += s.Value == 0 ? double.NaN : Math.Abs(s.Value - sma) / s.Value; } diff --git a/src/s-z/Smi/Smi.Series.cs b/src/s-z/Smi/Smi.Series.cs index d0dbb16ee..8099dda1b 100644 --- a/src/s-z/Smi/Smi.Series.cs +++ b/src/s-z/Smi/Smi.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcSmi( + private static List CalcSmi( this List qdList, int lookbackPeriods, int firstSmoothPeriods, @@ -60,7 +60,7 @@ internal static List CalcSmi( } } - double sm = q.Close - (0.5d * (hH + lL)); + double sm = q.Close - 0.5d * (hH + lL); double hl = hH - lL; // initialize last EMA values @@ -74,12 +74,12 @@ internal static List CalcSmi( } // first smoothing - double smEma1 = lastSmEma1 + (k1 * (sm - lastSmEma1)); - double hlEma1 = lastHlEma1 + (k1 * (hl - lastHlEma1)); + double smEma1 = lastSmEma1 + k1 * (sm - lastSmEma1); + double hlEma1 = lastHlEma1 + k1 * (hl - lastHlEma1); // second smoothing - double smEma2 = lastSmEma2 + (k2 * (smEma1 - lastSmEma2)); - double hlEma2 = lastHlEma2 + (k2 * (hlEma1 - lastHlEma2)); + double smEma2 = lastSmEma2 + k2 * (smEma1 - lastSmEma2); + double hlEma2 = lastHlEma2 + k2 * (hlEma1 - lastHlEma2); // stochastic momentum index smi = 100 * (smEma2 / (0.5 * hlEma2)); @@ -92,7 +92,7 @@ internal static List CalcSmi( } // signal line - signal = lastSignal + (kS * (smi - lastSignal)); + signal = lastSignal + kS * (smi - lastSignal); // carryover values lastSmEma1 = smEma1; @@ -107,7 +107,7 @@ internal static List CalcSmi( signal = double.NaN; } - results.Add(new SmiResult( + results.Add(new( Timestamp: q.Timestamp, Smi: smi.NaN2Null(), Signal: signal.NaN2Null())); diff --git a/src/s-z/Smma/Smma.Series.cs b/src/s-z/Smma/Smma.Series.cs index 65ec33542..7676b9009 100644 --- a/src/s-z/Smma/Smma.Series.cs +++ b/src/s-z/Smma/Smma.Series.cs @@ -5,7 +5,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { // calculate series - internal static List CalcSmma( + private static List CalcSmma( this List source, int lookbackPeriods) where T : IReusable @@ -48,10 +48,10 @@ internal static List CalcSmma( // normal SMMA else { - smma = ((prevSmma * (lookbackPeriods - 1)) + s.Value) / lookbackPeriods; + smma = (prevSmma * (lookbackPeriods - 1) + s.Value) / lookbackPeriods; } - results.Add(new SmmaResult( + results.Add(new( Timestamp: s.Timestamp, Smma: smma.NaN2Null())); diff --git a/src/s-z/StarcBands/StarcBands.Series.cs b/src/s-z/StarcBands/StarcBands.Series.cs index 7adb0aa83..60bc2b43d 100644 --- a/src/s-z/StarcBands/StarcBands.Series.cs +++ b/src/s-z/StarcBands/StarcBands.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcStarcBands( + private static List CalcStarcBands( this List qdList, int smaPeriods, double multiplier, @@ -25,11 +25,11 @@ internal static List CalcStarcBands( SmaResult s = smaResults[i]; AtrResult a = atrResults[i]; - results.Add(new StarcBandsResult( + results.Add(new( Timestamp: s.Timestamp, Centerline: s.Sma, - UpperBand: s.Sma + (multiplier * a.Atr), - LowerBand: s.Sma - (multiplier * a.Atr))); + UpperBand: s.Sma + multiplier * a.Atr, + LowerBand: s.Sma - multiplier * a.Atr)); } return results; diff --git a/src/s-z/Stc/Stc.Series.cs b/src/s-z/Stc/Stc.Series.cs index 6e470b171..7a7f7092e 100644 --- a/src/s-z/Stc/Stc.Series.cs +++ b/src/s-z/Stc/Stc.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcStc( + private static List CalcStc( this List tpList, int cyclePeriods, int fastPeriods, @@ -28,13 +28,13 @@ internal static List CalcStc( Close = x.Macd.Null2NaN() }) .ToList() - .CalcStoch(cyclePeriods, 1, 3, 3, 2, MaType.SMA); + .CalcStoch(cyclePeriods, 1, 3, 3, 2, MaType.Sma); // add stoch results for (int i = 0; i < length; i++) { StochResult r = stochMacd[i]; - results.Add(new StcResult { + results.Add(new() { Timestamp = r.Timestamp, Stc = r.Oscillator }); diff --git a/src/s-z/StdDev/StdDev.Series.cs b/src/s-z/StdDev/StdDev.Series.cs index 08b8bd488..6e77445c2 100644 --- a/src/s-z/StdDev/StdDev.Series.cs +++ b/src/s-z/StdDev/StdDev.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcStdDev( + private static List CalcStdDev( this List source, int lookbackPeriods) where T : IReusable @@ -43,7 +43,7 @@ internal static List CalcStdDev( stdDev = values.StdDev(); - zScore = (stdDev == 0) ? double.NaN + zScore = stdDev == 0 ? double.NaN : (s.Value - mean) / stdDev; } else diff --git a/src/s-z/StdDevChannels/StdDevChannels.Series.cs b/src/s-z/StdDevChannels/StdDevChannels.Series.cs index 6714eb8b1..6b36c617e 100644 --- a/src/s-z/StdDevChannels/StdDevChannels.Series.cs +++ b/src/s-z/StdDevChannels/StdDevChannels.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcStdDevChannels( + private static List CalcStdDevChannels( this List source, int? lookbackPeriods, double stdDeviations) @@ -35,20 +35,22 @@ internal static List CalcStdDevChannels( // add regression line (y = mx + b) and channels for (int p = i - (int)lookbackPeriods + 1; p <= i; p++) { - if (p >= 0) + if (p < 0) { - StdDevChannelsResult d = results[p]; + continue; + } - double? c = (s.Slope * (p + 1)) + s.Intercept; + StdDevChannelsResult d = results[p]; - // re-write record - results[p] = d with { - Centerline = c, - UpperChannel = c + width, - LowerChannel = c - width, - BreakPoint = p == i - lookbackPeriods + 1 - }; - } + double? c = s.Slope * (p + 1) + s.Intercept; + + // re-write record + results[p] = d with { + Centerline = c, + UpperChannel = c + width, + LowerChannel = c - width, + BreakPoint = p == i - lookbackPeriods + 1 + }; } } diff --git a/src/s-z/Stoch/Stoch.Api.cs b/src/s-z/Stoch/Stoch.Api.cs index 0119bad4b..1786ecaae 100644 --- a/src/s-z/Stoch/Stoch.Api.cs +++ b/src/s-z/Stoch/Stoch.Api.cs @@ -16,7 +16,7 @@ public static IEnumerable GetStoch( .CalcStoch( lookbackPeriods, signalPeriods, - smoothPeriods, 3, 2, MaType.SMA); + smoothPeriods, 3, 2, MaType.Sma); // SERIES, from TQuote (extended) /// diff --git a/src/s-z/Stoch/Stoch.Common.cs b/src/s-z/Stoch/Stoch.Common.cs index dbe45afd3..c591451c4 100644 --- a/src/s-z/Stoch/Stoch.Common.cs +++ b/src/s-z/Stoch/Stoch.Common.cs @@ -44,7 +44,7 @@ internal static void Validate( "dFactor must be greater than 0 for Stochastic."); } - if (movingAverageType is not MaType.SMA and not MaType.SMMA) + if (movingAverageType is not MaType.Sma and not MaType.Smma) { throw new ArgumentOutOfRangeException(nameof(dFactor), dFactor, "Stochastic only supports SMA and SMMA moving average types."); diff --git a/src/s-z/Stoch/Stoch.Series.cs b/src/s-z/Stoch/Stoch.Series.cs index 0effa5bb2..c43973a42 100644 --- a/src/s-z/Stoch/Stoch.Series.cs +++ b/src/s-z/Stoch/Stoch.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcStoch( + private static List CalcStoch( this List qdList, int lookbackPeriods, int signalPeriods, @@ -65,7 +65,7 @@ internal static List CalcStoch( o[i] = !isViable ? double.NaN - : lowLow != highHigh + : highHigh - lowLow != 0 ? 100 * (q.Close - lowLow) / (highHigh - lowLow) : 0; } @@ -85,31 +85,38 @@ internal static List CalcStoch( { k[i] = double.NaN; - if (movingAverageType is MaType.SMA) // TODO: || double.IsNaN(prevK) to re/initialize SMMA? + switch (movingAverageType) { - double sum = 0; - for (int p = i - smoothPeriods + 1; p <= i; p++) - { - sum += o[p]; - } - - k[i] = sum / smoothPeriods; - } - - else if (movingAverageType is MaType.SMMA) - { - // re/initialize - if (double.IsNaN(prevK)) - { - prevK = o[i]; - } - - k[i] = ((prevK * (smoothPeriods - 1)) + o[i]) / smoothPeriods; - prevK = k[i]; - } - else - { - throw new InvalidOperationException("Invalid Stochastic moving average type."); + // SMA case + case MaType.Sma: + { + double sum = 0; + for (int p = i - smoothPeriods + 1; p <= i; p++) + { + sum += o[p]; + } + + k[i] = sum / smoothPeriods; + break; + } + + // SMMA case + case MaType.Smma: + { + // re/initialize + if (double.IsNaN(prevK)) + { + prevK = o[i]; + } + + k[i] = (prevK * (smoothPeriods - 1) + o[i]) / smoothPeriods; + prevK = k[i]; + break; + } + + default: + throw new InvalidOperationException( + "Invalid Stochastic moving average type."); } } else @@ -128,36 +135,39 @@ internal static List CalcStoch( } else if (i >= signalPeriods) { - - // SMA case - if (movingAverageType is MaType.SMA) // TODO: || double.IsNaN(prevD) to re/initialize SMMA? - { - double sum = 0; - for (int p = i - signalPeriods + 1; p <= i; p++) - { - sum += k[p]; - } - - signal = sum / signalPeriods; - } - - // SMMA case - else if (movingAverageType is MaType.SMMA) - { - // re/initialize - if (double.IsNaN(prevD)) - { - prevD = k[i]; - } - - double d = ((prevD * (signalPeriods - 1)) + k[i]) / signalPeriods; - signal = d; - prevD = d; - } - - else + switch (movingAverageType) { - throw new InvalidOperationException("Invalid Stochastic moving average type."); + // SMA case + // TODO: || double.IsNaN(prevD) to re/initialize SMMA? + case MaType.Sma: + { + double sum = 0; + for (int p = i - signalPeriods + 1; p <= i; p++) + { + sum += k[p]; + } + + signal = sum / signalPeriods; + break; + } + + // SMMA case + case MaType.Smma: + { + // re/initialize + if (double.IsNaN(prevD)) + { + prevD = k[i]; + } + + double d = (prevD * (signalPeriods - 1) + k[i]) / signalPeriods; + signal = d; + prevD = d; + break; + } + + default: + throw new InvalidOperationException("Invalid Stochastic moving average type."); } } else @@ -165,11 +175,11 @@ internal static List CalcStoch( signal = double.NaN; } - results.Add(new StochResult( + results.Add(new( Timestamp: q.Timestamp, Oscillator: oscillator.NaN2Null(), Signal: signal.NaN2Null(), - PercentJ: ((kFactor * oscillator) - (dFactor * signal)).NaN2Null())); + PercentJ: (kFactor * oscillator - dFactor * signal).NaN2Null())); } return results; } diff --git a/src/s-z/StochRsi/StochRsi.Series.cs b/src/s-z/StochRsi/StochRsi.Series.cs index 50daa47a2..53ebab948 100644 --- a/src/s-z/StochRsi/StochRsi.Series.cs +++ b/src/s-z/StochRsi/StochRsi.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcStochRsi( + private static List CalcStochRsi( this List source, int rsiPeriods, int stochPeriods, @@ -24,7 +24,7 @@ internal static List CalcStochRsi( for (int i = 0; i < initPeriods; i++) { var s = source[i]; - results.Add(new StochRsiResult { Timestamp = s.Timestamp }); + results.Add(new() { Timestamp = s.Timestamp }); } // get Stochastic of RSI @@ -42,14 +42,14 @@ internal static List CalcStochRsi( .CalcStoch( stochPeriods, signalPeriods, - smoothPeriods, 3, 2, MaType.SMA) + smoothPeriods, 3, 2, MaType.Sma) .ToList(); // add stoch results for (int i = rsiPeriods + stochPeriods - 1; i < length; i++) { StochResult r = stoResults[i - rsiPeriods]; - results.Add(new StochRsiResult { + results.Add(new() { Timestamp = r.Timestamp, StochRsi = r.Oscillator, Signal = r.Signal diff --git a/src/s-z/SuperTrend/SuperTrend.Series.cs b/src/s-z/SuperTrend/SuperTrend.Series.cs index ee8c7bbba..35f3a1e28 100644 --- a/src/s-z/SuperTrend/SuperTrend.Series.cs +++ b/src/s-z/SuperTrend/SuperTrend.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcSuperTrend( + private static List CalcSuperTrend( this List qdList, int lookbackPeriods, double multiplier) @@ -37,8 +37,8 @@ internal static List CalcSuperTrend( double? prevClose = qdList[i - 1].Close; // potential bands - double? upperEval = mid + (multiplier * atr); - double? lowerEval = mid - (multiplier * atr); + double? upperEval = mid + multiplier * atr; + double? lowerEval = mid - multiplier * atr; // initial values // TODO: update healing, without requiring specific indexing @@ -85,7 +85,7 @@ internal static List CalcSuperTrend( lowerOnly = null; } - results.Add(new SuperTrendResult( + results.Add(new( Timestamp: q.Timestamp, SuperTrend: (decimal?)superTrend, UpperBand: (decimal?)upperOnly, diff --git a/src/s-z/T3/T3.Series.cs b/src/s-z/T3/T3.Series.cs index aa0112b62..f34fc01ed 100644 --- a/src/s-z/T3/T3.Series.cs +++ b/src/s-z/T3/T3.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcT3( + private static List CalcT3( this List source, int lookbackPeriods, double volumeFactor) @@ -21,9 +21,9 @@ internal static List CalcT3( double a = volumeFactor; double c1 = -a * a * a; - double c2 = (3 * a * a) + (3 * a * a * a); - double c3 = (-6 * a * a) - (3 * a) - (3 * a * a * a); - double c4 = 1 + (3 * a) + (a * a * a) + (3 * a * a); + double c2 = 3 * a * a + 3 * a * a * a; + double c3 = -6 * a * a - 3 * a - 3 * a * a * a; + double c4 = 1 + 3 * a + a * a * a + 3 * a * a; double e1 = double.NaN; double e2 = double.NaN; @@ -52,9 +52,9 @@ internal static List CalcT3( e6 += k * (e5 - e6); // T3 moving average - results.Add(new T3Result( + results.Add(new( Timestamp: s.Timestamp, - T3: ((c1 * e6) + (c2 * e5) + (c3 * e4) + (c4 * e3)).NaN2Null())); + T3: (c1 * e6 + c2 * e5 + c3 * e4 + c4 * e3).NaN2Null())); } return results; diff --git a/src/s-z/Tema/Tema.Series.cs b/src/s-z/Tema/Tema.Series.cs index 92a3ade9c..24473c3ab 100644 --- a/src/s-z/Tema/Tema.Series.cs +++ b/src/s-z/Tema/Tema.Series.cs @@ -5,7 +5,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { // calculate series - internal static List CalcTema( + private static List CalcTema( this List source, int lookbackPeriods) where T : IReusable @@ -54,14 +54,14 @@ internal static List CalcTema( // normal TEMA else { - ema1 = lastEma1 + (k * (s.Value - lastEma1)); - ema2 = lastEma2 + (k * (ema1 - lastEma2)); - ema3 = lastEma3 + (k * (ema2 - lastEma3)); + ema1 = lastEma1 + k * (s.Value - lastEma1); + ema2 = lastEma2 + k * (ema1 - lastEma2); + ema3 = lastEma3 + k * (ema2 - lastEma3); } - results.Add(new TemaResult( + results.Add(new( Timestamp: s.Timestamp, - Tema: ((3 * ema1) - (3 * ema2) + ema3).NaN2Null())); + Tema: (3 * ema1 - 3 * ema2 + ema3).NaN2Null())); lastEma1 = ema1; lastEma2 = ema2; diff --git a/src/s-z/Tema/Tema.Utilities.cs b/src/s-z/Tema/Tema.Utilities.cs index ad438bec5..80b403472 100644 --- a/src/s-z/Tema/Tema.Utilities.cs +++ b/src/s-z/Tema/Tema.Utilities.cs @@ -12,6 +12,6 @@ public static IEnumerable RemoveWarmupPeriods( .ToList() .FindIndex(x => x.Tema != null) + 1; - return results.Remove((3 * n) + 100); + return results.Remove(3 * n + 100); } } diff --git a/src/s-z/Tr/Tr.Series.cs b/src/s-z/Tr/Tr.Series.cs index a2984698b..bf7a626d2 100644 --- a/src/s-z/Tr/Tr.Series.cs +++ b/src/s-z/Tr/Tr.Series.cs @@ -5,7 +5,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { // calculate series - internal static List CalcTr( + private static List CalcTr( this List qdList) { // initialize diff --git a/src/s-z/Trix/Trix.Series.cs b/src/s-z/Trix/Trix.Series.cs index c87371a63..6c989d985 100644 --- a/src/s-z/Trix/Trix.Series.cs +++ b/src/s-z/Trix/Trix.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcTrix( + private static List CalcTrix( this List source, int lookbackPeriods) where T : IReusable @@ -55,13 +55,13 @@ internal static List CalcTrix( // normal TRIX else { - ema1 = lastEma1 + (k * (s.Value - lastEma1)); - ema2 = lastEma2 + (k * (ema1 - lastEma2)); - ema3 = lastEma3 + (k * (ema2 - lastEma3)); + ema1 = lastEma1 + k * (s.Value - lastEma1); + ema2 = lastEma2 + k * (ema1 - lastEma2); + ema3 = lastEma3 + k * (ema2 - lastEma3); double trix = 100 * (ema3 - lastEma3) / lastEma3; - results.Add(new TrixResult( + results.Add(new( Timestamp: s.Timestamp, Ema3: ema3.NaN2Null(), Trix: trix.NaN2Null())); diff --git a/src/s-z/Trix/Trix.Utilities.cs b/src/s-z/Trix/Trix.Utilities.cs index 2849feb50..fbf580205 100644 --- a/src/s-z/Trix/Trix.Utilities.cs +++ b/src/s-z/Trix/Trix.Utilities.cs @@ -12,6 +12,6 @@ public static IEnumerable RemoveWarmupPeriods( .ToList() .FindIndex(x => x.Trix != null); - return results.Remove((3 * n) + 100); + return results.Remove(3 * n + 100); } } diff --git a/src/s-z/Tsi/Tsi.Series.cs b/src/s-z/Tsi/Tsi.Series.cs index 5c59b197a..5b15d9bc5 100644 --- a/src/s-z/Tsi/Tsi.Series.cs +++ b/src/s-z/Tsi/Tsi.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcTsi( + private static List CalcTsi( this List source, int lookbackPeriods, int smoothPeriods, @@ -73,35 +73,35 @@ internal static List CalcTsi( // normal first smoothing else { - cs1[i] = ((c[i] - cs1[i - 1]) * mult1) + cs1[i - 1]; - as1[i] = ((a[i] - as1[i - 1]) * mult1) + as1[i - 1]; + cs1[i] = (c[i] - cs1[i - 1]) * mult1 + cs1[i - 1]; + as1[i] = (a[i] - as1[i - 1]) * mult1 + as1[i - 1]; } // re/initialize second smoothing if (double.IsNaN(cs2[i - 1]) && i >= smoothPeriods) { - double sumCS = 0; - double sumAS = 0; + double sumCs = 0; + double sumAs = 0; for (int p = i - smoothPeriods + 1; p <= i; p++) { - sumCS += cs1[p]; - sumAS += as1[p]; + sumCs += cs1[p]; + sumAs += as1[p]; } - cs2[i] = sumCS / smoothPeriods; - as2[i] = sumAS / smoothPeriods; + cs2[i] = sumCs / smoothPeriods; + as2[i] = sumAs / smoothPeriods; } // normal second smoothing else { - cs2[i] = ((cs1[i] - cs2[i - 1]) * mult2) + cs2[i - 1]; - as2[i] = ((as1[i] - as2[i - 1]) * mult2) + as2[i - 1]; + cs2[i] = (cs1[i] - cs2[i - 1]) * mult2 + cs2[i - 1]; + as2[i] = (as1[i] - as2[i - 1]) * mult2 + as2[i - 1]; } // true strength index - double tsi = (as2[i] != 0) + double tsi = as2[i] != 0 ? 100d * (cs2[i] / as2[i]) : double.NaN; @@ -125,7 +125,7 @@ internal static List CalcTsi( // normal signal else { - signal = ((tsi - prevSignal) * multS) + prevSignal; + signal = (tsi - prevSignal) * multS + prevSignal; } } else @@ -135,7 +135,7 @@ internal static List CalcTsi( : double.NaN; } - results.Add(new TsiResult( + results.Add(new( Timestamp: s.Timestamp, Tsi: tsi.NaN2Null(), Signal: signal.NaN2Null())); diff --git a/src/s-z/UlcerIndex/UlcerIndex.Models.cs b/src/s-z/UlcerIndex/UlcerIndex.Models.cs index e959840e0..ee2cd7620 100644 --- a/src/s-z/UlcerIndex/UlcerIndex.Models.cs +++ b/src/s-z/UlcerIndex/UlcerIndex.Models.cs @@ -9,5 +9,5 @@ public readonly record struct UlcerIndexResult double IReusable.Value => UlcerIndex.Null2NaN(); [Obsolete("Rename UI to UlcerIndex")] // v3.0.0 - public readonly double? UI => UlcerIndex; + public double? UI => UlcerIndex; } diff --git a/src/s-z/UlcerIndex/UlcerIndex.Series.cs b/src/s-z/UlcerIndex/UlcerIndex.Series.cs index a79f706d0..0ddf303e6 100644 --- a/src/s-z/UlcerIndex/UlcerIndex.Series.cs +++ b/src/s-z/UlcerIndex/UlcerIndex.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcUlcerIndex( + private static List CalcUlcerIndex( this List source, int lookbackPeriods) where T : IReusable @@ -41,7 +41,7 @@ internal static List CalcUlcerIndex( } } - double percentDrawdown = (maxClose == 0) ? double.NaN + double percentDrawdown = maxClose == 0 ? double.NaN : 100 * ((ps.Value - maxClose) / maxClose); sumSquared += percentDrawdown * percentDrawdown; diff --git a/src/s-z/Ultimate/Ultimate.Series.cs b/src/s-z/Ultimate/Ultimate.Series.cs index ab9681e01..6a4c8a1e7 100644 --- a/src/s-z/Ultimate/Ultimate.Series.cs +++ b/src/s-z/Ultimate/Ultimate.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcUltimate( + private static List CalcUltimate( this List qdList, int shortPeriods, int middlePeriods, @@ -35,13 +35,13 @@ internal static List CalcUltimate( if (i >= longPeriods) { - double sumBP1 = 0; - double sumBP2 = 0; - double sumBP3 = 0; + double sumBp1 = 0; + double sumBp2 = 0; + double sumBp3 = 0; - double sumTR1 = 0; - double sumTR2 = 0; - double sumTR3 = 0; + double sumTr1 = 0; + double sumTr2 = 0; + double sumTr3 = 0; for (int p = i + 1 - longPeriods; p <= i; p++) { @@ -50,34 +50,34 @@ internal static List CalcUltimate( // short aggregate if (pIndex > i + 1 - shortPeriods) { - sumBP1 += bp[p]; - sumTR1 += tr[p]; + sumBp1 += bp[p]; + sumTr1 += tr[p]; } // middle aggregate if (pIndex > i + 1 - middlePeriods) { - sumBP2 += bp[p]; - sumTR2 += tr[p]; + sumBp2 += bp[p]; + sumTr2 += tr[p]; } // long aggregate - sumBP3 += bp[p]; - sumTR3 += tr[p]; + sumBp3 += bp[p]; + sumTr3 += tr[p]; } - double avg1 = (sumTR1 == 0) ? double.NaN : sumBP1 / sumTR1; - double avg2 = (sumTR2 == 0) ? double.NaN : sumBP2 / sumTR2; - double avg3 = (sumTR3 == 0) ? double.NaN : sumBP3 / sumTR3; + double avg1 = sumTr1 == 0 ? double.NaN : sumBp1 / sumTr1; + double avg2 = sumTr2 == 0 ? double.NaN : sumBp2 / sumTr2; + double avg3 = sumTr3 == 0 ? double.NaN : sumBp3 / sumTr3; - ultimate = (100d * ((4d * avg1) + (2d * avg2) + avg3) / 7d).NaN2Null(); + ultimate = (100d * (4d * avg1 + 2d * avg2 + avg3) / 7d).NaN2Null(); } else { ultimate = null; } - results.Add(new UltimateResult( + results.Add(new( Timestamp: q.Timestamp, Ultimate: ultimate)); diff --git a/src/s-z/VolatilityStop/VolatilityStop.Series.cs b/src/s-z/VolatilityStop/VolatilityStop.Series.cs index d3ea35151..458a9bd48 100644 --- a/src/s-z/VolatilityStop/VolatilityStop.Series.cs +++ b/src/s-z/VolatilityStop/VolatilityStop.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcVolatilityStop( + private static List CalcVolatilityStop( this List qdList, int lookbackPeriods, double multiplier) @@ -37,7 +37,7 @@ internal static List CalcVolatilityStop( { IReusable init = reList[i]; sic = isLong ? Math.Max(sic, init.Value) : Math.Min(sic, init.Value); - results.Add(new VolatilityStopResult { Timestamp = init.Timestamp }); + results.Add(new() { Timestamp = init.Timestamp }); } // roll through quotes @@ -83,7 +83,7 @@ internal static List CalcVolatilityStop( sic = isLong ? Math.Max(sic, s.Value) : Math.Min(sic, s.Value); } - results.Add(new VolatilityStopResult( + results.Add(new( Timestamp: s.Timestamp, Sar: sar, IsStop: isStop, diff --git a/src/s-z/Vortex/Vortex.Series.cs b/src/s-z/Vortex/Vortex.Series.cs index ebd2893fc..81186735f 100644 --- a/src/s-z/Vortex/Vortex.Series.cs +++ b/src/s-z/Vortex/Vortex.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcVortex( + private static List CalcVortex( this List qdList, int lookbackPeriods) { @@ -75,7 +75,7 @@ internal static List CalcVortex( } } - results.Add(new VortexResult( + results.Add(new( Timestamp: q.Timestamp, Pvi: pvi.NaN2Null(), Nvi: nvi.NaN2Null())); diff --git a/src/s-z/Vwap/Vwap.Series.cs b/src/s-z/Vwap/Vwap.Series.cs index e9c04d2fb..b099fe98f 100644 --- a/src/s-z/Vwap/Vwap.Series.cs +++ b/src/s-z/Vwap/Vwap.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcVwap( + private static List CalcVwap( this List qdList, DateTime? startDate = null) { @@ -23,7 +23,7 @@ internal static List CalcVwap( startDate ??= qdList[0].Timestamp; double? cumVolume = 0; - double? cumVolumeTP = 0; + double? cumVolumeTp = 0; // roll through quotes for (int i = 0; i < length; i++) @@ -40,16 +40,16 @@ internal static List CalcVwap( if (q.Timestamp >= startDate) { cumVolume += v; - cumVolumeTP += v * (h + l + c) / 3; + cumVolumeTp += v * (h + l + c) / 3; - vwap = (cumVolume != 0) ? (cumVolumeTP / cumVolume) : null; + vwap = cumVolume != 0 ? cumVolumeTp / cumVolume : null; } else { vwap = null; } - results.Add(new VwapResult( + results.Add(new( Timestamp: q.Timestamp, Vwap: vwap)); } diff --git a/src/s-z/Vwma/Vwma.Series.cs b/src/s-z/Vwma/Vwma.Series.cs index 7d7e0447b..30be17b46 100644 --- a/src/s-z/Vwma/Vwma.Series.cs +++ b/src/s-z/Vwma/Vwma.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcVwma( + private static List CalcVwma( this List qdList, int lookbackPeriods) { @@ -36,14 +36,14 @@ internal static List CalcVwma( sumVl += v; } - vwma = sumVl != 0 ? (sumCl / sumVl) : double.NaN; + vwma = sumVl != 0 ? sumCl / sumVl : double.NaN; } else { vwma = double.NaN; } - results.Add(new VwmaResult( + results.Add(new( Timestamp: q.Timestamp, Vwma: vwma.NaN2Null())); } diff --git a/src/s-z/WilliamsR/WilliamsR.Series.cs b/src/s-z/WilliamsR/WilliamsR.Series.cs index 26bde3a04..90f95e697 100644 --- a/src/s-z/WilliamsR/WilliamsR.Series.cs +++ b/src/s-z/WilliamsR/WilliamsR.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcWilliamsR( + private static List CalcWilliamsR( this List qdList, int lookbackPeriods) { @@ -12,7 +12,7 @@ internal static List CalcWilliamsR( WilliamsR.Validate(lookbackPeriods); // convert Fast Stochastic to William %R - return qdList.CalcStoch(lookbackPeriods, 1, 1, 3, 2, MaType.SMA) + return qdList.CalcStoch(lookbackPeriods, 1, 1, 3, 2, MaType.Sma) .Select(s => new WilliamsResult { Timestamp = s.Timestamp, WilliamsR = s.Oscillator - 100 diff --git a/src/s-z/Wma/Wma.Series.cs b/src/s-z/Wma/Wma.Series.cs index 1ff039b77..27fd37e33 100644 --- a/src/s-z/Wma/Wma.Series.cs +++ b/src/s-z/Wma/Wma.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcWma( + private static List CalcWma( this List source, int lookbackPeriods) where T : IReusable @@ -39,7 +39,7 @@ internal static List CalcWma( wma = double.NaN; } - results.Add(new WmaResult( + results.Add(new( Timestamp: s.Timestamp, Wma: wma.NaN2Null())); } diff --git a/src/s-z/ZigZag/ZigZag.Models.cs b/src/s-z/ZigZag/ZigZag.Models.cs index f3c13ff98..1de03d546 100644 --- a/src/s-z/ZigZag/ZigZag.Models.cs +++ b/src/s-z/ZigZag/ZigZag.Models.cs @@ -14,7 +14,7 @@ public readonly record struct ZigZagResult internal class ZigZagEval { - internal int Index { get; set; } + internal int Index { get; init; } internal decimal? High { get; set; } internal decimal? Low { get; set; } } diff --git a/src/s-z/ZigZag/ZigZag.Series.cs b/src/s-z/ZigZag/ZigZag.Series.cs index 6a865e46b..c6f0ed580 100644 --- a/src/s-z/ZigZag/ZigZag.Series.cs +++ b/src/s-z/ZigZag/ZigZag.Series.cs @@ -4,7 +4,7 @@ namespace Skender.Stock.Indicators; public static partial class Indicator { - internal static List CalcZigZag( + private static List CalcZigZag( this List quotesList, EndType endType = EndType.Close, decimal percentChange = 5) @@ -16,16 +16,13 @@ internal static List CalcZigZag( // initialize int length = quotesList.Count; List results = new(length); - TQuote q0; if (length == 0) { return results; } - else - { - q0 = quotesList[0]; - } + + TQuote q0 = quotesList[0]; ZigZagEval eval = GetZigZagEval(endType, 1, q0); decimal changeThreshold = percentChange / 100m; @@ -48,8 +45,6 @@ internal static List CalcZigZag( PointType = "L" }; - int finalPointIndex = length; - // roll through quotes, to find initial trend for (int i = 0; i < length; i++) { @@ -58,10 +53,10 @@ internal static List CalcZigZag( eval = GetZigZagEval(endType, index, q); - decimal? changeUp = (lastLowPoint.Value == 0) ? null + decimal? changeUp = lastLowPoint.Value == 0 ? null : (eval.High - lastLowPoint.Value) / lastLowPoint.Value; - decimal? changeDn = (lastHighPoint.Value == 0) ? null + decimal? changeDn = lastHighPoint.Value == 0 ? null : (lastHighPoint.Value - eval.Low) / lastHighPoint.Value; if (changeUp >= changeThreshold && changeUp > changeDn) @@ -86,7 +81,7 @@ internal static List CalcZigZag( results.Add(firstResult); // find and draw lines - while (lastPoint.Index < finalPointIndex) + while (lastPoint.Index < length) { ZigZagPoint nextPoint = EvaluateNextPoint(quotesList, endType, changeThreshold, lastPoint); string lastDirection = lastPoint.PointType; @@ -139,7 +134,7 @@ private static ZigZagPoint EvaluateNextPoint( } else { - change = (extremePoint.Value == 0) ? null + change = extremePoint.Value == 0 ? null : (extremePoint.Value - eval.Low) / extremePoint.Value; } } @@ -153,7 +148,7 @@ private static ZigZagPoint EvaluateNextPoint( } else { - change = (extremePoint.Value == 0) ? null + change = extremePoint.Value == 0 ? null : (eval.High - extremePoint.Value) / extremePoint.Value; } } @@ -192,9 +187,9 @@ private static void DrawZigZagLine(List results, List quotes = []; - internal static IEnumerable otherQuotes = []; - internal static IEnumerable badQuotes = []; - internal static IEnumerable bigQuotes = []; - internal static IEnumerable maxQuotes = []; - internal static IEnumerable longishQuotes = []; - internal static IEnumerable longestQuotes = []; - internal static IEnumerable mismatchQuotes = []; - internal static IEnumerable noquotes = []; - internal static IEnumerable onequote = []; - internal static IEnumerable randomQuotes = []; - internal static IEnumerable zeroesQuotes = []; - internal static IEnumerable<(DateTime, double)> tupleNanny = []; + internal static IEnumerable Quotes = []; + internal static IEnumerable OtherQuotes = []; + internal static IEnumerable BadQuotes = []; + internal static IEnumerable BigQuotes = []; + internal static IEnumerable LongishQuotes = []; + internal static IEnumerable LongestQuotes = []; + internal static IEnumerable MismatchQuotes = []; + internal static IEnumerable Noquotes = []; + internal static IEnumerable Onequote = []; + internal static IEnumerable RandomQuotes = []; + internal static IEnumerable ZeroesQuotes = []; internal TestBase() { try { - quotes = TestData.GetDefault(); - otherQuotes = TestData.GetCompare(); - badQuotes = TestData.GetBad(); - bigQuotes = TestData.GetTooBig(); - maxQuotes = TestData.GetMax(); - longishQuotes = TestData.GetLongish(); - longestQuotes = TestData.GetLongest(); - mismatchQuotes = TestData.GetMismatch(); - noquotes = new List(); - onequote = TestData.GetDefault(1); - randomQuotes = TestData.GetRandom(1000); - zeroesQuotes = TestData.GetZeros(); + Quotes = TestData.GetDefault(); + OtherQuotes = TestData.GetCompare(); + BadQuotes = TestData.GetBad(); + BigQuotes = TestData.GetTooBig(); + LongishQuotes = TestData.GetLongish(); + LongestQuotes = TestData.GetLongest(); + MismatchQuotes = TestData.GetMismatch(); + Noquotes = new List(); + Onequote = TestData.GetDefault(1); + RandomQuotes = TestData.GetRandom(1000); + ZeroesQuotes = TestData.GetZeros(); } catch (Exception ex) { @@ -61,8 +58,8 @@ internal TestBase() [TestClass] public abstract class SeriesTestBase : TestBase { - internal readonly DateTime evalDate - = DateTime.ParseExact("12/31/2018", "MM/dd/yyyy", EnglishCulture); + internal readonly DateTime EvalDate + = DateTime.ParseExact("12/31/2018", "MM/dd/yyyy", englishCulture); // TODO: once caught up, make these abstract instead of virtual diff --git a/tests/indicators/_common/Candles/Candles.Tests.cs b/tests/indicators/_common/Candles/Candles.Tests.cs index a0a6b8e9a..aefdf70a6 100644 --- a/tests/indicators/_common/Candles/Candles.Tests.cs +++ b/tests/indicators/_common/Candles/Candles.Tests.cs @@ -15,20 +15,20 @@ public void SortCandles() Assert.AreEqual(502, candles.Count); // sample values - DateTime firstDate = DateTime.ParseExact("01/18/2016", "MM/dd/yyyy", EnglishCulture); + DateTime firstDate = DateTime.ParseExact("01/18/2016", "MM/dd/yyyy", englishCulture); Assert.AreEqual(firstDate, candles[0].Timestamp); - DateTime lastDate = DateTime.ParseExact("12/31/2018", "MM/dd/yyyy", EnglishCulture); + DateTime lastDate = DateTime.ParseExact("12/31/2018", "MM/dd/yyyy", englishCulture); Assert.AreEqual(lastDate, candles.LastOrDefault().Timestamp); - DateTime spotDate = DateTime.ParseExact("03/16/2017", "MM/dd/yyyy", EnglishCulture); + DateTime spotDate = DateTime.ParseExact("03/16/2017", "MM/dd/yyyy", englishCulture); Assert.AreEqual(spotDate, candles[50].Timestamp); } [TestMethod] public void CandleValues() { - List candles = quotes.ToCandleResults(); + List candles = Quotes.ToCandleResults(); // proper quantities Assert.AreEqual(502, candles.Count); @@ -72,7 +72,7 @@ public void CandleValues() [TestMethod] public void ToCandles() { - IEnumerable candles = quotes.ToCandles(); - Assert.AreEqual(quotes.Count(), candles.Count()); + IEnumerable candles = Quotes.ToCandles(); + Assert.AreEqual(Quotes.Count(), candles.Count()); } } diff --git a/tests/indicators/_common/Generics/Pruning.Tests.cs b/tests/indicators/_common/Generics/Pruning.Tests.cs index e3993e3e5..a65f51085 100644 --- a/tests/indicators/_common/Generics/Pruning.Tests.cs +++ b/tests/indicators/_common/Generics/Pruning.Tests.cs @@ -8,14 +8,14 @@ public void Remove() { // specific periods IEnumerable results = - quotes.GetHeikinAshi() + Quotes.GetHeikinAshi() .RemoveWarmupPeriods(102); Assert.AreEqual(400, results.Count()); // bad remove period Assert.ThrowsException(() - => quotes.GetAdx(14).RemoveWarmupPeriods(-1)); + => Quotes.GetAdx().RemoveWarmupPeriods(-1)); } [TestMethod] @@ -23,7 +23,7 @@ public void RemoveTooMany() { // more than available IEnumerable results = - quotes.GetHeikinAshi() + Quotes.GetHeikinAshi() .RemoveWarmupPeriods(600); Assert.AreEqual(0, results.Count()); diff --git a/tests/indicators/_common/Generics/Seek.Tests.cs b/tests/indicators/_common/Generics/Seek.Tests.cs index 73d2fd3fd..f175ee0b7 100644 --- a/tests/indicators/_common/Generics/Seek.Tests.cs +++ b/tests/indicators/_common/Generics/Seek.Tests.cs @@ -11,7 +11,7 @@ public void FindSeries() // find specific date DateTime findDate - = DateTime.ParseExact("2018-12-31", "yyyy-MM-dd", EnglishCulture); + = DateTime.ParseExact("2018-12-31", "yyyy-MM-dd", englishCulture); EmaResult r = emaResults.Find(findDate); Assert.AreEqual(249.3519, r.Ema.Round(4)); @@ -25,7 +25,7 @@ public void FindSeriesNone() // find specific date DateTime findDate - = DateTime.ParseExact("1928-10-29", "yyyy-MM-dd", EnglishCulture); + = DateTime.ParseExact("1928-10-29", "yyyy-MM-dd", englishCulture); Assert.ThrowsException( () => emaResults.Find(findDate)); @@ -40,7 +40,7 @@ public void FindSeriesIndex() // find specific date DateTime findDate - = DateTime.ParseExact("2018-12-31", "yyyy-MM-dd", EnglishCulture); + = DateTime.ParseExact("2018-12-31", "yyyy-MM-dd", englishCulture); int i = quotes.FindIndex(findDate); Assert.AreEqual(501, i); diff --git a/tests/indicators/_common/Generics/Sort.Tests.cs b/tests/indicators/_common/Generics/Sort.Tests.cs index e76f3e31a..10b8c6db7 100644 --- a/tests/indicators/_common/Generics/Sort.Tests.cs +++ b/tests/indicators/_common/Generics/Sort.Tests.cs @@ -11,15 +11,15 @@ public void ToSortedCollection() // baseline for comparison List baseline = [ - new SmaResult() { Timestamp = DateTime.Parse("1/1/2000", EnglishCulture), Sma = null }, - new SmaResult() { Timestamp = DateTime.Parse("1/2/2000", EnglishCulture), Sma = null }, - new SmaResult() { Timestamp = DateTime.Parse("1/9/2000", EnglishCulture), Sma = null }, - new SmaResult() { Timestamp = DateTime.Parse("1/3/2000", EnglishCulture), Sma = 3 }, - new SmaResult() { Timestamp = DateTime.Parse("1/4/2000", EnglishCulture), Sma = 4 }, - new SmaResult() { Timestamp = DateTime.Parse("1/5/2000", EnglishCulture), Sma = 5 }, - new SmaResult() { Timestamp = DateTime.Parse("1/6/2000", EnglishCulture), Sma = 6 }, - new SmaResult() { Timestamp = DateTime.Parse("1/7/2000", EnglishCulture), Sma = 7 }, - new SmaResult() { Timestamp = DateTime.Parse("1/8/2000", EnglishCulture), Sma = double.NaN } + new(Timestamp: DateTime.Parse("1/1/2000", englishCulture), Sma: null), + new(Timestamp: DateTime.Parse("1/2/2000", englishCulture), Sma: null), + new(Timestamp: DateTime.Parse("1/9/2000", englishCulture), Sma: null), + new(Timestamp: DateTime.Parse("1/3/2000", englishCulture), Sma: 3), + new(Timestamp: DateTime.Parse("1/4/2000", englishCulture), Sma: 4), + new(Timestamp: DateTime.Parse("1/5/2000", englishCulture), Sma: 5), + new(Timestamp: DateTime.Parse("1/6/2000", englishCulture), Sma: 6), + new(Timestamp: DateTime.Parse("1/7/2000", englishCulture), Sma: 7), + new(Timestamp: DateTime.Parse("1/8/2000", englishCulture), Sma: double.NaN) ]; // PUBLIC VARIANT, generic sorted Collection @@ -27,6 +27,6 @@ public void ToSortedCollection() .ToSortedCollection(); Assert.AreEqual(5, sortResults[4].Sma); - Assert.AreEqual(DateTime.Parse("1/9/2000", EnglishCulture), sortResults.LastOrDefault().Timestamp); + Assert.AreEqual(DateTime.Parse("1/9/2000", englishCulture), sortResults.LastOrDefault().Timestamp); } } diff --git a/tests/indicators/_common/Generics/Transforms.Tests.cs b/tests/indicators/_common/Generics/Transforms.Tests.cs index 5e4a9e939..f2ff438c7 100644 --- a/tests/indicators/_common/Generics/Transforms.Tests.cs +++ b/tests/indicators/_common/Generics/Transforms.Tests.cs @@ -8,7 +8,7 @@ public class TransformTests : SeriesTestBase [TestMethod] public void ToCollection() { - Collection collection = quotes + Collection collection = Quotes .ToSortedList() .ToCollection(); diff --git a/tests/indicators/_common/Math/Numerix.Tests.cs b/tests/indicators/_common/Math/Numerix.Tests.cs index 58a6b06bd..12a79fa63 100644 --- a/tests/indicators/_common/Math/Numerix.Tests.cs +++ b/tests/indicators/_common/Math/Numerix.Tests.cs @@ -3,17 +3,17 @@ namespace Tests.Common; [TestClass] public class NumerixTests : SeriesTestBase { - private readonly double[] closePrice = longishQuotes + private readonly double[] _closePrice = LongishQuotes .Select(x => (double)x.Close) .ToArray(); - private readonly double[] x = [1, 2, 3, 4, 5]; - private readonly double[] y = [0, 0, 0, 0]; + private readonly double[] _x = [1, 2, 3, 4, 5]; + private readonly double[] _y = [0, 0, 0, 0]; [TestMethod] public void StdDev() { - double sd = closePrice.StdDev(); + double sd = _closePrice.StdDev(); Assert.AreEqual(633.932098287, Math.Round(sd, 9)); } @@ -25,31 +25,31 @@ public void StdDev() [TestMethod] public void Slope() { - double s = Numerix.Slope(x, x); + double s = Numerix.Slope(_x, _x); Assert.AreEqual(1d, s); } [TestMethod] [ExpectedException(typeof(ArgumentNullException), "Null X parameter.")] - public void SlopeXnull() => Numerix.Slope(null, x); + public void SlopeXnull() => Numerix.Slope(null, _x); [TestMethod] [ExpectedException(typeof(ArgumentNullException), "Null Y parameter.")] - public void SlopeYnull() => Numerix.Slope(x, null); + public void SlopeYnull() => Numerix.Slope(_x, null); [TestMethod] [ExpectedException(typeof(ArgumentException), "X and Y different lengths.")] - public void SlopeMismatch() => Numerix.Slope(x, y); + public void SlopeMismatch() => Numerix.Slope(_x, _y); [TestMethod] public void RoundDownDate() { TimeSpan interval = PeriodSize.OneHour.ToTimeSpan(); - DateTime evDate = DateTime.Parse("2020-12-15 09:35:45", EnglishCulture); + DateTime evDate = DateTime.Parse("2020-12-15 09:35:45", englishCulture); DateTime rnDate = evDate.RoundDown(interval); - DateTime exDate = DateTime.Parse("2020-12-15 09:00:00", EnglishCulture); + DateTime exDate = DateTime.Parse("2020-12-15 09:00:00", englishCulture); Assert.AreEqual(exDate, rnDate); } diff --git a/tests/indicators/_common/Observables/AbstractProvider.Tests.cs b/tests/indicators/_common/Observables/AbstractProvider.Tests.cs index d95ae699c..afbeff510 100644 --- a/tests/indicators/_common/Observables/AbstractProvider.Tests.cs +++ b/tests/indicators/_common/Observables/AbstractProvider.Tests.cs @@ -6,7 +6,7 @@ public class ProviderTests : TestBase [TestMethod] public void Prefill() { - List quotesList = quotes + List quotesList = Quotes .ToSortedList() .Take(50) .ToList(); @@ -43,6 +43,12 @@ public void Prefill() provider.EndTransmission(); } + [TestMethod] + public void FindIndex() + { + Assert.Inconclusive("test not implemented"); + } + [TestMethod] public void RebuildCache() { diff --git a/tests/indicators/_common/Observables/Cache.Management.cs b/tests/indicators/_common/Observables/Cache.Management.cs index a7e10ece9..a987a86ef 100644 --- a/tests/indicators/_common/Observables/Cache.Management.cs +++ b/tests/indicators/_common/Observables/Cache.Management.cs @@ -28,7 +28,7 @@ public void Overflowing() QuoteProvider provider = new(); Quote q = new() { Timestamp = DateTime.Now }; // dup - var observer = provider + Use observer = provider .Use(CandlePart.Close); // overflowing, under threshold @@ -77,10 +77,10 @@ public void ActAddNew() [TestMethod] public void ActAddOld() // late arrival { - List quotesList = quotes + List quotesList = Quotes .ToSortedList(); - int length = quotes.Count(); + int length = Quotes.Count(); // add base quotes QuoteProvider provider = new(); diff --git a/tests/indicators/_common/Observables/ChainProvider.Tests.cs b/tests/indicators/_common/Observables/ChainProvider.Tests.cs index d1f892081..d44471e81 100644 --- a/tests/indicators/_common/Observables/ChainProvider.Tests.cs +++ b/tests/indicators/_common/Observables/ChainProvider.Tests.cs @@ -6,7 +6,7 @@ public class ChainProviderTests : TestBase, ITestChainProvider [TestMethod] public void ChainProvider() { - List quotesList = quotes + List quotesList = Quotes .ToSortedList(); int length = quotesList.Count; @@ -16,7 +16,7 @@ public void ChainProvider() // initialize observer Ema observer = provider - .Use(CandlePart.HL2) + .Use(CandlePart.Hl2) .ToEma(11); // emulate adding quotes to provider @@ -33,8 +33,8 @@ public void ChainProvider() .ToList(); // time-series, for comparison - List staticEma = quotes - .Use(CandlePart.HL2) + List staticEma = Quotes + .Use(CandlePart.Hl2) .GetEma(11) .ToList(); diff --git a/tests/indicators/_common/Observables/QuoteProvider.Tests.cs b/tests/indicators/_common/Observables/QuoteProvider.Tests.cs index ab64591e0..89c5fc50b 100644 --- a/tests/indicators/_common/Observables/QuoteProvider.Tests.cs +++ b/tests/indicators/_common/Observables/QuoteProvider.Tests.cs @@ -6,10 +6,10 @@ public class QuoteProviderTests : TestBase [TestMethod] public void AddQuote() { - List quotesList = quotes + List quotesList = Quotes .ToSortedList(); - int length = quotes.Count(); + int length = Quotes.Count(); // add base quotes (batch) QuoteProvider provider = new(); diff --git a/tests/indicators/_common/Quotes/Quote.Aggregates.Tests.cs b/tests/indicators/_common/Quotes/Quote.Aggregates.Tests.cs index 10b377659..beff800a8 100644 --- a/tests/indicators/_common/Quotes/Quote.Aggregates.Tests.cs +++ b/tests/indicators/_common/Quotes/Quote.Aggregates.Tests.cs @@ -1,4 +1,5 @@ namespace Tests.Common; +// ReSharper disable All [TestClass] public class QuoteAggregateTests : TestBase @@ -18,7 +19,7 @@ public void Aggregate() // sample values Quote r0 = results[0]; - Assert.AreEqual(DateTime.Parse("2020-12-15 09:30", EnglishCulture), r0.Timestamp); + Assert.AreEqual(DateTime.Parse("2020-12-15 09:30", englishCulture), r0.Timestamp); Assert.AreEqual(367.40m, r0.Open); Assert.AreEqual(367.775m, r0.High); Assert.AreEqual(367.02m, r0.Low); @@ -26,7 +27,7 @@ public void Aggregate() Assert.AreEqual(2401786m, r0.Volume); Quote r1 = results[1]; - Assert.AreEqual(DateTime.Parse("2020-12-15 09:45", EnglishCulture), r1.Timestamp); + Assert.AreEqual(DateTime.Parse("2020-12-15 09:45", englishCulture), r1.Timestamp); Assert.AreEqual(367.25m, r1.Open); Assert.AreEqual(367.44m, r1.High); Assert.AreEqual(366.69m, r1.Low); @@ -34,7 +35,7 @@ public void Aggregate() Assert.AreEqual(1669983m, r1.Volume); Quote r2 = results[2]; - Assert.AreEqual(DateTime.Parse("2020-12-15 10:00", EnglishCulture), r2.Timestamp); + Assert.AreEqual(DateTime.Parse("2020-12-15 10:00", englishCulture), r2.Timestamp); Assert.AreEqual(366.85m, r2.Open); Assert.AreEqual(367.17m, r2.High); Assert.AreEqual(366.57m, r2.Low); @@ -62,7 +63,7 @@ public void AggregateTimeSpan() // sample values Quote r0 = results[0]; - Assert.AreEqual(DateTime.Parse("2020-12-15 09:30", EnglishCulture), r0.Timestamp); + Assert.AreEqual(DateTime.Parse("2020-12-15 09:30", englishCulture), r0.Timestamp); Assert.AreEqual(367.40m, r0.Open); Assert.AreEqual(367.775m, r0.High); Assert.AreEqual(367.02m, r0.Low); @@ -70,7 +71,7 @@ public void AggregateTimeSpan() Assert.AreEqual(2401786m, r0.Volume); Quote r1 = results[1]; - Assert.AreEqual(DateTime.Parse("2020-12-15 09:45", EnglishCulture), r1.Timestamp); + Assert.AreEqual(DateTime.Parse("2020-12-15 09:45", englishCulture), r1.Timestamp); Assert.AreEqual(367.25m, r1.Open); Assert.AreEqual(367.44m, r1.High); Assert.AreEqual(366.69m, r1.Low); @@ -78,7 +79,7 @@ public void AggregateTimeSpan() Assert.AreEqual(1669983m, r1.Volume); Quote r2 = results[2]; - Assert.AreEqual(DateTime.Parse("2020-12-15 10:00", EnglishCulture), r2.Timestamp); + Assert.AreEqual(DateTime.Parse("2020-12-15 10:00", englishCulture), r2.Timestamp); Assert.AreEqual(366.85m, r2.Open); Assert.AreEqual(367.17m, r2.High); Assert.AreEqual(366.57m, r2.Low); @@ -95,7 +96,7 @@ public void AggregateTimeSpan() public void AggregateMonth() { // aggregate - List results = quotes + List results = Quotes .Aggregate(PeriodSize.Month) .ToList(); @@ -104,7 +105,7 @@ public void AggregateMonth() // sample values Quote r0 = results[0]; - Assert.AreEqual(DateTime.Parse("2017-01-01", EnglishCulture), r0.Timestamp); + Assert.AreEqual(DateTime.Parse("2017-01-01", englishCulture), r0.Timestamp); Assert.AreEqual(212.61m, r0.Open); Assert.AreEqual(217.02m, r0.High); Assert.AreEqual(211.52m, r0.Low); @@ -112,7 +113,7 @@ public void AggregateMonth() Assert.AreEqual(1569087580m, r0.Volume); Quote r1 = results[1]; - Assert.AreEqual(DateTime.Parse("2017-02-01", EnglishCulture), r1.Timestamp); + Assert.AreEqual(DateTime.Parse("2017-02-01", englishCulture), r1.Timestamp); Assert.AreEqual(215.65m, r1.Open); Assert.AreEqual(224.20m, r1.High); Assert.AreEqual(214.29m, r1.Low); @@ -120,7 +121,7 @@ public void AggregateMonth() Assert.AreEqual(1444958340m, r1.Volume); Quote r23 = results[23]; - Assert.AreEqual(DateTime.Parse("2018-12-01", EnglishCulture), r23.Timestamp); + Assert.AreEqual(DateTime.Parse("2018-12-01", englishCulture), r23.Timestamp); Assert.AreEqual(273.47m, r23.Open); Assert.AreEqual(273.59m, r23.High); Assert.AreEqual(229.42m, r23.Low); @@ -133,5 +134,5 @@ public void AggregateMonth() public void BadAggregationSize() => // bad period size - quotes.Aggregate(TimeSpan.Zero); + Quotes.Aggregate(TimeSpan.Zero); } diff --git a/tests/indicators/_common/Quotes/Quote.Converters.Tests.cs b/tests/indicators/_common/Quotes/Quote.Converters.Tests.cs index b33578e94..b8ad91d09 100644 --- a/tests/indicators/_common/Quotes/Quote.Converters.Tests.cs +++ b/tests/indicators/_common/Quotes/Quote.Converters.Tests.cs @@ -1,6 +1,7 @@ using System.Collections.ObjectModel; namespace Tests.Common; +// ReSharper disable All [TestClass] public class QuoteUtilityTests : TestBase @@ -16,15 +17,15 @@ public void QuoteToSortedCollection() Assert.AreEqual(502, h.Count); // check first date - DateTime firstDate = DateTime.ParseExact("01/18/2016", "MM/dd/yyyy", EnglishCulture); + DateTime firstDate = DateTime.ParseExact("01/18/2016", "MM/dd/yyyy", englishCulture); Assert.AreEqual(firstDate, h[0].Timestamp); // check last date - DateTime lastDate = DateTime.ParseExact("12/31/2018", "MM/dd/yyyy", EnglishCulture); + DateTime lastDate = DateTime.ParseExact("12/31/2018", "MM/dd/yyyy", englishCulture); Assert.AreEqual(lastDate, h.LastOrDefault().Timestamp); // spot check an out of sequence date - DateTime spotDate = DateTime.ParseExact("03/16/2017", "MM/dd/yyyy", EnglishCulture); + DateTime spotDate = DateTime.ParseExact("03/16/2017", "MM/dd/yyyy", englishCulture); Assert.AreEqual(spotDate, h[50].Timestamp); } @@ -39,22 +40,22 @@ public void QuoteToSortedList() Assert.AreEqual(502, h.Count); // check first date - DateTime firstDate = DateTime.ParseExact("01/18/2016", "MM/dd/yyyy", EnglishCulture); + DateTime firstDate = DateTime.ParseExact("01/18/2016", "MM/dd/yyyy", englishCulture); Assert.AreEqual(firstDate, h[0].Timestamp); // check last date - DateTime lastDate = DateTime.ParseExact("12/31/2018", "MM/dd/yyyy", EnglishCulture); + DateTime lastDate = DateTime.ParseExact("12/31/2018", "MM/dd/yyyy", englishCulture); Assert.AreEqual(lastDate, h.LastOrDefault().Timestamp); // spot check an out of sequence date - DateTime spotDate = DateTime.ParseExact("03/16/2017", "MM/dd/yyyy", EnglishCulture); + DateTime spotDate = DateTime.ParseExact("03/16/2017", "MM/dd/yyyy", englishCulture); Assert.AreEqual(spotDate, h[50].Timestamp); } [TestMethod] public void QuoteToReusable() { - DateTime d = DateTime.Parse("5/5/2055", EnglishCulture); + DateTime d = DateTime.Parse("5/5/2055", englishCulture); decimal l = 111111111111111m; decimal o = 222222222222222m; @@ -77,35 +78,35 @@ public void QuoteToReusable() }; Assert.AreEqual( - NullMath.Round((double)o, 10), - NullMath.Round(q.ToReusable(CandlePart.Open).Value, 10)); + ((double)o).Round(10), + q.ToReusable(CandlePart.Open).Value.Round(10)); Assert.AreEqual( - NullMath.Round((double)h, 10), - NullMath.Round(q.ToReusable(CandlePart.High).Value, 10)); + ((double)h).Round(10), + q.ToReusable(CandlePart.High).Value.Round(10)); Assert.AreEqual( - NullMath.Round((double)l, 10), - NullMath.Round(q.ToReusable(CandlePart.Low).Value, 10)); + ((double)l).Round(10), + q.ToReusable(CandlePart.Low).Value.Round(10)); Assert.AreEqual( - NullMath.Round((double)c, 10), - NullMath.Round(q.ToReusable(CandlePart.Close).Value, 10)); + ((double)c).Round(10), + q.ToReusable(CandlePart.Close).Value.Round(10)); Assert.AreEqual( - NullMath.Round((double)v, 10), - NullMath.Round(q.ToReusable(CandlePart.Volume).Value, 10)); + ((double)v).Round(10), + q.ToReusable(CandlePart.Volume).Value.Round(10)); Assert.AreEqual( - NullMath.Round((double)hl2, 10), - NullMath.Round(q.ToReusable(CandlePart.HL2).Value, 10)); + ((double)hl2).Round(10), + q.ToReusable(CandlePart.Hl2).Value.Round(10)); Assert.AreEqual( - NullMath.Round((double)hlc3, 10), - NullMath.Round(q.ToReusable(CandlePart.HLC3).Value, 10)); + ((double)hlc3).Round(10), + q.ToReusable(CandlePart.Hlc3).Value.Round(10)); Assert.AreEqual( - NullMath.Round((double)oc2, 10), - NullMath.Round(q.ToReusable(CandlePart.OC2).Value, 10)); + ((double)oc2).Round(10), + q.ToReusable(CandlePart.Oc2).Value.Round(10)); Assert.AreEqual( - NullMath.Round((double)ohl3, 10), - NullMath.Round(q.ToReusable(CandlePart.OHL3).Value, 10)); + ((double)ohl3).Round(10), + q.ToReusable(CandlePart.Ohl3).Value.Round(10)); Assert.AreEqual( - NullMath.Round((double)ohlc4, 10), - NullMath.Round(q.ToReusable(CandlePart.OHLC4).Value, 10)); + ((double)ohlc4).Round(10), + q.ToReusable(CandlePart.Ohlc4).Value.Round(10)); // bad argument Assert.ThrowsException(() @@ -119,18 +120,18 @@ public void QuoteToReusable() [TestMethod] public void ToReusableList() { - var reusableList = quotes + IReadOnlyList reusableList = Quotes .ToReusableList(CandlePart.Close); Assert.IsNotNull(reusableList); Assert.AreEqual(502, reusableList.Count); - Assert.AreEqual(reusableList.LastOrDefault().Value, 245.28d); + Assert.AreEqual(reusableList[^1].Value, 245.28d); } [TestMethod] public void QuoteDToReusable() { - DateTime d = DateTime.Parse("5/5/2055", EnglishCulture); + DateTime d = DateTime.Parse("5/5/2055", englishCulture); double l = 111111111111111; double o = 222222222222222; @@ -153,35 +154,35 @@ public void QuoteDToReusable() }; Assert.AreEqual( - NullMath.Round((double)o, 10), - NullMath.Round(q.ToReusable(CandlePart.Open).Value, 10)); + o.Round(10), + q.ToReusable(CandlePart.Open).Value.Round(10)); Assert.AreEqual( - NullMath.Round((double)h, 10), - NullMath.Round(q.ToReusable(CandlePart.High).Value, 10)); + h.Round(10), + q.ToReusable(CandlePart.High).Value.Round(10)); Assert.AreEqual( - NullMath.Round((double)l, 10), - NullMath.Round(q.ToReusable(CandlePart.Low).Value, 10)); + l.Round(10), + q.ToReusable(CandlePart.Low).Value.Round(10)); Assert.AreEqual( - NullMath.Round((double)c, 10), - NullMath.Round(q.ToReusable(CandlePart.Close).Value, 10)); + c.Round(10), + q.ToReusable(CandlePart.Close).Value.Round(10)); Assert.AreEqual( - NullMath.Round((double)v, 10), - NullMath.Round(q.ToReusable(CandlePart.Volume).Value, 10)); + v.Round(10), + q.ToReusable(CandlePart.Volume).Value.Round(10)); Assert.AreEqual( - NullMath.Round((double)hl2, 10), - NullMath.Round(q.ToReusable(CandlePart.HL2).Value, 10)); + hl2.Round(10), + q.ToReusable(CandlePart.Hl2).Value.Round(10)); Assert.AreEqual( - NullMath.Round((double)hlc3, 10), - NullMath.Round(q.ToReusable(CandlePart.HLC3).Value, 10)); + hlc3.Round(10), + q.ToReusable(CandlePart.Hlc3).Value.Round(10)); Assert.AreEqual( - NullMath.Round((double)oc2, 10), - NullMath.Round(q.ToReusable(CandlePart.OC2).Value, 10)); + oc2.Round(10), + q.ToReusable(CandlePart.Oc2).Value.Round(10)); Assert.AreEqual( - NullMath.Round((double)ohl3, 10), - NullMath.Round(q.ToReusable(CandlePart.OHL3).Value, 10)); + ohl3.Round(10), + q.ToReusable(CandlePart.Ohl3).Value.Round(10)); Assert.AreEqual( - NullMath.Round((double)ohlc4, 10), - NullMath.Round(q.ToReusable(CandlePart.OHLC4).Value, 10)); + ohlc4.Round(10), + q.ToReusable(CandlePart.Ohlc4).Value.Round(10)); // bad argument Assert.ThrowsException(() diff --git a/tests/indicators/_common/Quotes/Quote.Equality.Tests.cs b/tests/indicators/_common/Quotes/Quote.Equality.Tests.cs index 0dac7019b..7b915f23e 100644 --- a/tests/indicators/_common/Quotes/Quote.Equality.Tests.cs +++ b/tests/indicators/_common/Quotes/Quote.Equality.Tests.cs @@ -3,14 +3,14 @@ namespace Tests.Common; [TestClass] public class QuoteEqualityTests : TestBase { - internal readonly DateTime evalDate - = DateTime.ParseExact("12/31/2018", "MM/dd/yyyy", EnglishCulture); + private readonly DateTime _evalDate + = DateTime.ParseExact("12/31/2018", "MM/dd/yyyy", englishCulture); [TestMethod] public void EqualQuotes() { Quote q1 = new() { - Timestamp = evalDate, + Timestamp = _evalDate, Open = 1m, High = 1m, Low = 1m, @@ -19,7 +19,7 @@ public void EqualQuotes() }; Quote q2 = new() { - Timestamp = evalDate, + Timestamp = _evalDate, Open = 1m, High = 1m, Low = 1m, @@ -28,7 +28,7 @@ public void EqualQuotes() }; Quote q3 = new() { - Timestamp = evalDate, + Timestamp = _evalDate, Open = 1m, High = 1m, Low = 1m, diff --git a/tests/indicators/_common/Quotes/Quote.Validation.Tests.cs b/tests/indicators/_common/Quotes/Quote.Validation.Tests.cs index 070de02f6..a0d6ac447 100644 --- a/tests/indicators/_common/Quotes/Quote.Validation.Tests.cs +++ b/tests/indicators/_common/Quotes/Quote.Validation.Tests.cs @@ -14,23 +14,23 @@ public void Validate() Assert.AreEqual(502, h.Count); // sample values - DateTime lastDate = DateTime.ParseExact("12/31/2018", "MM/dd/yyyy", EnglishCulture); + DateTime lastDate = DateTime.ParseExact("12/31/2018", "MM/dd/yyyy", englishCulture); Assert.AreEqual(lastDate, h[501].Timestamp); - DateTime spotDate = DateTime.ParseExact("02/01/2017", "MM/dd/yyyy", EnglishCulture); + DateTime spotDate = DateTime.ParseExact("02/01/2017", "MM/dd/yyyy", englishCulture); Assert.AreEqual(spotDate, h[20].Timestamp); } [TestMethod] public void ValidateLong() { - List h = longishQuotes.Validate().ToList(); + List h = LongishQuotes.Validate().ToList(); // proper quantities Assert.AreEqual(5285, h.Count); // sample values - DateTime lastDate = DateTime.ParseExact("09/04/2020", "MM/dd/yyyy", EnglishCulture); + DateTime lastDate = DateTime.ParseExact("09/04/2020", "MM/dd/yyyy", englishCulture); Assert.AreEqual(lastDate, h[5284].Timestamp); } @@ -46,7 +46,7 @@ public void ValidateCut() Assert.AreEqual(200, h.Count); // should be 20 results and no index corruption - List r1 = Indicator.GetSma(h.TakeLast(20), 14).ToList(); + List r1 = h.TakeLast(20).GetSma(14).ToList(); Assert.AreEqual(20, r1.Count); for (int i = 1; i < r1.Count; i++) @@ -55,7 +55,7 @@ public void ValidateCut() } // should be 50 results and no index corruption - List r2 = Indicator.GetSma(h.TakeLast(50), 14).ToList(); + List r2 = h.TakeLast(50).GetSma(14).ToList(); Assert.AreEqual(50, r2.Count); for (int i = 1; i < r2.Count; i++) @@ -79,11 +79,11 @@ public void DuplicateHistory() { List badHistory = [ - new Quote { Timestamp = DateTime.ParseExact("2017-01-03", "yyyy-MM-dd", EnglishCulture), Open = 214.86m, High = 220.33m, Low = 210.96m, Close = 216.99m, Volume = 5923254 }, - new Quote { Timestamp = DateTime.ParseExact("2017-01-04", "yyyy-MM-dd", EnglishCulture), Open = 214.75m, High = 228.00m, Low = 214.31m, Close = 226.99m, Volume = 11213471 }, - new Quote { Timestamp = DateTime.ParseExact("2017-01-05", "yyyy-MM-dd", EnglishCulture), Open = 226.42m, High = 227.48m, Low = 221.95m, Close = 226.75m, Volume = 5911695 }, - new Quote { Timestamp = DateTime.ParseExact("2017-01-06", "yyyy-MM-dd", EnglishCulture), Open = 226.93m, High = 230.31m, Low = 225.45m, Close = 229.01m, Volume = 5527893 }, - new Quote { Timestamp = DateTime.ParseExact("2017-01-06", "yyyy-MM-dd", EnglishCulture), Open = 228.97m, High = 231.92m, Low = 228.00m, Close = 231.28m, Volume = 3979484 } + new() { Timestamp = DateTime.ParseExact("2017-01-03", "yyyy-MM-dd", englishCulture), Open = 214.86m, High = 220.33m, Low = 210.96m, Close = 216.99m, Volume = 5923254 }, + new() { Timestamp = DateTime.ParseExact("2017-01-04", "yyyy-MM-dd", englishCulture), Open = 214.75m, High = 228.00m, Low = 214.31m, Close = 226.99m, Volume = 11213471 }, + new() { Timestamp = DateTime.ParseExact("2017-01-05", "yyyy-MM-dd", englishCulture), Open = 226.42m, High = 227.48m, Low = 221.95m, Close = 226.75m, Volume = 5911695 }, + new() { Timestamp = DateTime.ParseExact("2017-01-06", "yyyy-MM-dd", englishCulture), Open = 226.93m, High = 230.31m, Low = 225.45m, Close = 229.01m, Volume = 5527893 }, + new() { Timestamp = DateTime.ParseExact("2017-01-06", "yyyy-MM-dd", englishCulture), Open = 228.97m, High = 231.92m, Low = 228.00m, Close = 231.28m, Volume = 3979484 } ]; badHistory.Validate(); diff --git a/tests/indicators/_common/Results/Result.Utilities.Tests.cs b/tests/indicators/_common/Results/Result.Utilities.Tests.cs index 8286e252d..380540c6e 100644 --- a/tests/indicators/_common/Results/Result.Utilities.Tests.cs +++ b/tests/indicators/_common/Results/Result.Utilities.Tests.cs @@ -1,5 +1,3 @@ -using System.Collections.ObjectModel; - namespace Tests.Common; [TestClass] @@ -8,8 +6,8 @@ public class Results : SeriesTestBase [TestMethod] public void Condense() { - List results = quotes - .GetAdx(14) + List results = Quotes + .GetAdx() .ToList(); // make a few more in the middle null and NaN diff --git a/tests/indicators/_common/Use/Use.Series.Tests.cs b/tests/indicators/_common/Use/Use.Series.Tests.cs index 343de5fb7..6c50f084a 100644 --- a/tests/indicators/_common/Use/Use.Series.Tests.cs +++ b/tests/indicators/_common/Use/Use.Series.Tests.cs @@ -7,16 +7,16 @@ public class UseTests : SeriesTestBase public override void Standard() { // compose basic data - List o = quotes.Use(CandlePart.Open).ToList(); - List h = quotes.Use(CandlePart.High).ToList(); - List l = quotes.Use(CandlePart.Low).ToList(); - List c = quotes.Use(CandlePart.Close).ToList(); - List v = quotes.Use(CandlePart.Volume).ToList(); - List hl = quotes.Use(CandlePart.HL2).ToList(); - List hlc = quotes.Use(CandlePart.HLC3).ToList(); - List oc = quotes.Use(CandlePart.OC2).ToList(); - List ohl = quotes.Use(CandlePart.OHL3).ToList(); - List ohlc = quotes.Use(CandlePart.OHLC4).ToList(); + List o = Quotes.Use(CandlePart.Open).ToList(); + List h = Quotes.Use(CandlePart.High).ToList(); + List l = Quotes.Use(CandlePart.Low).ToList(); + List c = Quotes.Use(CandlePart.Close).ToList(); + List v = Quotes.Use(CandlePart.Volume).ToList(); + List hl = Quotes.Use(CandlePart.Hl2).ToList(); + List hlc = Quotes.Use(CandlePart.Hlc3).ToList(); + List oc = Quotes.Use(CandlePart.Oc2).ToList(); + List ohl = Quotes.Use(CandlePart.Ohl3).ToList(); + List ohlc = Quotes.Use(CandlePart.Ohlc4).ToList(); // proper quantities Assert.AreEqual(502, c.Count); @@ -34,7 +34,7 @@ public override void Standard() Reusable rohlc = ohlc[501]; // proper last date - DateTime lastDate = DateTime.ParseExact("12/31/2018", "MM/dd/yyyy", EnglishCulture); + DateTime lastDate = DateTime.ParseExact("12/31/2018", "MM/dd/yyyy", englishCulture); Assert.AreEqual(lastDate, rc.Timestamp); // last values should be correct @@ -54,7 +54,7 @@ public override void Standard() [TestMethod] public void Use() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .ToList(); @@ -64,7 +64,7 @@ public void Use() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetSma(10) .ToList(); diff --git a/tests/indicators/_testdata/Helper.Importer.cs b/tests/indicators/_testdata/Helper.Importer.cs index 0f115bfcc..bc253bbfb 100644 --- a/tests/indicators/_testdata/Helper.Importer.cs +++ b/tests/indicators/_testdata/Helper.Importer.cs @@ -12,7 +12,7 @@ internal static Quote QuoteFromCsv(string csvLine) { if (string.IsNullOrEmpty(csvLine)) { - return new Quote(); + return new(); } string[] csv = csvLine.Split(','); diff --git a/tests/indicators/_testdata/Helper.Random.cs b/tests/indicators/_testdata/Helper.Random.cs index f35e31000..c455bb586 100644 --- a/tests/indicators/_testdata/Helper.Random.cs +++ b/tests/indicators/_testdata/Helper.Random.cs @@ -18,9 +18,9 @@ Geometric Brownian Motion (GMB) is a random simulator of market movement. **/ internal class RandomGbm : List { - private readonly double volatility; - private readonly double drift; - private double seed; + private readonly double _volatility; + private readonly double _drift; + private double _seed; public RandomGbm( int bars = 250, @@ -28,9 +28,9 @@ public RandomGbm( double drift = 0.01, double seed = 1000.0) { - this.seed = seed; - this.volatility = volatility * 0.01; - this.drift = drift * 0.001; + this._seed = seed; + this._volatility = volatility * 0.01; + this._drift = drift * 0.001; for (int i = 0; i < bars; i++) { DateTime date = DateTime.Today.AddMinutes(i - bars); @@ -40,18 +40,18 @@ public RandomGbm( public void Add(DateTime timestamp) { - double open = Price(seed, volatility * volatility, drift); - double close = Price(open, volatility, drift); + double open = Price(_seed, _volatility * _volatility, _drift); + double close = Price(open, _volatility, _drift); double ocMax = Math.Max(open, close); - double high = Price(seed, volatility * 0.5, 0); - high = (high < ocMax) ? (2 * ocMax) - high : high; + double high = Price(_seed, _volatility * 0.5, 0); + high = high < ocMax ? 2 * ocMax - high : high; double ocMin = Math.Min(open, close); - double low = Price(seed, volatility * 0.5, 0); - low = (low > ocMin) ? (2 * ocMin) - low : low; + double low = Price(_seed, _volatility * 0.5, 0); + low = low > ocMin ? 2 * ocMin - low : low; - double volume = Price(seed * 10, volatility * 2, drift: 0); + double volume = Price(_seed * 10, _volatility * 2, drift: 0); Quote quote = new() { Timestamp = timestamp, @@ -63,7 +63,7 @@ public void Add(DateTime timestamp) }; Add(quote); - seed = close; + _seed = close; } private static double Price(double seed, double volatility, double drift) @@ -72,6 +72,6 @@ private static double Price(double seed, double volatility, double drift) double u1 = 1.0 - rnd.NextDouble(); double u2 = 1.0 - rnd.NextDouble(); double z = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2); - return seed * Math.Exp(drift - (volatility * volatility * 0.5) + (volatility * z)); + return seed * Math.Exp(drift - volatility * volatility * 0.5 + volatility * z); } } diff --git a/tests/indicators/a-d/Adl/Adl.Series.Tests.cs b/tests/indicators/a-d/Adl/Adl.Series.Tests.cs index ac43f6027..4c699f240 100644 --- a/tests/indicators/a-d/Adl/Adl.Series.Tests.cs +++ b/tests/indicators/a-d/Adl/Adl.Series.Tests.cs @@ -6,7 +6,7 @@ public class AdlTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetAdl() .ToList(); @@ -28,7 +28,7 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetAdl() .GetSma(10) .ToList(); @@ -43,7 +43,7 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetAdl() .ToList(); @@ -54,7 +54,7 @@ public override void BadData() [TestMethod] public void BigData() { - List r = bigQuotes + List r = BigQuotes .GetAdl() .ToList(); @@ -64,7 +64,7 @@ public void BigData() [TestMethod] public void RandomData() { - List r = randomQuotes + List r = RandomQuotes .GetAdl() .ToList(); @@ -74,13 +74,13 @@ public void RandomData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetAdl() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetAdl() .ToList(); diff --git a/tests/indicators/a-d/Adx/Adx.Tests.cs b/tests/indicators/a-d/Adx/Adx.Tests.cs index e0fde30f9..e59714422 100644 --- a/tests/indicators/a-d/Adx/Adx.Tests.cs +++ b/tests/indicators/a-d/Adx/Adx.Tests.cs @@ -6,8 +6,8 @@ public class AdxTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetAdx(14) + List results = Quotes + .GetAdx() .ToList(); // proper quantities @@ -47,8 +47,8 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes - .GetAdx(14) + List results = Quotes + .GetAdx() .GetSma(10) .ToList(); @@ -59,18 +59,18 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetAdx(20) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Adx is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Adx is double.NaN)); } [TestMethod] public void BigData() { - List r = bigQuotes + List r = BigQuotes .GetAdx(200) .ToList(); @@ -80,13 +80,13 @@ public void BigData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetAdx(5) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetAdx(5) .ToList(); @@ -101,30 +101,30 @@ public void Issue859() .Select(Importer.QuoteFromCsv) .OrderByDescending(x => x.Timestamp); - List r = test859.GetAdx(14).ToList(); + List r = test859.GetAdx().ToList(); - Assert.AreEqual(0, r.Count(x => x.Adx is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Adx is double.NaN)); Assert.AreEqual(595, r.Count); } [TestMethod] public void Zeroes() { - List r = zeroesQuotes.GetAdx(14).ToList(); + List r = ZeroesQuotes.GetAdx().ToList(); - Assert.AreEqual(0, r.Count(x => x.Adx is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Adx is double.NaN)); Assert.AreEqual(200, r.Count); } [TestMethod] public void Removed() { - List r = quotes.GetAdx(14) + List r = Quotes.GetAdx() .RemoveWarmupPeriods() .ToList(); // assertions - Assert.AreEqual(502 - ((2 * 14) + 100), r.Count); + Assert.AreEqual(502 - (2 * 14 + 100), r.Count); AdxResult last = r.LastOrDefault(); Assert.AreEqual(17.7565, last.Pdi.Round(4)); @@ -137,5 +137,5 @@ public void Exceptions() => // bad lookback period Assert.ThrowsException(() => - quotes.GetAdx(1)); + Quotes.GetAdx(1)); } diff --git a/tests/indicators/a-d/Alligator/Alligator.Series.Tests.cs b/tests/indicators/a-d/Alligator/Alligator.Series.Tests.cs index f9c672212..9aed6c57a 100644 --- a/tests/indicators/a-d/Alligator/Alligator.Series.Tests.cs +++ b/tests/indicators/a-d/Alligator/Alligator.Series.Tests.cs @@ -6,7 +6,7 @@ public class AlligatorTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetAlligator() .ToList(); @@ -46,7 +46,7 @@ public override void Standard() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetAlligator() .ToList(); @@ -58,24 +58,24 @@ public void Chainee() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetAlligator(3, 3, 2, 1, 1, 1) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Jaw is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Jaw is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetAlligator() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetAlligator() .ToList(); @@ -85,7 +85,7 @@ public override void NoQuotes() [TestMethod] public void Condense() { - List r = quotes + List r = Quotes .GetAlligator() .Condense() .ToList(); @@ -101,8 +101,8 @@ public void Condense() [TestMethod] public void Removed() { - List r = quotes - .GetAlligator(13, 8) + List r = Quotes + .GetAlligator() .RemoveWarmupPeriods() .ToList(); @@ -118,17 +118,17 @@ public void Removed() public void Equality() { AlligatorResult r1 = new() { - Timestamp = evalDate, + Timestamp = EvalDate, Jaw = 1d }; AlligatorResult r2 = new() { - Timestamp = evalDate, + Timestamp = EvalDate, Jaw = 1d }; AlligatorResult r3 = new() { - Timestamp = evalDate, + Timestamp = EvalDate, Jaw = 2d }; @@ -141,34 +141,34 @@ public void Exceptions() { // bad jaw lookback periods Assert.ThrowsException(() => - quotes.GetAlligator(13, 8, 13, 5, 5, 3)); + Quotes.GetAlligator(13, 8, 13)); // bad teeth lookback periods Assert.ThrowsException(() => - quotes.GetAlligator(13, 8, 8, 5, 8, 3)); + Quotes.GetAlligator(13, 8, 8, 5, 8)); // bad lips lookback periods Assert.ThrowsException(() => - quotes.GetAlligator(13, 8, 8, 5, 0, 3)); + Quotes.GetAlligator(13, 8, 8, 5, 0)); // bad jaw offset periods Assert.ThrowsException(() => - quotes.GetAlligator(13, 0, 8, 5, 5, 3)); + Quotes.GetAlligator(13, 0)); // bad teeth offset periods Assert.ThrowsException(() => - quotes.GetAlligator(13, 8, 8, 0, 5, 3)); + Quotes.GetAlligator(13, 8, 8, 0)); // bad lips offset periods Assert.ThrowsException(() => - quotes.GetAlligator(13, 8, 8, 5, 5, 0)); + Quotes.GetAlligator(13, 8, 8, 5, 5, 0)); // bad jaw + offset periods Assert.ThrowsException(() => - quotes.GetAlligator(13, 8, 12, 11, 5, 3)); + Quotes.GetAlligator(13, 8, 12, 11)); // bad teeth + offset periods Assert.ThrowsException(() => - quotes.GetAlligator(13, 8, 8, 5, 7, 7)); + Quotes.GetAlligator(13, 8, 8, 5, 7, 7)); } } diff --git a/tests/indicators/a-d/Alligator/Alligator.Stream.Tests.cs b/tests/indicators/a-d/Alligator/Alligator.Stream.Tests.cs index 43fdfe283..7de0bc97b 100644 --- a/tests/indicators/a-d/Alligator/Alligator.Stream.Tests.cs +++ b/tests/indicators/a-d/Alligator/Alligator.Stream.Tests.cs @@ -6,7 +6,7 @@ public class AlligatorTests : StreamTestBase, ITestChainObserver [TestMethod] public override void QuoteObserver() { - List quotesList = quotes + List quotesList = Quotes .ToSortedList(); int length = quotesList.Count; @@ -16,7 +16,7 @@ public override void QuoteObserver() // initialize observer Alligator observer = provider - .ToAlligator(13, 8, 8, 5, 5, 3); + .ToAlligator(); // fetch initial results (early) IEnumerable results @@ -54,7 +54,7 @@ List streamList // time-series, for comparison List seriesList = quotesList - .GetAlligator(13, 8, 8, 5, 5, 3) + .GetAlligator() .ToList(); // assert, should equal series @@ -76,7 +76,7 @@ List streamList [TestMethod] public void ChainObserver() { - List quotesList = quotes + List quotesList = Quotes .ToSortedList(); int length = quotesList.Count; @@ -87,7 +87,7 @@ public void ChainObserver() // initialize observer Alligator observer = provider .ToSma(10) - .ToAlligator(13, 8, 8, 5, 5, 3); + .ToAlligator(); // emulate adding quotes out of order // note: this works when graceful order @@ -123,7 +123,7 @@ List streamList // time-series, for comparison List seriesList = quotesList .GetSma(10) - .GetAlligator(13, 8, 8, 5, 5, 3) + .GetAlligator() .ToList(); // assert, should equal series diff --git a/tests/indicators/a-d/Alma/Alma.Tests.cs b/tests/indicators/a-d/Alma/Alma.Tests.cs index 65134544e..9b5f15080 100644 --- a/tests/indicators/a-d/Alma/Alma.Tests.cs +++ b/tests/indicators/a-d/Alma/Alma.Tests.cs @@ -10,7 +10,7 @@ public override void Standard() double offset = 0.85; double sigma = 6; - List results = quotes + List results = Quotes .GetAlma(lookbackPeriods, offset, sigma) .ToList(); @@ -41,9 +41,9 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) - .GetAlma(10, 0.85, 6) + .GetAlma(10) .ToList(); Assert.AreEqual(502, results.Count); @@ -56,9 +56,9 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) - .GetAlma(10, 0.85, 6) + .GetAlma(10) .ToList(); Assert.AreEqual(502, results.Count); @@ -72,7 +72,7 @@ public void Chainor() double offset = 0.85; double sigma = 6; - List results = quotes + List results = Quotes .GetAlma(lookbackPeriods, offset, sigma) .GetSma(10) .ToList(); @@ -84,36 +84,36 @@ public void Chainor() [TestMethod] public void NaN() { - List r1 = TestData.GetBtcUsdNan().GetAlma(9, 0.85, 6).ToList(); + List r1 = TestData.GetBtcUsdNan().GetAlma().ToList(); - Assert.AreEqual(0, r1.Count(x => x.Alma is double and double.NaN)); + Assert.AreEqual(0, r1.Count(x => x.Alma is double.NaN)); - List r2 = TestData.GetBtcUsdNan().GetAlma(20, 0.85, 6).ToList(); + List r2 = TestData.GetBtcUsdNan().GetAlma(20).ToList(); - Assert.AreEqual(0, r2.Count(x => x.Alma is double and double.NaN)); + Assert.AreEqual(0, r2.Count(x => x.Alma is double.NaN)); } [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetAlma(14, 0.5, 3) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Alma is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Alma is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetAlma() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetAlma() .ToList(); @@ -123,8 +123,8 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes - .GetAlma(10, 0.85, 6) + List results = Quotes + .GetAlma(10) .RemoveWarmupPeriods() .ToList(); @@ -140,14 +140,14 @@ public void Exceptions() { // bad lookback period Assert.ThrowsException(() => - quotes.GetAlma(0, 1, 5)); + Quotes.GetAlma(0, 1, 5)); // bad offset Assert.ThrowsException(() => - quotes.GetAlma(15, 1.1, 3)); + Quotes.GetAlma(15, 1.1, 3)); // bad sigma Assert.ThrowsException(() => - quotes.GetAlma(10, 0.5, 0)); + Quotes.GetAlma(10, 0.5, 0)); } } diff --git a/tests/indicators/a-d/Aroon/Aroon.Tests.cs b/tests/indicators/a-d/Aroon/Aroon.Tests.cs index 088f8813e..c9b84d78f 100644 --- a/tests/indicators/a-d/Aroon/Aroon.Tests.cs +++ b/tests/indicators/a-d/Aroon/Aroon.Tests.cs @@ -6,8 +6,8 @@ public class Aroon : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetAroon(25) + List results = Quotes + .GetAroon() .ToList(); // proper quantities @@ -46,8 +46,8 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes - .GetAroon(25) + List results = Quotes + .GetAroon() .GetSma(10) .ToList(); @@ -58,24 +58,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetAroon(20) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Oscillator is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Oscillator is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetAroon() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetAroon() .ToList(); @@ -85,8 +85,8 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes - .GetAroon(25) + List results = Quotes + .GetAroon() .RemoveWarmupPeriods() .ToList(); @@ -103,5 +103,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetAroon(0)); + => Quotes.GetAroon(0)); } diff --git a/tests/indicators/a-d/Atr/Atr.Tests.cs b/tests/indicators/a-d/Atr/Atr.Tests.cs index 3738efaa5..54efdc200 100644 --- a/tests/indicators/a-d/Atr/Atr.Tests.cs +++ b/tests/indicators/a-d/Atr/Atr.Tests.cs @@ -6,8 +6,8 @@ public class AtrTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetAtr(14) + List results = Quotes + .GetAtr() .ToList(); // proper quantities @@ -44,7 +44,7 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetAtr(10) .GetSma(10) .ToList(); @@ -56,24 +56,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetAtr(20) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Atr is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Atr is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetAtr() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetAtr() .ToList(); @@ -83,8 +83,8 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes - .GetAtr(14) + List results = Quotes + .GetAtr() .RemoveWarmupPeriods() .ToList(); @@ -101,5 +101,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() => - quotes.GetAtr(1)); + Quotes.GetAtr(1)); } diff --git a/tests/indicators/a-d/AtrStop/AtrStop.Tests.cs b/tests/indicators/a-d/AtrStop/AtrStop.Tests.cs index 6fd126475..231252ce1 100644 --- a/tests/indicators/a-d/AtrStop/AtrStop.Tests.cs +++ b/tests/indicators/a-d/AtrStop/AtrStop.Tests.cs @@ -9,8 +9,8 @@ public override void Standard() int lookbackPeriods = 21; double multiplier = 3; - List results = quotes - .GetAtrStop(lookbackPeriods, multiplier, EndType.Close) + List results = Quotes + .GetAtrStop(lookbackPeriods, multiplier) .ToList(); // proper quantities @@ -55,7 +55,7 @@ public void HighLow() int lookbackPeriods = 21; double multiplier = 3; - List results = quotes + List results = Quotes .GetAtrStop(lookbackPeriods, multiplier, EndType.HighLow) .ToList(); @@ -98,7 +98,7 @@ public void HighLow() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetAtrStop(7) .ToList(); @@ -108,13 +108,13 @@ public override void BadData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetAtrStop() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetAtrStop() .ToList(); @@ -128,7 +128,7 @@ public void Condense() double multiplier = 3; List results = - quotes.GetAtrStop(lookbackPeriods, multiplier) + Quotes.GetAtrStop(lookbackPeriods, multiplier) .Condense() .ToList(); @@ -148,7 +148,7 @@ public void Removed() double multiplier = 3; List results = - quotes.GetAtrStop(lookbackPeriods, multiplier) + Quotes.GetAtrStop(lookbackPeriods, multiplier) .RemoveWarmupPeriods() .ToList(); @@ -166,10 +166,10 @@ public void Exceptions() { // bad lookback period Assert.ThrowsException(() - => quotes.GetAtrStop(1)); + => Quotes.GetAtrStop(1)); // bad multiplier Assert.ThrowsException(() - => quotes.GetAtrStop(7, 0)); + => Quotes.GetAtrStop(7, 0)); } } diff --git a/tests/indicators/a-d/Awesome/Awesome.Tests.cs b/tests/indicators/a-d/Awesome/Awesome.Tests.cs index 5d8a90743..6c65262c8 100644 --- a/tests/indicators/a-d/Awesome/Awesome.Tests.cs +++ b/tests/indicators/a-d/Awesome/Awesome.Tests.cs @@ -6,8 +6,8 @@ public class AwesomeTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetAwesome(5, 34) + List results = Quotes + .GetAwesome() .ToList(); // proper quantities @@ -35,7 +35,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetAwesome() .ToList(); @@ -47,7 +47,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetAwesome() .ToList(); @@ -59,7 +59,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetAwesome() .GetSma(10) .ToList(); @@ -71,24 +71,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetAwesome() .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Oscillator is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Oscillator is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetAwesome() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetAwesome() .ToList(); @@ -98,8 +98,8 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes - .GetAwesome(5, 34) + List results = Quotes + .GetAwesome() .RemoveWarmupPeriods() .ToList(); @@ -116,10 +116,10 @@ public void Exceptions() { // bad fast period Assert.ThrowsException(() => - quotes.GetAwesome(0, 34)); + Quotes.GetAwesome(0)); // bad slow period Assert.ThrowsException(() => - quotes.GetAwesome(25, 25)); + Quotes.GetAwesome(25, 25)); } } diff --git a/tests/indicators/a-d/Beta/Beta.Tests.cs b/tests/indicators/a-d/Beta/Beta.Tests.cs index 84db4caf7..2d2336791 100644 --- a/tests/indicators/a-d/Beta/Beta.Tests.cs +++ b/tests/indicators/a-d/Beta/Beta.Tests.cs @@ -6,8 +6,8 @@ public class BetaTests : SeriesTestBase [TestMethod] public void All() { - List results = otherQuotes - .GetBeta(quotes, 20, BetaType.All) + List results = OtherQuotes + .GetBeta(Quotes, 20, BetaType.All) .ToList(); // proper quantities @@ -51,8 +51,8 @@ public void All() [TestMethod] public override void Standard() { - List results = Indicator - .GetBeta(otherQuotes, quotes, 20, BetaType.Standard) + List results = OtherQuotes + .GetBeta(Quotes, 20) .ToList(); // proper quantities @@ -67,8 +67,8 @@ public override void Standard() [TestMethod] public void Up() { - List results = otherQuotes - .GetBeta(quotes, 20, BetaType.Up) + List results = OtherQuotes + .GetBeta(Quotes, 20, BetaType.Up) .ToList(); // proper quantities @@ -83,8 +83,8 @@ public void Up() [TestMethod] public void Down() { - List results = otherQuotes - .GetBeta(quotes, 20, BetaType.Down) + List results = OtherQuotes + .GetBeta(Quotes, 20, BetaType.Down) .ToList(); // proper quantities @@ -99,9 +99,9 @@ public void Down() [TestMethod] public void UseReusable() { - List results = otherQuotes + List results = OtherQuotes .Use(CandlePart.Close) - .GetBeta(quotes.Use(CandlePart.Close), 20) + .GetBeta(Quotes.Use(CandlePart.Close), 20) .ToList(); Assert.AreEqual(502, results.Count); @@ -111,8 +111,8 @@ public void UseReusable() [TestMethod] public void Chainor() { - List results = otherQuotes - .GetBeta(quotes, 20) + List results = OtherQuotes + .GetBeta(Quotes, 20) .GetSma(10) .ToList(); @@ -123,46 +123,46 @@ public void Chainor() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) - .GetBeta(otherQuotes.GetSma(2), 20) + .GetBeta(OtherQuotes.GetSma(2), 20) .ToList(); Assert.AreEqual(502, results.Count); Assert.AreEqual(481, results.Count(x => x.Beta != null)); - Assert.AreEqual(0, results.Count(x => x.Beta is double and double.NaN)); + Assert.AreEqual(0, results.Count(x => x.Beta is double.NaN)); } [TestMethod] public override void BadData() { - List r1 = badQuotes - .GetBeta(badQuotes, 15, BetaType.Standard) + List r1 = BadQuotes + .GetBeta(BadQuotes, 15) .ToList(); Assert.AreEqual(502, r1.Count); - Assert.AreEqual(0, r1.Count(x => x.Beta is double and double.NaN)); + Assert.AreEqual(0, r1.Count(x => x.Beta is double.NaN)); - List r2 = badQuotes - .GetBeta(badQuotes, 15, BetaType.Up) + List r2 = BadQuotes + .GetBeta(BadQuotes, 15, BetaType.Up) .ToList(); Assert.AreEqual(502, r2.Count); - Assert.AreEqual(0, r2.Count(x => x.BetaUp is double and double.NaN)); + Assert.AreEqual(0, r2.Count(x => x.BetaUp is double.NaN)); - List r3 = badQuotes - .GetBeta(badQuotes, 15, BetaType.Down) + List r3 = BadQuotes + .GetBeta(BadQuotes, 15, BetaType.Down) .ToList(); Assert.AreEqual(502, r3.Count); - Assert.AreEqual(0, r3.Count(x => x.BetaDown is double and double.NaN)); + Assert.AreEqual(0, r3.Count(x => x.BetaDown is double.NaN)); } [TestMethod] public void BigData() { - List r = bigQuotes - .GetBeta(bigQuotes, 150, BetaType.All) + List r = BigQuotes + .GetBeta(BigQuotes, 150, BetaType.All) .ToList(); Assert.AreEqual(1246, r.Count); @@ -182,11 +182,9 @@ public void BetaMsft() List evalQuotes = TestData.GetMsft().ToList(); List mktQuotes = TestData.GetSpx().ToList(); - List results = Indicator - .GetBeta( - evalQuotes.Aggregate(PeriodSize.Month), - mktQuotes.Aggregate(PeriodSize.Month), - 60, BetaType.Standard) + List results = evalQuotes.Aggregate(PeriodSize.Month) + .GetBeta(mktQuotes.Aggregate(PeriodSize.Month), + 60) .ToList(); Assert.AreEqual(0.91, results[385].Beta.Round(2)); @@ -195,8 +193,8 @@ public void BetaMsft() [TestMethod] public void Removed() { - List results = otherQuotes - .GetBeta(quotes, 20) + List results = OtherQuotes + .GetBeta(Quotes, 20) .RemoveWarmupPeriods() .ToList(); @@ -211,8 +209,8 @@ public void Removed() public void SameSame() { // Beta should be 1 if evaluating against self - List results = quotes - .GetBeta(quotes, 20) + List results = Quotes + .GetBeta(Quotes, 20) .ToList(); // proper quantities @@ -227,13 +225,13 @@ public void SameSame() [TestMethod] public override void NoQuotes() { - List r0 = noquotes - .GetBeta(noquotes, 5) + List r0 = Noquotes + .GetBeta(Noquotes, 5) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote.GetBeta(onequote, 5).ToList(); + List r1 = Onequote.GetBeta(Onequote, 5).ToList(); Assert.AreEqual(1, r1.Count); } @@ -242,28 +240,28 @@ public void NoMatch() { List quoteA = [ - new Quote { Timestamp = DateTime.Parse("1/1/2020", EnglishCulture), Close = 1234 }, - new Quote { Timestamp = DateTime.Parse("1/2/2020", EnglishCulture), Close = 1234 }, - new Quote { Timestamp = DateTime.Parse("1/3/2020", EnglishCulture), Close = 1234 }, - new Quote { Timestamp = DateTime.Parse("1/4/2020", EnglishCulture), Close = 1234 }, - new Quote { Timestamp = DateTime.Parse("1/5/2020", EnglishCulture), Close = 1234 }, - new Quote { Timestamp = DateTime.Parse("1/6/2020", EnglishCulture), Close = 1234 }, - new Quote { Timestamp = DateTime.Parse("1/7/2020", EnglishCulture), Close = 1234 }, - new Quote { Timestamp = DateTime.Parse("1/8/2020", EnglishCulture), Close = 1234 }, - new Quote { Timestamp = DateTime.Parse("1/9/2020", EnglishCulture), Close = 1234 } + new() { Timestamp = DateTime.Parse("1/1/2020", englishCulture), Close = 1234 }, + new() { Timestamp = DateTime.Parse("1/2/2020", englishCulture), Close = 1234 }, + new() { Timestamp = DateTime.Parse("1/3/2020", englishCulture), Close = 1234 }, + new() { Timestamp = DateTime.Parse("1/4/2020", englishCulture), Close = 1234 }, + new() { Timestamp = DateTime.Parse("1/5/2020", englishCulture), Close = 1234 }, + new() { Timestamp = DateTime.Parse("1/6/2020", englishCulture), Close = 1234 }, + new() { Timestamp = DateTime.Parse("1/7/2020", englishCulture), Close = 1234 }, + new() { Timestamp = DateTime.Parse("1/8/2020", englishCulture), Close = 1234 }, + new() { Timestamp = DateTime.Parse("1/9/2020", englishCulture), Close = 1234 } ]; List quoteB = [ - new Quote { Timestamp = DateTime.Parse("1/1/2020", EnglishCulture), Close = 1234 }, - new Quote { Timestamp = DateTime.Parse("1/2/2020", EnglishCulture), Close = 1234 }, - new Quote { Timestamp = DateTime.Parse("1/3/2020", EnglishCulture), Close = 1234 }, - new Quote { Timestamp = DateTime.Parse("2/4/2020", EnglishCulture), Close = 1234 }, // abberrant - new Quote { Timestamp = DateTime.Parse("1/5/2020", EnglishCulture), Close = 1234 }, - new Quote { Timestamp = DateTime.Parse("1/6/2020", EnglishCulture), Close = 1234 }, - new Quote { Timestamp = DateTime.Parse("1/7/2020", EnglishCulture), Close = 1234 }, - new Quote { Timestamp = DateTime.Parse("1/8/2020", EnglishCulture), Close = 1234 }, - new Quote { Timestamp = DateTime.Parse("1/9/2020", EnglishCulture), Close = 1234 } + new() { Timestamp = DateTime.Parse("1/1/2020", englishCulture), Close = 1234 }, + new() { Timestamp = DateTime.Parse("1/2/2020", englishCulture), Close = 1234 }, + new() { Timestamp = DateTime.Parse("1/3/2020", englishCulture), Close = 1234 }, + new() { Timestamp = DateTime.Parse("2/4/2020", englishCulture), Close = 1234 }, // abberrant + new() { Timestamp = DateTime.Parse("1/5/2020", englishCulture), Close = 1234 }, + new() { Timestamp = DateTime.Parse("1/6/2020", englishCulture), Close = 1234 }, + new() { Timestamp = DateTime.Parse("1/7/2020", englishCulture), Close = 1234 }, + new() { Timestamp = DateTime.Parse("1/8/2020", englishCulture), Close = 1234 }, + new() { Timestamp = DateTime.Parse("1/9/2020", englishCulture), Close = 1234 } ]; Assert.ThrowsException(() @@ -275,12 +273,12 @@ public void Exceptions() { // bad lookback period Assert.ThrowsException(() - => quotes.GetBeta(otherQuotes, 0)); + => Quotes.GetBeta(OtherQuotes, 0)); // bad evaluation quotes List eval = TestData.GetCompare(300).ToList(); Assert.ThrowsException(() - => quotes.GetBeta(eval, 30)); + => Quotes.GetBeta(eval, 30)); } } diff --git a/tests/indicators/a-d/BollingerBands/BollingerBands.Tests.cs b/tests/indicators/a-d/BollingerBands/BollingerBands.Tests.cs index b2693e9e2..42c981362 100644 --- a/tests/indicators/a-d/BollingerBands/BollingerBands.Tests.cs +++ b/tests/indicators/a-d/BollingerBands/BollingerBands.Tests.cs @@ -7,7 +7,7 @@ public class BollingerBandsTests : SeriesTestBase public override void Standard() { List results = - quotes.GetBollingerBands(20, 2) + Quotes.GetBollingerBands() .ToList(); // proper quantities @@ -40,7 +40,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetBollingerBands() .ToList(); @@ -52,7 +52,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetBollingerBands() .ToList(); @@ -64,7 +64,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetBollingerBands() .GetSma(10) .ToList(); @@ -76,24 +76,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetBollingerBands(15, 3) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.UpperBand is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.UpperBand is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetBollingerBands() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetBollingerBands() .ToList(); @@ -104,7 +104,7 @@ public override void NoQuotes() public void Removed() { List results = - quotes.GetBollingerBands(20, 2) + Quotes.GetBollingerBands() .RemoveWarmupPeriods() .ToList(); @@ -125,10 +125,10 @@ public void Exceptions() { // bad lookback period Assert.ThrowsException(() => - quotes.GetBollingerBands(1)); + Quotes.GetBollingerBands(1)); // bad standard deviation Assert.ThrowsException(() => - quotes.GetBollingerBands(2, 0)); + Quotes.GetBollingerBands(2, 0)); } } diff --git a/tests/indicators/a-d/Bop/Bop.Tests.cs b/tests/indicators/a-d/Bop/Bop.Tests.cs index bf0c138ac..edb15c39b 100644 --- a/tests/indicators/a-d/Bop/Bop.Tests.cs +++ b/tests/indicators/a-d/Bop/Bop.Tests.cs @@ -6,8 +6,8 @@ public class BopTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetBop(14) + List results = Quotes + .GetBop() .ToList(); // proper quantities @@ -34,8 +34,8 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes - .GetBop(14) + List results = Quotes + .GetBop() .GetSma(10) .ToList(); @@ -49,29 +49,29 @@ public void NaN() IEnumerable r = TestData.GetBtcUsdNan() .GetBop(50); - Assert.AreEqual(0, r.Count(x => x.Bop is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Bop is double.NaN)); } [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetBop() .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Bop is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Bop is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetBop() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetBop() .ToList(); Assert.AreEqual(1, r1.Count); @@ -80,8 +80,8 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes - .GetBop(14) + List results = Quotes + .GetBop() .RemoveWarmupPeriods() .ToList(); @@ -96,5 +96,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetBop(0)); + => Quotes.GetBop(0)); } diff --git a/tests/indicators/a-d/Cci/Cci.Tests.cs b/tests/indicators/a-d/Cci/Cci.Tests.cs index 710c36d77..98e97c0fa 100644 --- a/tests/indicators/a-d/Cci/Cci.Tests.cs +++ b/tests/indicators/a-d/Cci/Cci.Tests.cs @@ -6,8 +6,8 @@ public class CciTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetCci(20) + List results = Quotes + .GetCci() .ToList(); // proper quantities @@ -22,8 +22,8 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes - .GetCci(20) + List results = Quotes + .GetCci() .GetSma(10) .ToList(); @@ -34,24 +34,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetCci(15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Cci is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Cci is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetCci() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetCci() .ToList(); @@ -61,8 +61,8 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes - .GetCci(20) + List results = Quotes + .GetCci() .RemoveWarmupPeriods() .ToList(); @@ -77,5 +77,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetCci(0)); + => Quotes.GetCci(0)); } diff --git a/tests/indicators/a-d/ChaikinOsc/ChaikinOsc.Tests.cs b/tests/indicators/a-d/ChaikinOsc/ChaikinOsc.Tests.cs index 039296b58..3c707d261 100644 --- a/tests/indicators/a-d/ChaikinOsc/ChaikinOsc.Tests.cs +++ b/tests/indicators/a-d/ChaikinOsc/ChaikinOsc.Tests.cs @@ -9,7 +9,7 @@ public override void Standard() int fastPeriods = 3; int slowPeriods = 10; - List results = quotes + List results = Quotes .GetChaikinOsc(fastPeriods, slowPeriods) .ToList(); @@ -28,8 +28,8 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes - .GetChaikinOsc(3, 10) + List results = Quotes + .GetChaikinOsc() .GetSma(10) .ToList(); @@ -40,24 +40,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetChaikinOsc(5, 15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Oscillator is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Oscillator is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetChaikinOsc() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetChaikinOsc() .ToList(); @@ -70,7 +70,7 @@ public void Removed() int fastPeriods = 3; int slowPeriods = 10; - List results = quotes + List results = Quotes .GetChaikinOsc(fastPeriods, slowPeriods) .RemoveWarmupPeriods() .ToList(); @@ -90,10 +90,10 @@ public void Exceptions() { // bad fast lookback Assert.ThrowsException(() => - quotes.GetChaikinOsc(0)); + Quotes.GetChaikinOsc(0)); // bad slow lookback Assert.ThrowsException(() => - quotes.GetChaikinOsc(10, 5)); + Quotes.GetChaikinOsc(10, 5)); } } diff --git a/tests/indicators/a-d/Chandelier/Chandelier.Tests.cs b/tests/indicators/a-d/Chandelier/Chandelier.Tests.cs index 4350d3488..a453d760a 100644 --- a/tests/indicators/a-d/Chandelier/Chandelier.Tests.cs +++ b/tests/indicators/a-d/Chandelier/Chandelier.Tests.cs @@ -9,7 +9,7 @@ public override void Standard() int lookbackPeriods = 22; List longResult = - quotes.GetChandelier(lookbackPeriods, 3) + Quotes.GetChandelier(lookbackPeriods) .ToList(); // proper quantities @@ -25,7 +25,7 @@ public override void Standard() // short List shortResult = - quotes.GetChandelier(lookbackPeriods, 3, ChandelierType.Short) + Quotes.GetChandelier(lookbackPeriods, 3, ChandelierType.Short) .ToList(); ChandelierResult c = shortResult[501]; @@ -35,8 +35,8 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes - .GetChandelier(22) + List results = Quotes + .GetChandelier() .GetSma(10) .ToList(); @@ -47,24 +47,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetChandelier(15, 2) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.ChandelierExit is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.ChandelierExit is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetChandelier() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetChandelier() .ToList(); @@ -74,8 +74,8 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List longResult = quotes - .GetChandelier(22, 3) + List longResult = Quotes + .GetChandelier() .RemoveWarmupPeriods() .ToList(); @@ -91,14 +91,14 @@ public void Exceptions() { // bad lookback period Assert.ThrowsException(() => - quotes.GetChandelier(0)); + Quotes.GetChandelier(0)); // bad multiplier Assert.ThrowsException(() => - quotes.GetChandelier(25, 0)); + Quotes.GetChandelier(25, 0)); // bad type Assert.ThrowsException(() => - quotes.GetChandelier(25, 2, (ChandelierType)int.MaxValue)); + Quotes.GetChandelier(25, 2, (ChandelierType)int.MaxValue)); } } diff --git a/tests/indicators/a-d/Chop/Chop.Tests.cs b/tests/indicators/a-d/Chop/Chop.Tests.cs index 4c53357a5..5e3da9525 100644 --- a/tests/indicators/a-d/Chop/Chop.Tests.cs +++ b/tests/indicators/a-d/Chop/Chop.Tests.cs @@ -6,8 +6,8 @@ public class ChopTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetChop(14) + List results = Quotes + .GetChop() .ToList(); // proper quantities @@ -31,8 +31,8 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes - .GetChop(14) + List results = Quotes + .GetChop() .GetSma(10) .ToList(); @@ -44,7 +44,7 @@ public void Chainor() public void SmallLookback() { int lookbackPeriods = 2; - List results = quotes + List results = Quotes .GetChop(lookbackPeriods) .ToList(); @@ -56,24 +56,24 @@ public void SmallLookback() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetChop(20) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Chop is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Chop is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetChop() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetChop() .ToList(); @@ -83,8 +83,8 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes - .GetChop(14) + List results = Quotes + .GetChop() .RemoveWarmupPeriods() .ToList(); @@ -99,5 +99,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetChop(1)); + => Quotes.GetChop(1)); } diff --git a/tests/indicators/a-d/Cmf/Cmf.Tests.cs b/tests/indicators/a-d/Cmf/Cmf.Tests.cs index f8df6df30..29f0a5ff6 100644 --- a/tests/indicators/a-d/Cmf/Cmf.Tests.cs +++ b/tests/indicators/a-d/Cmf/Cmf.Tests.cs @@ -6,8 +6,8 @@ public class CmfTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetCmf(20) + List results = Quotes + .GetCmf() .ToList(); // proper quantities @@ -34,8 +34,8 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes - .GetCmf(20) + List results = Quotes + .GetCmf() .GetSma(10) .ToList(); @@ -46,18 +46,18 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetCmf(15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Cmf is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Cmf is double.NaN)); } [TestMethod] public void BigData() { - List r = bigQuotes + List r = BigQuotes .GetCmf(150) .ToList(); @@ -67,13 +67,13 @@ public void BigData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetCmf() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetCmf() .ToList(); @@ -83,8 +83,8 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes - .GetCmf(20) + List results = Quotes + .GetCmf() .RemoveWarmupPeriods() .ToList(); @@ -101,5 +101,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetCmf(0)); + => Quotes.GetCmf(0)); } diff --git a/tests/indicators/a-d/Cmo/Cmo.Tests.cs b/tests/indicators/a-d/Cmo/Cmo.Tests.cs index f13f98d8c..9623cdda8 100644 --- a/tests/indicators/a-d/Cmo/Cmo.Tests.cs +++ b/tests/indicators/a-d/Cmo/Cmo.Tests.cs @@ -6,7 +6,7 @@ public class CmoTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetCmo(14) .ToList(); @@ -31,7 +31,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetCmo(14) .ToList(); @@ -43,7 +43,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetCmo(20) .ToList(); @@ -55,7 +55,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetCmo(20) .GetSma(10) .ToList(); @@ -67,24 +67,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetCmo(35) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Cmo is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Cmo is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetCmo(5) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetCmo(5) .ToList(); @@ -94,7 +94,7 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes + List results = Quotes .GetCmo(14) .RemoveWarmupPeriods() .ToList(); @@ -110,5 +110,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetCmo(0)); + => Quotes.GetCmo(0)); } diff --git a/tests/indicators/a-d/ConnorsRsi/ConnorsRsi.Tests.cs b/tests/indicators/a-d/ConnorsRsi/ConnorsRsi.Tests.cs index 3571e4d7b..451bdd381 100644 --- a/tests/indicators/a-d/ConnorsRsi/ConnorsRsi.Tests.cs +++ b/tests/indicators/a-d/ConnorsRsi/ConnorsRsi.Tests.cs @@ -11,7 +11,7 @@ public override void Standard() int rankPeriods = 100; int startPeriod = Math.Max(rsiPeriods, Math.Max(streakPeriods, rankPeriods)) + 2; - List results1 = quotes + List results1 = Quotes .GetConnorsRsi(rsiPeriods, streakPeriods, rankPeriods) .ToList(); @@ -27,7 +27,7 @@ public override void Standard() Assert.AreEqual(74.7662, r1.ConnorsRsi.Round(4)); // different parameters - List results2 = quotes.GetConnorsRsi(14, 20, 10).ToList(); + List results2 = Quotes.GetConnorsRsi(14, 20, 10).ToList(); ConnorsRsiResult r2 = results2[501]; Assert.AreEqual(42.0773, r2.Rsi.Round(4)); Assert.AreEqual(52.7386, r2.RsiStreak.Round(4)); @@ -38,7 +38,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetConnorsRsi() .ToList(); @@ -50,7 +50,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetConnorsRsi() .ToList(); @@ -62,7 +62,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetConnorsRsi() .GetSma(10) .ToList(); @@ -74,24 +74,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetConnorsRsi(4, 3, 25) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Rsi is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Rsi is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetConnorsRsi() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetConnorsRsi() .ToList(); @@ -109,7 +109,7 @@ public void Removed() int removePeriods = Math.Max(rsiPeriods, Math.Max(streakPeriods, rankPeriods)) + 2; List results = - quotes.GetConnorsRsi(rsiPeriods, streakPeriods, rankPeriods) + Quotes.GetConnorsRsi(rsiPeriods, streakPeriods, rankPeriods) .RemoveWarmupPeriods() .ToList(); @@ -128,14 +128,14 @@ public void Exceptions() { // bad RSI period Assert.ThrowsException(() => - quotes.GetConnorsRsi(1, 2, 100)); + Quotes.GetConnorsRsi(1)); // bad Streak period Assert.ThrowsException(() => - quotes.GetConnorsRsi(3, 1, 100)); + Quotes.GetConnorsRsi(3, 1)); // bad Rank period Assert.ThrowsException(() => - quotes.GetConnorsRsi(3, 2, 1)); + Quotes.GetConnorsRsi(3, 2, 1)); } } diff --git a/tests/indicators/a-d/Correlation/Correlation.Tests.cs b/tests/indicators/a-d/Correlation/Correlation.Tests.cs index 9de0d4512..63d0fb7ef 100644 --- a/tests/indicators/a-d/Correlation/Correlation.Tests.cs +++ b/tests/indicators/a-d/Correlation/Correlation.Tests.cs @@ -6,8 +6,8 @@ public class CorrelationTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetCorrelation(otherQuotes, 20) + List results = Quotes + .GetCorrelation(OtherQuotes, 20) .ToList(); // proper quantities @@ -36,9 +36,9 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) - .GetCorrelation(otherQuotes.Use(CandlePart.Close), 20) + .GetCorrelation(OtherQuotes.Use(CandlePart.Close), 20) .ToList(); Assert.AreEqual(502, results.Count); @@ -48,8 +48,8 @@ public void UseReusable() [TestMethod] public void Chainor() { - List results = quotes - .GetCorrelation(otherQuotes, 20) + List results = Quotes + .GetCorrelation(OtherQuotes, 20) .GetSma(10) .ToList(); @@ -60,32 +60,32 @@ public void Chainor() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) - .GetCorrelation(otherQuotes.GetSma(2), 20) + .GetCorrelation(OtherQuotes.GetSma(2), 20) .ToList(); Assert.AreEqual(502, results.Count); Assert.AreEqual(482, results.Count(x => x.Correlation != null)); - Assert.AreEqual(0, results.Count(x => x.Correlation is double and double.NaN)); + Assert.AreEqual(0, results.Count(x => x.Correlation is double.NaN)); } [TestMethod] public override void BadData() { - List r = badQuotes - .GetCorrelation(badQuotes, 15) + List r = BadQuotes + .GetCorrelation(BadQuotes, 15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Correlation is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Correlation is double.NaN)); } [TestMethod] public void BigData() { - List r = bigQuotes - .GetCorrelation(bigQuotes, 150) + List r = BigQuotes + .GetCorrelation(BigQuotes, 150) .ToList(); Assert.AreEqual(1246, r.Count); @@ -94,14 +94,14 @@ public void BigData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes - .GetCorrelation(noquotes, 10) + List r0 = Noquotes + .GetCorrelation(Noquotes, 10) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote - .GetCorrelation(onequote, 10) + List r1 = Onequote + .GetCorrelation(Onequote, 10) .ToList(); Assert.AreEqual(1, r1.Count); @@ -110,8 +110,8 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes - .GetCorrelation(otherQuotes, 20) + List results = Quotes + .GetCorrelation(OtherQuotes, 20) .RemoveWarmupPeriods() .ToList(); @@ -128,15 +128,15 @@ public void Exceptions() { // bad lookback period Assert.ThrowsException(() => - quotes.GetCorrelation(otherQuotes, 0)); + Quotes.GetCorrelation(OtherQuotes, 0)); // bad eval quotes IEnumerable eval = TestData.GetCompare(300); Assert.ThrowsException(() => - quotes.GetCorrelation(eval, 30)); + Quotes.GetCorrelation(eval, 30)); // mismatched quotes Assert.ThrowsException(() => - mismatchQuotes.GetCorrelation(otherQuotes, 20)); + MismatchQuotes.GetCorrelation(OtherQuotes, 20)); } } diff --git a/tests/indicators/a-d/Dema/Dema.Tests.cs b/tests/indicators/a-d/Dema/Dema.Tests.cs index b3ccb1385..38909df0e 100644 --- a/tests/indicators/a-d/Dema/Dema.Tests.cs +++ b/tests/indicators/a-d/Dema/Dema.Tests.cs @@ -6,7 +6,7 @@ public class DemaTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetDema(20) .ToList(); @@ -31,7 +31,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetDema(20) .ToList(); @@ -43,7 +43,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetDema(20) .ToList(); @@ -55,7 +55,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetDema(20) .GetSma(10) .ToList(); @@ -67,24 +67,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetDema(15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Dema is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Dema is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetDema(5) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetDema(5) .ToList(); @@ -94,7 +94,7 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes + List results = Quotes .GetDema(20) .RemoveWarmupPeriods() .ToList(); @@ -110,5 +110,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetDema(0)); + => Quotes.GetDema(0)); } diff --git a/tests/indicators/a-d/Doji/Doji.Tests.cs b/tests/indicators/a-d/Doji/Doji.Tests.cs index 6e3e6c400..3a5747bfd 100644 --- a/tests/indicators/a-d/Doji/Doji.Tests.cs +++ b/tests/indicators/a-d/Doji/Doji.Tests.cs @@ -6,8 +6,8 @@ public class DojiTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetDoji(0.1) + List results = Quotes + .GetDoji() .ToList(); // proper quantities @@ -43,7 +43,7 @@ public override void Standard() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetDoji() .ToList(); @@ -53,13 +53,13 @@ public override void BadData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetDoji() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetDoji() .ToList(); @@ -69,8 +69,8 @@ public override void NoQuotes() [TestMethod] public void Condense() { - List r = quotes - .GetDoji(0.1) + List r = Quotes + .GetDoji() .Condense() .ToList(); @@ -82,9 +82,9 @@ public void Exceptions() { // bad maximum change value Assert.ThrowsException(() => - quotes.GetDoji(-0.00001)); + Quotes.GetDoji(-0.00001)); Assert.ThrowsException(() => - quotes.GetDoji(0.50001)); + Quotes.GetDoji(0.50001)); } } diff --git a/tests/indicators/a-d/Donchian/Donchian.Tests.cs b/tests/indicators/a-d/Donchian/Donchian.Tests.cs index 39fbe4586..5c5eee03b 100644 --- a/tests/indicators/a-d/Donchian/Donchian.Tests.cs +++ b/tests/indicators/a-d/Donchian/Donchian.Tests.cs @@ -6,8 +6,8 @@ public class DonchianTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetDonchian(20) + List results = Quotes + .GetDonchian() .ToList(); // proper quantities @@ -52,7 +52,7 @@ public override void Standard() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetDonchian(15) .ToList(); @@ -62,13 +62,13 @@ public override void BadData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetDonchian() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetDonchian() .ToList(); @@ -78,8 +78,8 @@ public override void NoQuotes() [TestMethod] public void Condense() { - List r = quotes - .GetDonchian(20) + List r = Quotes + .GetDonchian() .Condense() .ToList(); @@ -96,8 +96,8 @@ public void Condense() [TestMethod] public void Removed() { - List results = quotes - .GetDonchian(20) + List results = Quotes + .GetDonchian() .RemoveWarmupPeriods() .ToList(); @@ -115,5 +115,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetDonchian(0)); + => Quotes.GetDonchian(0)); } diff --git a/tests/indicators/a-d/Dpo/Dpo.Tests.cs b/tests/indicators/a-d/Dpo/Dpo.Tests.cs index d7aec6008..1b367cbb4 100644 --- a/tests/indicators/a-d/Dpo/Dpo.Tests.cs +++ b/tests/indicators/a-d/Dpo/Dpo.Tests.cs @@ -17,14 +17,14 @@ public override void Standard() for (int i = 0; i < csvData.Count; i++) { string[] csv = csvData[i].Split(","); - DateTime date = Convert.ToDateTime(csv[1], EnglishCulture); + DateTime date = Convert.ToDateTime(csv[1], englishCulture); - qot.Add(new Quote { + qot.Add(new() { Timestamp = date, Close = csv[5].ToDecimal() }); - exp.Add(new DpoResult() { + exp.Add(new() { Timestamp = date, Sma = csv[6].ToDoubleNull(), Dpo = csv[7].ToDoubleNull() @@ -53,7 +53,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetDpo(14) .ToList(); @@ -65,7 +65,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetDpo(14) .ToList(); @@ -77,7 +77,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetDpo(14) .GetSma(10) .ToList(); @@ -89,24 +89,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetDpo(5) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Dpo is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Dpo is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetDpo(5) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetDpo(5) .ToList(); @@ -117,5 +117,5 @@ public override void NoQuotes() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetDpo(0)); + => Quotes.GetDpo(0)); } diff --git a/tests/indicators/a-d/Dynamic/Dynamic.Tests.cs b/tests/indicators/a-d/Dynamic/Dynamic.Tests.cs index 62eba1652..04ce4f68a 100644 --- a/tests/indicators/a-d/Dynamic/Dynamic.Tests.cs +++ b/tests/indicators/a-d/Dynamic/Dynamic.Tests.cs @@ -6,7 +6,7 @@ public class McGinleyDynamicTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetDynamic(14) .ToList(); @@ -31,20 +31,20 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetDynamic(20) .ToList(); Assert.AreEqual(502, results.Count); Assert.AreEqual(501, results.Count(x => x.Dynamic != null)); - Assert.AreEqual(0, results.Count(x => x.Dynamic is double and double.NaN)); + Assert.AreEqual(0, results.Count(x => x.Dynamic is double.NaN)); } [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(10) .GetDynamic(14) .ToList(); @@ -56,7 +56,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetDynamic(14) .GetSma(10) .ToList(); @@ -68,24 +68,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetDynamic(15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Dynamic is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Dynamic is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetDynamic(14) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetDynamic(14) .ToList(); @@ -97,10 +97,10 @@ public void Exceptions() { // bad lookback period Assert.ThrowsException(() - => quotes.GetDynamic(0)); + => Quotes.GetDynamic(0)); // bad k-factor Assert.ThrowsException(() - => quotes.GetDynamic(14, 0)); + => Quotes.GetDynamic(14, 0)); } } diff --git a/tests/indicators/e-k/ElderRay/ElderRay.Tests.cs b/tests/indicators/e-k/ElderRay/ElderRay.Tests.cs index a2d6381e0..6868125c2 100644 --- a/tests/indicators/e-k/ElderRay/ElderRay.Tests.cs +++ b/tests/indicators/e-k/ElderRay/ElderRay.Tests.cs @@ -6,8 +6,8 @@ public class ElderRayTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetElderRay(13) + List results = Quotes + .GetElderRay() .ToList(); // proper quantities @@ -50,8 +50,8 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes - .GetElderRay(13) + List results = Quotes + .GetElderRay() .GetSma(10) .ToList(); @@ -62,24 +62,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetElderRay() .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.BullPower is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.BullPower is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetElderRay() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetElderRay() .ToList(); @@ -89,8 +89,8 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes - .GetElderRay(13) + List results = Quotes + .GetElderRay() .RemoveWarmupPeriods() .ToList(); @@ -107,5 +107,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetElderRay(0)); + => Quotes.GetElderRay(0)); } diff --git a/tests/indicators/e-k/Ema/Ema.Series.Tests.cs b/tests/indicators/e-k/Ema/Ema.Series.Tests.cs index 05ed674d7..a16e86072 100644 --- a/tests/indicators/e-k/Ema/Ema.Series.Tests.cs +++ b/tests/indicators/e-k/Ema/Ema.Series.Tests.cs @@ -14,7 +14,7 @@ public void Increment() [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetEma(20) .ToList(); @@ -36,7 +36,7 @@ public override void Standard() [TestMethod] public void UsePart() { - List results = quotes + List results = Quotes .Use(CandlePart.Open) .GetEma(20) .ToList(); @@ -50,66 +50,66 @@ public void UsePart() // sample values EmaResult r29 = results[29]; - Assert.AreEqual(216.2643, NullMath.Round(r29.Ema, 4)); + Assert.AreEqual(216.2643, r29.Ema.Round(4)); EmaResult r249 = results[249]; - Assert.AreEqual(255.4875, NullMath.Round(r249.Ema, 4)); + Assert.AreEqual(255.4875, r249.Ema.Round(4)); EmaResult r501 = results[501]; - Assert.AreEqual(249.9157, NullMath.Round(r501.Ema, 4)); + Assert.AreEqual(249.9157, r501.Ema.Round(4)); } [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetEma(20) .ToList(); Assert.AreEqual(502, results.Count); Assert.AreEqual(483, results.Count(x => x.Ema != null)); - Assert.AreEqual(0, results.Count(x => x.Ema is double and double.NaN)); + Assert.AreEqual(0, results.Count(x => x.Ema is double.NaN)); } [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetEma(20) .ToList(); Assert.AreEqual(502, results.Count); Assert.AreEqual(482, results.Count(x => x.Ema != null)); - Assert.AreEqual(0, results.Count(x => x.Ema is double and double.NaN)); + Assert.AreEqual(0, results.Count(x => x.Ema is double.NaN)); } [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetEma(20) .GetSma(10) .ToList(); Assert.AreEqual(502, results.Count); Assert.AreEqual(474, results.Count(x => x.Sma != null)); - Assert.AreEqual(0, results.Count(x => x.Sma is double and double.NaN)); + Assert.AreEqual(0, results.Count(x => x.Sma is double.NaN)); } [TestMethod] public void ChaineeMore() { - List results = quotes - .GetRsi(14) + List results = Quotes + .GetRsi() .GetEma(20) .ToList(); // assertions Assert.AreEqual(502, results.Count); Assert.AreEqual(469, results.Count(x => x.Ema != null)); - Assert.AreEqual(0, results.Count(x => x.Ema is double and double.NaN)); + Assert.AreEqual(0, results.Count(x => x.Ema is double.NaN)); // sample values EmaResult r32 = results[32]; @@ -128,24 +128,24 @@ public void ChaineeMore() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetEma(15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Ema is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Ema is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetEma(10) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetEma(10) .ToList(); @@ -155,7 +155,7 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes + List results = Quotes .GetEma(20) .RemoveWarmupPeriods() .ToList(); @@ -171,5 +171,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetEma(0)); + => Quotes.GetEma(0)); } diff --git a/tests/indicators/e-k/Ema/Ema.Stream.Tests.cs b/tests/indicators/e-k/Ema/Ema.Stream.Tests.cs index f70178119..c813a9e5b 100644 --- a/tests/indicators/e-k/Ema/Ema.Stream.Tests.cs +++ b/tests/indicators/e-k/Ema/Ema.Stream.Tests.cs @@ -6,7 +6,7 @@ public class EmaTests : StreamTestBase, ITestChainObserver, ITestChainProvider [TestMethod] public override void QuoteObserver() { - List quotesList = quotes + List quotesList = Quotes .ToSortedList(); int length = quotesList.Count; @@ -77,7 +77,7 @@ public void ChainObserver() int emaPeriods = 12; int smaPeriods = 8; - List quotesList = quotes + List quotesList = Quotes .ToSortedList(); int length = quotesList.Count; @@ -101,7 +101,7 @@ List streamEma = [.. observer.Results]; // time-series, for comparison - List staticEma = quotes + List staticEma = Quotes .GetSma(smaPeriods) .GetEma(emaPeriods) .ToList(); @@ -128,7 +128,7 @@ public void ChainProvider() int emaPeriods = 20; int smaPeriods = 10; - List quotesList = quotes + List quotesList = Quotes .ToSortedList(); int length = quotesList.Count; diff --git a/tests/indicators/e-k/Epma/Epma.Tests.cs b/tests/indicators/e-k/Epma/Epma.Tests.cs index 2b5974b30..d3d5e7cec 100644 --- a/tests/indicators/e-k/Epma/Epma.Tests.cs +++ b/tests/indicators/e-k/Epma/Epma.Tests.cs @@ -6,7 +6,7 @@ public class EpmaTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetEpma(20) .ToList(); @@ -34,7 +34,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetEpma(20) .ToList(); @@ -46,7 +46,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetEpma(20) .ToList(); @@ -58,7 +58,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetEpma(20) .GetSma(10) .ToList(); @@ -70,24 +70,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetEpma(15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Epma is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Epma is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetEpma(5) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetEpma(5) .ToList(); @@ -97,7 +97,7 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes + List results = Quotes .GetEpma(20) .RemoveWarmupPeriods() .ToList(); @@ -113,5 +113,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetEpma(0)); + => Quotes.GetEpma(0)); } diff --git a/tests/indicators/e-k/Fcb/Fcb.Tests.cs b/tests/indicators/e-k/Fcb/Fcb.Tests.cs index 043d3456a..89c5b41e9 100644 --- a/tests/indicators/e-k/Fcb/Fcb.Tests.cs +++ b/tests/indicators/e-k/Fcb/Fcb.Tests.cs @@ -6,8 +6,8 @@ public class FcbTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetFcb(2) + List results = Quotes + .GetFcb() .ToList(); // proper quantities @@ -44,7 +44,7 @@ public override void Standard() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetFcb() .ToList(); @@ -54,13 +54,13 @@ public override void BadData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetFcb() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetFcb() .ToList(); @@ -70,8 +70,8 @@ public override void NoQuotes() [TestMethod] public void Condense() { - List results = quotes - .GetFcb(2) + List results = Quotes + .GetFcb() .Condense() .ToList(); @@ -86,8 +86,8 @@ public void Condense() [TestMethod] public void Removed() { - List results = quotes - .GetFcb(2) + List results = Quotes + .GetFcb() .RemoveWarmupPeriods() .ToList(); @@ -103,5 +103,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetFcb(1)); + => Quotes.GetFcb(1)); } diff --git a/tests/indicators/e-k/FisherTransform/FisherTransform.Tests.cs b/tests/indicators/e-k/FisherTransform/FisherTransform.Tests.cs index c3abe86a7..73ff1cdb0 100644 --- a/tests/indicators/e-k/FisherTransform/FisherTransform.Tests.cs +++ b/tests/indicators/e-k/FisherTransform/FisherTransform.Tests.cs @@ -6,8 +6,8 @@ public class FisherTransformTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetFisherTransform(10) + List results = Quotes + .GetFisherTransform() .ToList(); // proper quantities @@ -49,9 +49,9 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) - .GetFisherTransform(10) + .GetFisherTransform() .ToList(); Assert.AreEqual(502, results.Count); @@ -61,9 +61,9 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) - .GetFisherTransform(10) + .GetFisherTransform() .ToList(); Assert.AreEqual(502, results.Count); @@ -73,8 +73,8 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes - .GetFisherTransform(10) + List results = Quotes + .GetFisherTransform() .GetSma(10) .ToList(); @@ -85,24 +85,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetFisherTransform(9) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Fisher is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Fisher is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetFisherTransform() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetFisherTransform() .ToList(); @@ -113,5 +113,5 @@ public override void NoQuotes() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetFisherTransform(0)); + => Quotes.GetFisherTransform(0)); } diff --git a/tests/indicators/e-k/ForceIndex/ForceIndex.Tests.cs b/tests/indicators/e-k/ForceIndex/ForceIndex.Tests.cs index 3bf4c1c33..50f32fb5b 100644 --- a/tests/indicators/e-k/ForceIndex/ForceIndex.Tests.cs +++ b/tests/indicators/e-k/ForceIndex/ForceIndex.Tests.cs @@ -6,7 +6,7 @@ public class ForceIndexTests : SeriesTestBase [TestMethod] public override void Standard() { - List r = quotes.GetForceIndex(13).ToList(); + List r = Quotes.GetForceIndex(13).ToList(); // proper quantities Assert.AreEqual(502, r.Count); @@ -25,7 +25,7 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetForceIndex(13) .GetSma(10) .ToList(); @@ -37,24 +37,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes - .GetForceIndex(2) + List r = BadQuotes + .GetForceIndex() .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.ForceIndex is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.ForceIndex is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetForceIndex(5) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetForceIndex(5) .ToList(); @@ -64,7 +64,7 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes + List results = Quotes .GetForceIndex(13) .RemoveWarmupPeriods() .ToList(); @@ -80,5 +80,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetForceIndex(0)); + => Quotes.GetForceIndex(0)); } diff --git a/tests/indicators/e-k/Fractal/Fractal.Tests.cs b/tests/indicators/e-k/Fractal/Fractal.Tests.cs index 81231a8bd..8d5b923df 100644 --- a/tests/indicators/e-k/Fractal/Fractal.Tests.cs +++ b/tests/indicators/e-k/Fractal/Fractal.Tests.cs @@ -6,8 +6,8 @@ public class FractalTests : SeriesTestBase [TestMethod] public void StandardSpan2() { - List results = quotes - .GetFractal(2, EndType.HighLow) + List results = Quotes + .GetFractal() .ToList(); // proper quantities @@ -44,8 +44,8 @@ public void StandardSpan2() [TestMethod] public void StandardSpan4() { - List results = quotes - .GetFractal(4, 4, EndType.HighLow) + List results = Quotes + .GetFractal(4, 4) .ToList(); // proper quantities @@ -82,7 +82,7 @@ public void StandardSpan4() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetFractal() .ToList(); @@ -92,13 +92,13 @@ public override void BadData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetFractal() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetFractal() .ToList(); @@ -108,7 +108,7 @@ public override void NoQuotes() [TestMethod] public void Condense() { - List r = quotes + List r = Quotes .GetFractal() .Condense() .ToList(); @@ -120,5 +120,5 @@ public void Condense() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetFractal(1)); + => Quotes.GetFractal(1)); } diff --git a/tests/indicators/e-k/Gator/Gator.Tests.cs b/tests/indicators/e-k/Gator/Gator.Tests.cs index cb308e0a6..6a353d162 100644 --- a/tests/indicators/e-k/Gator/Gator.Tests.cs +++ b/tests/indicators/e-k/Gator/Gator.Tests.cs @@ -6,7 +6,7 @@ public class GatorTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetGator() .ToList(); @@ -76,7 +76,7 @@ public override void Standard() [TestMethod] public void FromAlligator() { - List results = quotes + List results = Quotes .GetAlligator() .GetGator() .ToList(); @@ -147,7 +147,7 @@ public void FromAlligator() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetGator() .ToList(); @@ -159,7 +159,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetGator() .ToList(); @@ -171,24 +171,24 @@ public void Chainee() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetGator() .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Upper is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Upper is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetGator() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetGator() .ToList(); @@ -198,7 +198,7 @@ public override void NoQuotes() [TestMethod] public void Condense() { - List results = quotes + List results = Quotes .GetGator() .Condense() .ToList(); @@ -216,7 +216,7 @@ public void Condense() [TestMethod] public void Removed() { - List results = quotes + List results = Quotes .GetGator() .RemoveWarmupPeriods() .ToList(); diff --git a/tests/indicators/e-k/HeikinAshi/HeikinAshi.Tests.cs b/tests/indicators/e-k/HeikinAshi/HeikinAshi.Tests.cs index 708c7f53c..5b1236b42 100644 --- a/tests/indicators/e-k/HeikinAshi/HeikinAshi.Tests.cs +++ b/tests/indicators/e-k/HeikinAshi/HeikinAshi.Tests.cs @@ -6,7 +6,7 @@ public class HeikinAshiTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetHeikinAshi() .ToList(); @@ -25,7 +25,7 @@ public override void Standard() [TestMethod] public void UseAsQuotes() { - IEnumerable haQuotes = quotes.GetHeikinAshi(); + IEnumerable haQuotes = Quotes.GetHeikinAshi(); IEnumerable haSma = haQuotes.GetSma(5); Assert.AreEqual(498, haSma.Count(x => x.Sma != null)); } @@ -33,7 +33,7 @@ public void UseAsQuotes() [TestMethod] public void ToQuotes() { - List results = quotes + List results = Quotes .GetHeikinAshi() .ToList(); @@ -58,7 +58,7 @@ public void ToQuotes() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetHeikinAshi() .ToList(); @@ -68,13 +68,13 @@ public override void BadData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetHeikinAshi() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetHeikinAshi() .ToList(); diff --git a/tests/indicators/e-k/Hma/Hma.Tests.cs b/tests/indicators/e-k/Hma/Hma.Tests.cs index 80bd47a42..3d9f93f77 100644 --- a/tests/indicators/e-k/Hma/Hma.Tests.cs +++ b/tests/indicators/e-k/Hma/Hma.Tests.cs @@ -6,7 +6,7 @@ public class HmaTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetHma(20) .ToList(); @@ -25,7 +25,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetHma(20) .ToList(); @@ -37,7 +37,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetHma(19) .ToList(); @@ -49,7 +49,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetHma(20) .GetSma(10) .ToList(); @@ -61,24 +61,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetHma(15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Hma is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Hma is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetHma(5) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetHma(5) .ToList(); @@ -88,7 +88,7 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes + List results = Quotes .GetHma(20) .RemoveWarmupPeriods() .ToList(); @@ -104,5 +104,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetHma(1)); + => Quotes.GetHma(1)); } diff --git a/tests/indicators/e-k/HtTrendline/HtTrendline.Tests.cs b/tests/indicators/e-k/HtTrendline/HtTrendline.Tests.cs index 85e90f701..01637e985 100644 --- a/tests/indicators/e-k/HtTrendline/HtTrendline.Tests.cs +++ b/tests/indicators/e-k/HtTrendline/HtTrendline.Tests.cs @@ -6,7 +6,7 @@ public class HtTrendlineTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetHtTrendline() .ToList(); @@ -60,7 +60,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetHtTrendline() .ToList(); @@ -72,7 +72,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetHtTrendline() .ToList(); @@ -84,7 +84,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetHtTrendline() .GetSma(10) .ToList(); @@ -96,18 +96,18 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetHtTrendline() .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Trendline is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Trendline is double.NaN)); } [TestMethod] public void Removed() { - List results = quotes + List results = Quotes .GetHtTrendline() .RemoveWarmupPeriods() .ToList(); @@ -135,13 +135,13 @@ public void PennyData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetHtTrendline() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetHtTrendline() .ToList(); diff --git a/tests/indicators/e-k/Hurst/Hurst.Tests.cs b/tests/indicators/e-k/Hurst/Hurst.Tests.cs index f05367b5b..c372b23cf 100644 --- a/tests/indicators/e-k/Hurst/Hurst.Tests.cs +++ b/tests/indicators/e-k/Hurst/Hurst.Tests.cs @@ -6,8 +6,8 @@ public class HurstTests : SeriesTestBase [TestMethod] public void StandardLong() { - List results = longestQuotes - .GetHurst(longestQuotes.Count() - 1) + List results = LongestQuotes + .GetHurst(LongestQuotes.Count() - 1) .ToList(); // assertions @@ -24,9 +24,9 @@ public void StandardLong() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) - .GetHurst(100) + .GetHurst() .ToList(); Assert.AreEqual(502, results.Count); @@ -36,8 +36,8 @@ public void UseReusable() [TestMethod] public void Chainor() { - List results = quotes - .GetHurst(100) + List results = Quotes + .GetHurst() .GetSma(10) .ToList(); @@ -48,9 +48,9 @@ public void Chainor() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(10) - .GetHurst(100) + .GetHurst() .ToList(); Assert.AreEqual(502, results.Count); @@ -60,24 +60,24 @@ public void Chainee() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetHurst(150) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.HurstExponent is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.HurstExponent is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetHurst() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetHurst() .ToList(); @@ -87,7 +87,7 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = longestQuotes.GetHurst(longestQuotes.Count() - 1) + List results = LongestQuotes.GetHurst(LongestQuotes.Count() - 1) .RemoveWarmupPeriods() .ToList(); @@ -102,5 +102,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetHurst(19)); + => Quotes.GetHurst(19)); } diff --git a/tests/indicators/e-k/Ichimoku/Ichimoku.Tests.cs b/tests/indicators/e-k/Ichimoku/Ichimoku.Tests.cs index 03e3ec405..0435dfb1a 100644 --- a/tests/indicators/e-k/Ichimoku/Ichimoku.Tests.cs +++ b/tests/indicators/e-k/Ichimoku/Ichimoku.Tests.cs @@ -10,7 +10,7 @@ public override void Standard() int kijunPeriods = 26; int senkouBPeriods = 52; - List results = quotes + List results = Quotes .GetIchimoku(tenkanPeriods, kijunPeriods, senkouBPeriods) .ToList(); @@ -55,7 +55,7 @@ public override void Standard() [TestMethod] public void Extended() { - List r = quotes + List r = Quotes .GetIchimoku(3, 13, 40, 0, 0) .ToList(); @@ -65,7 +65,7 @@ public void Extended() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetIchimoku() .ToList(); @@ -75,13 +75,13 @@ public override void BadData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetIchimoku() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetIchimoku() .ToList(); @@ -91,7 +91,7 @@ public override void NoQuotes() [TestMethod] public void Condense() { - List r = quotes + List r = Quotes .GetIchimoku() .Condense() .ToList(); @@ -104,24 +104,24 @@ public void Exceptions() { // bad signal period Assert.ThrowsException(() => - quotes.GetIchimoku(0)); + Quotes.GetIchimoku(0)); // bad short span period Assert.ThrowsException(() => - quotes.GetIchimoku(9, 0, 52)); + Quotes.GetIchimoku(9, 0)); // bad long span period Assert.ThrowsException(() => - quotes.GetIchimoku(9, 26, 26)); + Quotes.GetIchimoku(9, 26, 26)); // invalid offsets Assert.ThrowsException(() => - quotes.GetIchimoku(9, 26, 52, -1)); + Quotes.GetIchimoku(9, 26, 52, -1)); Assert.ThrowsException(() => - quotes.GetIchimoku(9, 26, 52, -1, 12)); + Quotes.GetIchimoku(9, 26, 52, -1, 12)); Assert.ThrowsException(() => - quotes.GetIchimoku(9, 26, 52, 12, -1)); + Quotes.GetIchimoku(9, 26, 52, 12, -1)); } } diff --git a/tests/indicators/e-k/Kama/Kama.Tests.cs b/tests/indicators/e-k/Kama/Kama.Tests.cs index 2c93c52c6..af17f320f 100644 --- a/tests/indicators/e-k/Kama/Kama.Tests.cs +++ b/tests/indicators/e-k/Kama/Kama.Tests.cs @@ -10,49 +10,49 @@ public override void Standard() int fastPeriods = 2; int slowPeriods = 30; - List results = quotes + List results = Quotes .GetKama(erPeriods, fastPeriods, slowPeriods) .ToList(); // proper quantities Assert.AreEqual(502, results.Count); - Assert.AreEqual(492, results.Count(x => x.ER != null)); + Assert.AreEqual(492, results.Count(x => x.Er != null)); Assert.AreEqual(493, results.Count(x => x.Kama != null)); // sample values KamaResult r1 = results[8]; - Assert.AreEqual(null, r1.ER); + Assert.AreEqual(null, r1.Er); Assert.AreEqual(null, r1.Kama); KamaResult r2 = results[9]; - Assert.AreEqual(null, r2.ER); + Assert.AreEqual(null, r2.Er); Assert.AreEqual(213.7500, r2.Kama.Round(4)); KamaResult r3 = results[10]; - Assert.AreEqual(0.2465, r3.ER.Round(4)); + Assert.AreEqual(0.2465, r3.Er.Round(4)); Assert.AreEqual(213.7713, r3.Kama.Round(4)); KamaResult r4 = results[24]; - Assert.AreEqual(0.2136, r4.ER.Round(4)); + Assert.AreEqual(0.2136, r4.Er.Round(4)); Assert.AreEqual(214.7423, r4.Kama.Round(4)); KamaResult r5 = results[149]; - Assert.AreEqual(0.3165, r5.ER.Round(4)); + Assert.AreEqual(0.3165, r5.Er.Round(4)); Assert.AreEqual(235.5510, r5.Kama.Round(4)); KamaResult r6 = results[249]; - Assert.AreEqual(0.3182, r6.ER.Round(4)); + Assert.AreEqual(0.3182, r6.Er.Round(4)); Assert.AreEqual(256.0898, r6.Kama.Round(4)); KamaResult r7 = results[501]; - Assert.AreEqual(0.2214, r7.ER.Round(4)); + Assert.AreEqual(0.2214, r7.Er.Round(4)); Assert.AreEqual(240.1138, r7.Kama.Round(4)); } [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetKama() .ToList(); @@ -64,7 +64,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetKama() .ToList(); @@ -76,7 +76,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetKama() .GetSma(10) .ToList(); @@ -88,24 +88,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetKama() .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Kama is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Kama is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetKama() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetKama() .ToList(); @@ -119,7 +119,7 @@ public void Removed() int fastPeriods = 2; int slowPeriods = 30; - List results = quotes + List results = Quotes .GetKama(erPeriods, fastPeriods, slowPeriods) .RemoveWarmupPeriods() .ToList(); @@ -128,7 +128,7 @@ public void Removed() Assert.AreEqual(502 - Math.Max(erPeriods + 100, erPeriods * 10), results.Count); KamaResult last = results.LastOrDefault(); - Assert.AreEqual(0.2214, last.ER.Round(4)); + Assert.AreEqual(0.2214, last.Er.Round(4)); Assert.AreEqual(240.1138, last.Kama.Round(4)); } @@ -137,14 +137,14 @@ public void Exceptions() { // bad ER period Assert.ThrowsException(() => - quotes.GetKama(0, 2, 30)); + Quotes.GetKama(0)); // bad fast period Assert.ThrowsException(() => - quotes.GetKama(10, 0, 30)); + Quotes.GetKama(10, 0)); // bad slow period Assert.ThrowsException(() => - quotes.GetKama(10, 5, 5)); + Quotes.GetKama(10, 5, 5)); } } diff --git a/tests/indicators/e-k/Keltner/Keltner.Tests.cs b/tests/indicators/e-k/Keltner/Keltner.Tests.cs index 0b11d7d6e..4ef9aa98e 100644 --- a/tests/indicators/e-k/Keltner/Keltner.Tests.cs +++ b/tests/indicators/e-k/Keltner/Keltner.Tests.cs @@ -10,7 +10,7 @@ public override void Standard() int multiplier = 2; int atrPeriods = 10; - List results = quotes + List results = Quotes .GetKeltner(emaPeriods, multiplier, atrPeriods) .ToList(); @@ -40,24 +40,24 @@ public override void Standard() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetKeltner(10, 3, 15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.UpperBand is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.UpperBand is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetKeltner() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetKeltner() .ToList(); @@ -71,7 +71,7 @@ public void Condense() int multiplier = 2; int atrPeriods = 10; - List results = quotes + List results = Quotes .GetKeltner(emaPeriods, multiplier, atrPeriods) .Condense() .ToList(); @@ -94,7 +94,7 @@ public void Removed() int atrPeriods = 10; int n = Math.Max(emaPeriods, atrPeriods); - List results = quotes + List results = Quotes .GetKeltner(emaPeriods, multiplier, atrPeriods) .RemoveWarmupPeriods() .ToList(); @@ -114,14 +114,14 @@ public void Exceptions() { // bad EMA period Assert.ThrowsException(() => - quotes.GetKeltner(1, 2, 10)); + Quotes.GetKeltner(1)); // bad ATR period Assert.ThrowsException(() => - quotes.GetKeltner(20, 2, 1)); + Quotes.GetKeltner(20, 2, 1)); // bad multiplier Assert.ThrowsException(() => - quotes.GetKeltner(20, 0, 10)); + Quotes.GetKeltner(20, 0)); } } diff --git a/tests/indicators/e-k/Kvo/Kvo.Tests.cs b/tests/indicators/e-k/Kvo/Kvo.Tests.cs index 9e1e8691a..79b847967 100644 --- a/tests/indicators/e-k/Kvo/Kvo.Tests.cs +++ b/tests/indicators/e-k/Kvo/Kvo.Tests.cs @@ -7,7 +7,7 @@ public class KlingerTests : SeriesTestBase public override void Standard() { List results = - quotes.GetKvo(34, 55, 13) + Quotes.GetKvo() .ToList(); // proper quantities @@ -48,7 +48,7 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetKvo() .GetSma(10) .ToList(); @@ -60,24 +60,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetKvo() .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Oscillator is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Oscillator is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetKvo() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetKvo() .ToList(); @@ -87,8 +87,8 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes - .GetKvo(34, 55, 13) + List results = Quotes + .GetKvo() .RemoveWarmupPeriods() .ToList(); @@ -105,14 +105,14 @@ public void Exceptions() { // bad fast period Assert.ThrowsException(() => - quotes.GetKvo(2)); + Quotes.GetKvo(2)); // bad slow period Assert.ThrowsException(() => - quotes.GetKvo(20, 20)); + Quotes.GetKvo(20, 20)); // bad signal period Assert.ThrowsException(() => - quotes.GetKvo(34, 55, 0)); + Quotes.GetKvo(34, 55, 0)); } } diff --git a/tests/indicators/m-r/MaEnvelopes/MaEnvelopes.Tests.cs b/tests/indicators/m-r/MaEnvelopes/MaEnvelopes.Tests.cs index 998459c1b..84f989368 100644 --- a/tests/indicators/m-r/MaEnvelopes/MaEnvelopes.Tests.cs +++ b/tests/indicators/m-r/MaEnvelopes/MaEnvelopes.Tests.cs @@ -7,7 +7,7 @@ public class MaEnvelopesTests : SeriesTestBase public void Alma() { List results = - quotes.GetMaEnvelopes(10, 2.5, MaType.ALMA) + Quotes.GetMaEnvelopes(10, 2.5, MaType.Alma) .ToList(); // proper quantities @@ -35,7 +35,7 @@ public void Alma() public void Dema() { List results = - quotes.GetMaEnvelopes(20, 2.5, MaType.DEMA) + Quotes.GetMaEnvelopes(20, 2.5, MaType.Dema) .ToList(); // proper quantities @@ -63,7 +63,7 @@ public void Dema() public void Epma() { List results = - quotes.GetMaEnvelopes(20, 2.5, MaType.EPMA) + Quotes.GetMaEnvelopes(20, 2.5, MaType.Epma) .ToList(); // proper quantities @@ -91,7 +91,7 @@ public void Epma() public void Ema() { List results = - quotes.GetMaEnvelopes(20, 2.5, MaType.EMA) + Quotes.GetMaEnvelopes(20, 2.5, MaType.Ema) .ToList(); // proper quantities @@ -119,7 +119,7 @@ public void Ema() public void Hma() { List results = - quotes.GetMaEnvelopes(20, 2.5, MaType.HMA) + Quotes.GetMaEnvelopes(20, 2.5, MaType.Hma) .ToList(); // proper quantities @@ -142,7 +142,7 @@ public void Hma() public void Sma() { List results = - quotes.GetMaEnvelopes(20, 2.5, MaType.SMA) + Quotes.GetMaEnvelopes(20) .ToList(); // proper quantities @@ -170,7 +170,7 @@ public void Sma() public void Smma() { List results = - quotes.GetMaEnvelopes(20, 2.5, MaType.SMMA) + Quotes.GetMaEnvelopes(20, 2.5, MaType.Smma) .ToList(); // proper quantities @@ -198,7 +198,7 @@ public void Smma() public void Tema() { List results = - quotes.GetMaEnvelopes(20, 2.5, MaType.TEMA) + Quotes.GetMaEnvelopes(20, 2.5, MaType.Tema) .ToList(); // proper quantities @@ -226,7 +226,7 @@ public void Tema() public void Wma() { List results = - quotes.GetMaEnvelopes(20, 2.5, MaType.WMA) + Quotes.GetMaEnvelopes(20, 2.5, MaType.Wma) .ToList(); // proper quantities @@ -248,9 +248,9 @@ public void Wma() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) - .GetMaEnvelopes(10, 2.5, MaType.SMA) + .GetMaEnvelopes(10) .ToList(); Assert.AreEqual(502, results.Count); @@ -260,9 +260,9 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) - .GetMaEnvelopes(10, 2.5, MaType.SMA) + .GetMaEnvelopes(10) .ToList(); Assert.AreEqual(502, results.Count); @@ -272,50 +272,50 @@ public void Chainee() [TestMethod] public override void BadData() { - List a = badQuotes - .GetMaEnvelopes(5, 2.5, MaType.ALMA) + List a = BadQuotes + .GetMaEnvelopes(5, 2.5, MaType.Alma) .ToList(); Assert.AreEqual(502, a.Count); - List d = badQuotes - .GetMaEnvelopes(5, 2.5, MaType.DEMA) + List d = BadQuotes + .GetMaEnvelopes(5, 2.5, MaType.Dema) .ToList(); Assert.AreEqual(502, d.Count); - List p = badQuotes - .GetMaEnvelopes(5, 2.5, MaType.EPMA) + List p = BadQuotes + .GetMaEnvelopes(5, 2.5, MaType.Epma) .ToList(); Assert.AreEqual(502, p.Count); - List e = badQuotes - .GetMaEnvelopes(5, 2.5, MaType.EMA) + List e = BadQuotes + .GetMaEnvelopes(5, 2.5, MaType.Ema) .ToList(); Assert.AreEqual(502, e.Count); - List h = badQuotes - .GetMaEnvelopes(5, 2.5, MaType.HMA) + List h = BadQuotes + .GetMaEnvelopes(5, 2.5, MaType.Hma) .ToList(); Assert.AreEqual(502, h.Count); - List s = badQuotes - .GetMaEnvelopes(5, 2.5, MaType.SMA) + List s = BadQuotes + .GetMaEnvelopes(5) .ToList(); Assert.AreEqual(502, s.Count); - List t = badQuotes - .GetMaEnvelopes(5, 2.5, MaType.TEMA) + List t = BadQuotes + .GetMaEnvelopes(5, 2.5, MaType.Tema) .ToList(); Assert.AreEqual(502, t.Count); - List w = badQuotes - .GetMaEnvelopes(5, 2.5, MaType.WMA) + List w = BadQuotes + .GetMaEnvelopes(5, 2.5, MaType.Wma) .ToList(); Assert.AreEqual(502, w.Count); @@ -324,8 +324,8 @@ public override void BadData() [TestMethod] public void Condense() { - List r = quotes - .GetMaEnvelopes(20, 2.5, MaType.SMA) + List r = Quotes + .GetMaEnvelopes(20) .Condense() .ToList(); @@ -337,11 +337,11 @@ public void Exceptions() { // bad offset period Assert.ThrowsException(() => - quotes.GetMaEnvelopes(14, 0)); + Quotes.GetMaEnvelopes(14, 0)); // bad MA period Assert.ThrowsException(() => - quotes.GetMaEnvelopes(14, 5, MaType.KAMA)); + Quotes.GetMaEnvelopes(14, 5, MaType.Kama)); // note: insufficient quotes is tested elsewhere } diff --git a/tests/indicators/m-r/Macd/Macd.Tests.cs b/tests/indicators/m-r/Macd/Macd.Tests.cs index 4c9caff3b..66abbc38b 100644 --- a/tests/indicators/m-r/Macd/Macd.Tests.cs +++ b/tests/indicators/m-r/Macd/Macd.Tests.cs @@ -11,7 +11,7 @@ public override void Standard() int signalPeriods = 9; List results = - quotes.GetMacd(fastPeriods, slowPeriods, signalPeriods) + Quotes.GetMacd(fastPeriods, slowPeriods, signalPeriods) .ToList(); // proper quantities @@ -46,7 +46,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetMacd() .ToList(); @@ -58,7 +58,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetMacd() .ToList(); @@ -70,7 +70,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetMacd() .GetSma(10) .ToList(); @@ -82,24 +82,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetMacd(10, 20, 5) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Macd is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Macd is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetMacd() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetMacd() .ToList(); @@ -113,7 +113,7 @@ public void Removed() int slowPeriods = 26; int signalPeriods = 9; - List results = quotes + List results = Quotes .GetMacd(fastPeriods, slowPeriods, signalPeriods) .RemoveWarmupPeriods() .ToList(); @@ -132,14 +132,14 @@ public void Exceptions() { // bad fast period Assert.ThrowsException(() => - quotes.GetMacd(0, 26, 9)); + Quotes.GetMacd(0)); // bad slow periods must be larger than faster period Assert.ThrowsException(() => - quotes.GetMacd(12, 12, 9)); + Quotes.GetMacd(12, 12)); // bad signal period Assert.ThrowsException(() => - quotes.GetMacd(12, 26, -1)); + Quotes.GetMacd(12, 26, -1)); } } diff --git a/tests/indicators/m-r/Mama/Mama.Tests.cs b/tests/indicators/m-r/Mama/Mama.Tests.cs index f2a7023d5..ece73cdb9 100644 --- a/tests/indicators/m-r/Mama/Mama.Tests.cs +++ b/tests/indicators/m-r/Mama/Mama.Tests.cs @@ -9,7 +9,7 @@ public override void Standard() double fastLimit = 0.5; double slowLimit = 0.05; - List results = quotes + List results = Quotes .GetMama(fastLimit, slowLimit) .ToList(); @@ -50,7 +50,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetMama() .ToList(); @@ -62,7 +62,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetMama() .ToList(); @@ -74,7 +74,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetMama() .GetSma(10) .ToList(); @@ -86,24 +86,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetMama() .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Mama is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Mama is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetMama() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetMama() .ToList(); @@ -116,7 +116,7 @@ public void Removed() double fastLimit = 0.5; double slowLimit = 0.05; - List results = quotes + List results = Quotes .GetMama(fastLimit, slowLimit) .RemoveWarmupPeriods() .ToList(); @@ -134,14 +134,14 @@ public void Exceptions() { // bad fast period (same as slow period) Assert.ThrowsException(() => - quotes.GetMama(0.5, 0.5)); + Quotes.GetMama(0.5, 0.5)); // bad fast period (cannot be 1 or more) Assert.ThrowsException(() => - quotes.GetMama(1, 0.5)); + Quotes.GetMama(1, 0.5)); // bad slow period Assert.ThrowsException(() => - quotes.GetMama(0.5, 0)); + Quotes.GetMama(0.5, 0)); } } diff --git a/tests/indicators/m-r/Marubozu/Marubozu.Tests.cs b/tests/indicators/m-r/Marubozu/Marubozu.Tests.cs index 6027d5735..6d4ef3c9a 100644 --- a/tests/indicators/m-r/Marubozu/Marubozu.Tests.cs +++ b/tests/indicators/m-r/Marubozu/Marubozu.Tests.cs @@ -6,8 +6,8 @@ public class MarubozuTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetMarubozu(95) + List results = Quotes + .GetMarubozu() .ToList(); // proper quantities @@ -43,7 +43,7 @@ public override void Standard() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetMarubozu() .ToList(); @@ -53,13 +53,13 @@ public override void BadData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetMarubozu() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetMarubozu() .ToList(); @@ -69,8 +69,8 @@ public override void NoQuotes() [TestMethod] public void Condense() { - List r = quotes - .GetMarubozu(95) + List r = Quotes + .GetMarubozu() .Condense() .ToList(); @@ -82,9 +82,9 @@ public void Exceptions() { // bad minimum body percent values Assert.ThrowsException(() => - quotes.GetMarubozu(79.9)); + Quotes.GetMarubozu(79.9)); Assert.ThrowsException(() => - quotes.GetMarubozu(100.1)); + Quotes.GetMarubozu(100.1)); } } diff --git a/tests/indicators/m-r/Mfi/Mfi.Tests.cs b/tests/indicators/m-r/Mfi/Mfi.Tests.cs index 28f17e8ee..49571bc11 100644 --- a/tests/indicators/m-r/Mfi/Mfi.Tests.cs +++ b/tests/indicators/m-r/Mfi/Mfi.Tests.cs @@ -6,8 +6,8 @@ public class MfiTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetMfi(14) + List results = Quotes + .GetMfi() .ToList(); // proper quantities @@ -25,7 +25,7 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetMfi() .GetSma(10) .ToList(); @@ -39,7 +39,7 @@ public void SmallLookback() { int lookbackPeriods = 4; - List results = quotes + List results = Quotes .GetMfi(lookbackPeriods) .ToList(); @@ -58,24 +58,24 @@ public void SmallLookback() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetMfi(15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Mfi is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Mfi is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetMfi() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetMfi() .ToList(); @@ -87,7 +87,7 @@ public void Removed() { int lookbackPeriods = 14; - List results = quotes + List results = Quotes .GetMfi(lookbackPeriods) .RemoveWarmupPeriods() .ToList(); @@ -103,5 +103,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetMfi(1)); + => Quotes.GetMfi(1)); } diff --git a/tests/indicators/m-r/Obv/Obv.Tests.cs b/tests/indicators/m-r/Obv/Obv.Tests.cs index a3af7ccdd..11582a5c6 100644 --- a/tests/indicators/m-r/Obv/Obv.Tests.cs +++ b/tests/indicators/m-r/Obv/Obv.Tests.cs @@ -6,7 +6,7 @@ public class ObvTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetObv() .ToList(); @@ -24,7 +24,7 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetObv() .GetSma(10) .ToList(); @@ -36,7 +36,7 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetObv() .ToList(); @@ -47,7 +47,7 @@ public override void BadData() [TestMethod] public void BigData() { - List r = bigQuotes + List r = BigQuotes .GetObv() .ToList(); @@ -57,13 +57,13 @@ public void BigData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetObv() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetObv() .ToList(); diff --git a/tests/indicators/m-r/ParabolicSar/ParabolicSar.Tests.cs b/tests/indicators/m-r/ParabolicSar/ParabolicSar.Tests.cs index e297dd0a0..09bc9e664 100644 --- a/tests/indicators/m-r/ParabolicSar/ParabolicSar.Tests.cs +++ b/tests/indicators/m-r/ParabolicSar/ParabolicSar.Tests.cs @@ -10,7 +10,7 @@ public override void Standard() double maxAccelerationFactor = 0.2; List results = - quotes.GetParabolicSar(acclerationStep, maxAccelerationFactor) + Quotes.GetParabolicSar(acclerationStep, maxAccelerationFactor) .ToList(); // proper quantities @@ -43,7 +43,7 @@ public void Extended() double initialStep = 0.01; List results = - quotes.GetParabolicSar( + Quotes.GetParabolicSar( acclerationStep, maxAccelerationFactor, initialStep) .ToList(); @@ -76,7 +76,7 @@ public void Extended() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetParabolicSar() .GetSma(10) .ToList(); @@ -109,24 +109,24 @@ public void InsufficientQuotes() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetParabolicSar(0.2, 0.2, 0.2) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Sar is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Sar is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetParabolicSar() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetParabolicSar() .ToList(); @@ -139,7 +139,7 @@ public void Removed() double acclerationStep = 0.02; double maxAccelerationFactor = 0.2; - List results = quotes + List results = Quotes .GetParabolicSar(acclerationStep, maxAccelerationFactor) .RemoveWarmupPeriods() .ToList(); @@ -157,18 +157,18 @@ public void Exceptions() { // bad acceleration step Assert.ThrowsException(() => - quotes.GetParabolicSar(0, 1)); + Quotes.GetParabolicSar(0, 1)); // insufficient acceleration step Assert.ThrowsException(() => - quotes.GetParabolicSar(0.02, 0)); + Quotes.GetParabolicSar(0.02, 0)); // step larger than factor Assert.ThrowsException(() => - quotes.GetParabolicSar(6, 2)); + Quotes.GetParabolicSar(6, 2)); // insufficient initial factor Assert.ThrowsException(() => - quotes.GetParabolicSar(0.02, 0.5, 0)); + Quotes.GetParabolicSar(0.02, 0.5, 0)); } } diff --git a/tests/indicators/m-r/PivotPoints/PivotPoints.Tests.cs b/tests/indicators/m-r/PivotPoints/PivotPoints.Tests.cs index e365632c5..3bf7b2e96 100644 --- a/tests/indicators/m-r/PivotPoints/PivotPoints.Tests.cs +++ b/tests/indicators/m-r/PivotPoints/PivotPoints.Tests.cs @@ -9,17 +9,17 @@ public override void Standard() PeriodSize periodSize = PeriodSize.Month; PivotPointType pointType = PivotPointType.Standard; - List results = quotes + List results = Quotes .GetPivotPoints(periodSize, pointType) .ToList(); // proper quantities Assert.AreEqual(502, results.Count); - Assert.AreEqual(482, results.Count(x => x.PP != null)); + Assert.AreEqual(482, results.Count(x => x.Pp != null)); // sample values PivotPointsResult r1 = results[19]; - Assert.AreEqual(null, r1.PP); + Assert.AreEqual(null, r1.Pp); Assert.AreEqual(null, r1.S1); Assert.AreEqual(null, r1.S2); Assert.AreEqual(null, r1.S3); @@ -30,7 +30,7 @@ public override void Standard() Assert.AreEqual(null, r1.R4); PivotPointsResult r2 = results[20]; - Assert.AreEqual(214.5000m, r2.PP.Round(4)); + Assert.AreEqual(214.5000m, r2.Pp.Round(4)); Assert.AreEqual(211.9800m, r2.S1.Round(4)); Assert.AreEqual(209.0000m, r2.S2.Round(4)); Assert.AreEqual(206.4800m, r2.S3.Round(4)); @@ -41,7 +41,7 @@ public override void Standard() Assert.AreEqual(null, r2.R4); PivotPointsResult r3 = results[149]; - Assert.AreEqual(233.6400m, r3.PP.Round(4)); + Assert.AreEqual(233.6400m, r3.Pp.Round(4)); Assert.AreEqual(230.8100m, r3.S1.Round(4)); Assert.AreEqual(226.3300m, r3.S2.Round(4)); Assert.AreEqual(223.5000m, r3.S3.Round(4)); @@ -52,7 +52,7 @@ public override void Standard() Assert.AreEqual(null, r3.R4); PivotPointsResult r4 = results[250]; - Assert.AreEqual(251.2767m, r4.PP.Round(4)); + Assert.AreEqual(251.2767m, r4.Pp.Round(4)); Assert.AreEqual(247.6133m, r4.S1.Round(4)); Assert.AreEqual(241.2867m, r4.S2.Round(4)); Assert.AreEqual(237.6233m, r4.S3.Round(4)); @@ -63,7 +63,7 @@ public override void Standard() Assert.AreEqual(null, r4.R4); PivotPointsResult r5 = results[251]; - Assert.AreEqual(255.1967m, r5.PP.Round(4)); + Assert.AreEqual(255.1967m, r5.Pp.Round(4)); Assert.AreEqual(251.6933m, r5.S1.Round(4)); Assert.AreEqual(246.3667m, r5.S2.Round(4)); Assert.AreEqual(242.8633m, r5.S3.Round(4)); @@ -74,7 +74,7 @@ public override void Standard() Assert.AreEqual(null, r5.R4); PivotPointsResult r6 = results[501]; - Assert.AreEqual(266.6767m, r6.PP.Round(4)); + Assert.AreEqual(266.6767m, r6.Pp.Round(4)); Assert.AreEqual(258.9633m, r6.S1.Round(4)); Assert.AreEqual(248.9667m, r6.S2.Round(4)); Assert.AreEqual(241.2533m, r6.S3.Round(4)); @@ -97,13 +97,13 @@ public void Camarilla() // proper quantities Assert.AreEqual(38, results.Count); - Assert.AreEqual(33, results.Count(x => x.PP != null)); + Assert.AreEqual(33, results.Count(x => x.Pp != null)); // sample values PivotPointsResult r2 = results[4]; Assert.AreEqual(null, r2.R4); Assert.AreEqual(null, r2.R3); - Assert.AreEqual(null, r2.PP); + Assert.AreEqual(null, r2.Pp); Assert.AreEqual(null, r2.S1); Assert.AreEqual(null, r2.S2); Assert.AreEqual(null, r2.R1); @@ -112,7 +112,7 @@ public void Camarilla() Assert.AreEqual(null, r2.S4); PivotPointsResult r3 = results[5]; - Assert.AreEqual(271.0200m, r3.PP.Round(4)); + Assert.AreEqual(271.0200m, r3.Pp.Round(4)); Assert.AreEqual(270.13725m, r3.S1.Round(5)); Assert.AreEqual(269.2545m, r3.S2.Round(4)); Assert.AreEqual(268.3718m, r3.S3.Round(4)); @@ -123,7 +123,7 @@ public void Camarilla() Assert.AreEqual(276.3165m, r3.R4.Round(4)); PivotPointsResult r4 = results[22]; - Assert.AreEqual(268.9600m, r4.PP.Round(4)); + Assert.AreEqual(268.9600m, r4.Pp.Round(4)); Assert.AreEqual(267.9819m, r4.S1.Round(4)); Assert.AreEqual(267.0038m, r4.S2.Round(4)); Assert.AreEqual(266.0258m, r4.S3.Round(4)); @@ -134,7 +134,7 @@ public void Camarilla() Assert.AreEqual(274.8285m, r4.R4.Round(4)); PivotPointsResult r5 = results[23]; - Assert.AreEqual(257.1700m, r5.PP.Round(4)); + Assert.AreEqual(257.1700m, r5.Pp.Round(4)); Assert.AreEqual(255.5640m, r5.S1.Round(4)); Assert.AreEqual(253.9580m, r5.S2.Round(4)); Assert.AreEqual(252.3520m, r5.S3.Round(4)); @@ -145,7 +145,7 @@ public void Camarilla() Assert.AreEqual(266.8060m, r5.R4.Round(4)); PivotPointsResult r6 = results[37]; - Assert.AreEqual(243.1500m, r6.PP.Round(4)); + Assert.AreEqual(243.1500m, r6.Pp.Round(4)); Assert.AreEqual(241.56325m, r6.S1.Round(5)); Assert.AreEqual(239.9765m, r6.S2.Round(4)); Assert.AreEqual(238.3898m, r6.S3.Round(4)); @@ -162,19 +162,19 @@ public void Demark() PeriodSize periodSize = PeriodSize.Month; PivotPointType pointType = PivotPointType.Demark; - List results = quotes + List results = Quotes .GetPivotPoints(periodSize, pointType) .ToList(); // proper quantities Assert.AreEqual(502, results.Count); - Assert.AreEqual(482, results.Count(x => x.PP != null)); + Assert.AreEqual(482, results.Count(x => x.Pp != null)); // sample values PivotPointsResult r1 = results[19]; Assert.AreEqual(null, r1.R4); Assert.AreEqual(null, r1.R3); - Assert.AreEqual(null, r1.PP); + Assert.AreEqual(null, r1.Pp); Assert.AreEqual(null, r1.S1); Assert.AreEqual(null, r1.S2); Assert.AreEqual(null, r1.R1); @@ -185,7 +185,7 @@ public void Demark() PivotPointsResult r2 = results[20]; Assert.AreEqual(null, r2.R4); Assert.AreEqual(null, r2.R3); - Assert.AreEqual(215.1300m, r2.PP.Round(4)); + Assert.AreEqual(215.1300m, r2.Pp.Round(4)); Assert.AreEqual(213.2400m, r2.S1.Round(4)); Assert.AreEqual(null, r2.S2); Assert.AreEqual(218.7400m, r2.R1.Round(4)); @@ -196,7 +196,7 @@ public void Demark() PivotPointsResult r3 = results[149]; Assert.AreEqual(null, r3.R4); Assert.AreEqual(null, r3.R3); - Assert.AreEqual(234.3475m, r3.PP.Round(4)); + Assert.AreEqual(234.3475m, r3.Pp.Round(4)); Assert.AreEqual(232.2250m, r3.S1.Round(4)); Assert.AreEqual(null, r3.S2); Assert.AreEqual(239.5350m, r3.R1.Round(4)); @@ -207,7 +207,7 @@ public void Demark() PivotPointsResult r4 = results[250]; Assert.AreEqual(null, r4.R4); Assert.AreEqual(null, r4.R3); - Assert.AreEqual(252.1925m, r4.PP.Round(4)); + Assert.AreEqual(252.1925m, r4.Pp.Round(4)); Assert.AreEqual(249.4450m, r4.S1.Round(4)); Assert.AreEqual(null, r4.S2); Assert.AreEqual(259.4350m, r4.R1.Round(4)); @@ -218,7 +218,7 @@ public void Demark() PivotPointsResult r5 = results[251]; Assert.AreEqual(null, r5.R4); Assert.AreEqual(null, r5.R3); - Assert.AreEqual(256.0725m, r5.PP.Round(4)); + Assert.AreEqual(256.0725m, r5.Pp.Round(4)); Assert.AreEqual(253.4450m, r5.S1.Round(4)); Assert.AreEqual(null, r5.S2); Assert.AreEqual(262.2750m, r5.R1.Round(4)); @@ -229,7 +229,7 @@ public void Demark() PivotPointsResult r6 = results[501]; Assert.AreEqual(null, r6.R4); Assert.AreEqual(null, r6.R3); - Assert.AreEqual(268.6050m, r6.PP.Round(4)); + Assert.AreEqual(268.6050m, r6.Pp.Round(4)); Assert.AreEqual(262.8200m, r6.S1.Round(4)); Assert.AreEqual(null, r6.S2); Assert.AreEqual(280.5300m, r6.R1.Round(4)); @@ -239,7 +239,7 @@ public void Demark() // special Demark case: test close = open WindowPoint d1 = Indicator.GetPivotPointDemark(125, 200, 100, 125); - Assert.AreEqual(550m / 4, d1.PP); + Assert.AreEqual(550m / 4, d1.Pp); } [TestMethod] @@ -254,13 +254,13 @@ public void Fibonacci() // proper quantities Assert.AreEqual(300, results.Count); - Assert.AreEqual(241, results.Count(x => x.PP != null)); + Assert.AreEqual(241, results.Count(x => x.Pp != null)); // sample values PivotPointsResult r1 = results[58]; Assert.AreEqual(null, r1.R4); Assert.AreEqual(null, r1.R3); - Assert.AreEqual(null, r1.PP); + Assert.AreEqual(null, r1.Pp); Assert.AreEqual(null, r1.S1); Assert.AreEqual(null, r1.S2); Assert.AreEqual(null, r1.R1); @@ -269,7 +269,7 @@ public void Fibonacci() Assert.AreEqual(null, r1.S4); PivotPointsResult r2 = results[59]; - Assert.AreEqual(368.4967m, r2.PP.Round(4)); + Assert.AreEqual(368.4967m, r2.Pp.Round(4)); Assert.AreEqual(367.9237m, r2.S1.Round(4)); Assert.AreEqual(367.5697m, r2.S2.Round(4)); Assert.AreEqual(366.9967m, r2.S3.Round(4)); @@ -278,7 +278,7 @@ public void Fibonacci() Assert.AreEqual(369.9967m, r2.R3.Round(4)); PivotPointsResult r3 = results[118]; - Assert.AreEqual(368.4967m, r3.PP.Round(4)); + Assert.AreEqual(368.4967m, r3.Pp.Round(4)); Assert.AreEqual(367.9237m, r3.S1.Round(4)); Assert.AreEqual(367.5697m, r3.S2.Round(4)); Assert.AreEqual(366.9967m, r3.S3.Round(4)); @@ -287,7 +287,7 @@ public void Fibonacci() Assert.AreEqual(369.9967m, r3.R3.Round(4)); PivotPointsResult r4 = results[119]; - Assert.AreEqual(369.0000m, r4.PP.Round(4)); + Assert.AreEqual(369.0000m, r4.Pp.Round(4)); Assert.AreEqual(368.5760m, r4.S1.Round(4)); Assert.AreEqual(368.3140m, r4.S2.Round(4)); Assert.AreEqual(367.8900m, r4.S3.Round(4)); @@ -296,7 +296,7 @@ public void Fibonacci() Assert.AreEqual(370.1100m, r4.R3.Round(4)); PivotPointsResult r5 = results[149]; - Assert.AreEqual(369.0000m, r5.PP.Round(4)); + Assert.AreEqual(369.0000m, r5.Pp.Round(4)); Assert.AreEqual(368.5760m, r5.S1.Round(4)); Assert.AreEqual(368.3140m, r5.S2.Round(4)); Assert.AreEqual(367.8900m, r5.S3.Round(4)); @@ -305,7 +305,7 @@ public void Fibonacci() Assert.AreEqual(370.1100m, r5.R3.Round(4)); PivotPointsResult r6 = results[299]; - Assert.AreEqual(368.8200m, r6.PP.Round(4)); + Assert.AreEqual(368.8200m, r6.Pp.Round(4)); Assert.AreEqual(367.5632m, r6.S1.Round(4)); Assert.AreEqual(366.7868m, r6.S2.Round(4)); Assert.AreEqual(365.5300m, r6.S3.Round(4)); @@ -326,13 +326,13 @@ public void Woodie() // proper quantities Assert.AreEqual(1564, results.Count); - Assert.AreEqual(1173, results.Count(x => x.PP != null)); + Assert.AreEqual(1173, results.Count(x => x.Pp != null)); // sample values PivotPointsResult r2 = results[390]; Assert.AreEqual(null, r2.R4); Assert.AreEqual(null, r2.R3); - Assert.AreEqual(null, r2.PP); + Assert.AreEqual(null, r2.Pp); Assert.AreEqual(null, r2.S1); Assert.AreEqual(null, r2.S2); Assert.AreEqual(null, r2.R1); @@ -341,7 +341,7 @@ public void Woodie() Assert.AreEqual(null, r2.S4); PivotPointsResult r3 = results[391]; - Assert.AreEqual(368.7875m, r3.PP.Round(4)); + Assert.AreEqual(368.7875m, r3.Pp.Round(4)); Assert.AreEqual(367.9850m, r3.S1.Round(4)); Assert.AreEqual(365.1175m, r3.S2.Round(4)); Assert.AreEqual(364.3150m, r3.S3.Round(4)); @@ -350,7 +350,7 @@ public void Woodie() Assert.AreEqual(375.3250m, r3.R3.Round(4)); PivotPointsResult r4 = results[1172]; - Assert.AreEqual(370.9769m, r4.PP.Round(4)); + Assert.AreEqual(370.9769m, r4.Pp.Round(4)); Assert.AreEqual(370.7938m, r4.S1.Round(4)); Assert.AreEqual(368.6845m, r4.S2.Round(4)); Assert.AreEqual(368.5014m, r4.S3.Round(4)); @@ -359,7 +359,7 @@ public void Woodie() Assert.AreEqual(375.3786m, r4.R3.Round(4)); PivotPointsResult r5 = results[1173]; - Assert.AreEqual(371.3625m, r5.PP.Round(4)); + Assert.AreEqual(371.3625m, r5.Pp.Round(4)); Assert.AreEqual(370.2650m, r5.S1.Round(4)); Assert.AreEqual(369.9525m, r5.S2.Round(4)); Assert.AreEqual(368.8550m, r5.S3.Round(4)); @@ -368,7 +368,7 @@ public void Woodie() Assert.AreEqual(373.0850m, r5.R3.Round(4)); PivotPointsResult r6 = results[1563]; - Assert.AreEqual(371.3625m, r6.PP.Round(4)); + Assert.AreEqual(371.3625m, r6.Pp.Round(4)); Assert.AreEqual(370.2650m, r6.S1.Round(4)); Assert.AreEqual(369.9525m, r6.S2.Round(4)); Assert.AreEqual(368.8550m, r6.S3.Round(4)); @@ -380,7 +380,7 @@ public void Woodie() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetPivotPoints(PeriodSize.Week) .ToList(); @@ -390,13 +390,13 @@ public override void BadData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetPivotPoints(PeriodSize.Week) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetPivotPoints(PeriodSize.Week) .ToList(); @@ -409,7 +409,7 @@ public void Removed() PeriodSize periodSize = PeriodSize.Month; PivotPointType pointType = PivotPointType.Standard; - List results = quotes + List results = Quotes .GetPivotPoints(periodSize, pointType) .RemoveWarmupPeriods() .ToList(); @@ -418,7 +418,7 @@ public void Removed() Assert.AreEqual(482, results.Count); PivotPointsResult last = results.LastOrDefault(); - Assert.AreEqual(266.6767m, last.PP.Round(4)); + Assert.AreEqual(266.6767m, last.Pp.Round(4)); Assert.AreEqual(258.9633m, last.S1.Round(4)); Assert.AreEqual(248.9667m, last.S2.Round(4)); Assert.AreEqual(241.2533m, last.S3.Round(4)); @@ -434,12 +434,12 @@ public void Exceptions() { // bad pointtype size Assert.ThrowsException(() - => quotes + => Quotes .GetPivotPoints(PeriodSize.Week, (PivotPointType)999)); // bad window size Assert.ThrowsException(() - => quotes + => Quotes .GetPivotPoints(PeriodSize.ThreeMinutes)); } } diff --git a/tests/indicators/m-r/Pivots/Pivots.Tests.cs b/tests/indicators/m-r/Pivots/Pivots.Tests.cs index 711c405bd..e2f035434 100644 --- a/tests/indicators/m-r/Pivots/Pivots.Tests.cs +++ b/tests/indicators/m-r/Pivots/Pivots.Tests.cs @@ -6,8 +6,8 @@ public class PivotsTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetPivots(4, 4, 20, EndType.HighLow) + List results = Quotes + .GetPivots(4, 4) .ToList(); // proper quantities @@ -38,18 +38,18 @@ public override void Standard() PivotsResult r120 = results[120]; Assert.AreEqual(233.02m, r120.HighPoint); - Assert.AreEqual(PivotTrend.LH, r120.HighTrend); + Assert.AreEqual(PivotTrend.Lh, r120.HighTrend); Assert.AreEqual(233.02m, r120.HighLine); Assert.AreEqual(null, r120.LowPoint); - Assert.AreEqual(PivotTrend.LL, r120.LowTrend); + Assert.AreEqual(PivotTrend.Ll, r120.LowTrend); Assert.AreEqual(228.9671m, r120.LowLine.Round(4)); PivotsResult r180 = results[180]; Assert.AreEqual(239.74m, r180.HighPoint); - Assert.AreEqual(PivotTrend.HH, r180.HighTrend); + Assert.AreEqual(PivotTrend.Hh, r180.HighTrend); Assert.AreEqual(239.74m, r180.HighLine); Assert.AreEqual(null, r180.LowPoint); - Assert.AreEqual(PivotTrend.HL, r180.LowTrend); + Assert.AreEqual(PivotTrend.Hl, r180.LowTrend); Assert.AreEqual(236.7050m, r180.LowLine.Round(4)); PivotsResult r250 = results[250]; @@ -62,10 +62,10 @@ public override void Standard() PivotsResult r472 = results[472]; Assert.AreEqual(null, r472.HighPoint); - Assert.AreEqual(PivotTrend.LH, r472.HighTrend); + Assert.AreEqual(PivotTrend.Lh, r472.HighTrend); Assert.AreEqual(274.14m, r472.HighLine); Assert.AreEqual(null, r472.LowPoint); - Assert.AreEqual(PivotTrend.HL, r472.LowTrend); + Assert.AreEqual(PivotTrend.Hl, r472.LowTrend); Assert.AreEqual(255.8078m, r472.LowLine.Round(4)); PivotsResult r497 = results[497]; @@ -88,7 +88,7 @@ public override void Standard() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetPivots() .ToList(); @@ -98,13 +98,13 @@ public override void BadData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetPivots() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetPivots() .ToList(); @@ -114,8 +114,8 @@ public override void NoQuotes() [TestMethod] public void Condense() { - List r = quotes - .GetPivots(4, 4, 20, EndType.HighLow) + List r = Quotes + .GetPivots(4, 4) .Condense() .ToList(); @@ -127,14 +127,14 @@ public void Exceptions() { // bad left span Assert.ThrowsException(() => - quotes.GetPivots(1)); + Quotes.GetPivots(1)); // bad right span Assert.ThrowsException(() => - quotes.GetPivots(2, 1)); + Quotes.GetPivots(2, 1)); // bad lookback window Assert.ThrowsException(() => - quotes.GetPivots(20, 10, 20, EndType.Close)); + Quotes.GetPivots(20, 10, 20, EndType.Close)); } } diff --git a/tests/indicators/m-r/Pmo/Pmo.Tests.cs b/tests/indicators/m-r/Pmo/Pmo.Tests.cs index ee72a6d96..e8149c4a1 100644 --- a/tests/indicators/m-r/Pmo/Pmo.Tests.cs +++ b/tests/indicators/m-r/Pmo/Pmo.Tests.cs @@ -6,8 +6,8 @@ public class PmoTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetPmo(35, 20, 10) + List results = Quotes + .GetPmo() .ToList(); // proper quantities @@ -28,7 +28,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetPmo() .ToList(); @@ -40,7 +40,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetPmo() .ToList(); @@ -52,7 +52,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetPmo() .GetSma(10) .ToList(); @@ -64,24 +64,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetPmo(25, 15, 5) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Pmo is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Pmo is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetPmo() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetPmo() .ToList(); @@ -91,8 +91,8 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes - .GetPmo(35, 20, 10) + List results = Quotes + .GetPmo() .RemoveWarmupPeriods() .ToList(); @@ -109,14 +109,14 @@ public void Exceptions() { // bad time period Assert.ThrowsException(() => - quotes.GetPmo(1)); + Quotes.GetPmo(1)); // bad smoothing period Assert.ThrowsException(() => - quotes.GetPmo(5, 0)); + Quotes.GetPmo(5, 0)); // bad signal period Assert.ThrowsException(() => - quotes.GetPmo(5, 5, 0)); + Quotes.GetPmo(5, 5, 0)); } } diff --git a/tests/indicators/m-r/Prs/Prs.Tests.cs b/tests/indicators/m-r/Prs/Prs.Tests.cs index b206e25fa..bc6b342dc 100644 --- a/tests/indicators/m-r/Prs/Prs.Tests.cs +++ b/tests/indicators/m-r/Prs/Prs.Tests.cs @@ -8,8 +8,8 @@ public override void Standard() { int lookbackPeriods = 30; - List results = otherQuotes - .GetPrs(quotes, lookbackPeriods) + List results = OtherQuotes + .GetPrs(Quotes, lookbackPeriods) .ToList(); // proper quantities @@ -33,9 +33,9 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = otherQuotes + List results = OtherQuotes .Use(CandlePart.Close) - .GetPrs(quotes.Use(CandlePart.Close), 20) + .GetPrs(Quotes.Use(CandlePart.Close), 20) .ToList(); Assert.AreEqual(502, results.Count); @@ -45,8 +45,8 @@ public void UseReusable() [TestMethod] public void Chainor() { - List results = otherQuotes - .GetPrs(quotes, 20) + List results = OtherQuotes + .GetPrs(Quotes, 20) .GetSma(10) .ToList(); @@ -57,38 +57,38 @@ public void Chainor() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) - .GetPrs(otherQuotes.GetSma(2), 20) + .GetPrs(OtherQuotes.GetSma(2), 20) .ToList(); Assert.AreEqual(502, results.Count); Assert.AreEqual(501, results.Count(x => x.Prs != null)); - Assert.AreEqual(0, results.Count(x => x.Prs is double and double.NaN)); + Assert.AreEqual(0, results.Count(x => x.Prs is double.NaN)); } [TestMethod] public override void BadData() { - List r = badQuotes - .GetPrs(badQuotes, 15) + List r = BadQuotes + .GetPrs(BadQuotes, 15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Prs is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Prs is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes - .GetPrs(noquotes) + List r0 = Noquotes + .GetPrs(Noquotes) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote - .GetPrs(onequote) + List r1 = Onequote + .GetPrs(Onequote) .ToList(); Assert.AreEqual(1, r1.Count); @@ -99,18 +99,18 @@ public void Exceptions() { // bad lookback period Assert.ThrowsException(() => - otherQuotes.GetPrs(quotes, 0)); + OtherQuotes.GetPrs(Quotes, 0)); // insufficient quotes Assert.ThrowsException(() => - TestData.GetCompare(13).GetPrs(quotes, 14)); + TestData.GetCompare(13).GetPrs(Quotes, 14)); // insufficient eval quotes Assert.ThrowsException(() => - TestData.GetCompare(300).GetPrs(quotes, 14)); + TestData.GetCompare(300).GetPrs(Quotes, 14)); // mismatch quotes Assert.ThrowsException(() => - otherQuotes.GetPrs(mismatchQuotes, 14)); + OtherQuotes.GetPrs(MismatchQuotes, 14)); } } diff --git a/tests/indicators/m-r/Pvo/Pvo.Tests.cs b/tests/indicators/m-r/Pvo/Pvo.Tests.cs index c7a31372a..1bdcfd49c 100644 --- a/tests/indicators/m-r/Pvo/Pvo.Tests.cs +++ b/tests/indicators/m-r/Pvo/Pvo.Tests.cs @@ -11,7 +11,7 @@ public override void Standard() int signalPeriods = 9; List results = - quotes.GetPvo(fastPeriods, slowPeriods, signalPeriods) + Quotes.GetPvo(fastPeriods, slowPeriods, signalPeriods) .ToList(); // proper quantities @@ -50,7 +50,7 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetPvo() .GetSma(10) .ToList(); @@ -62,24 +62,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetPvo(10, 20, 5) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Pvo is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Pvo is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetPvo() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetPvo() .ToList(); @@ -93,7 +93,7 @@ public void Removed() int slowPeriods = 26; int signalPeriods = 9; - List results = quotes + List results = Quotes .GetPvo(fastPeriods, slowPeriods, signalPeriods) .RemoveWarmupPeriods() .ToList(); @@ -112,14 +112,14 @@ public void Exceptions() { // bad fast period Assert.ThrowsException(() => - quotes.GetPvo(0, 26, 9)); + Quotes.GetPvo(0)); // bad slow periods must be larger than faster period Assert.ThrowsException(() => - quotes.GetPvo(12, 12, 9)); + Quotes.GetPvo(12, 12)); // bad signal period Assert.ThrowsException(() => - quotes.GetPvo(12, 26, -1)); + Quotes.GetPvo(12, 26, -1)); } } diff --git a/tests/indicators/m-r/Renko/Renko.Tests.cs b/tests/indicators/m-r/Renko/Renko.Tests.cs index 9770e38b4..2e7323836 100644 --- a/tests/indicators/m-r/Renko/Renko.Tests.cs +++ b/tests/indicators/m-r/Renko/Renko.Tests.cs @@ -6,8 +6,8 @@ public class RenkoTests : SeriesTestBase [TestMethod] public void StandardClose() { - List results = quotes - .GetRenko(2.5m, EndType.Close) + List results = Quotes + .GetRenko(2.5m) .ToList(); // assertions @@ -45,7 +45,7 @@ public void StandardClose() [TestMethod] public void StandardHighLow() { - List results = quotes + List results = Quotes .GetRenko(2.5m, EndType.HighLow) .ToList(); @@ -82,8 +82,8 @@ public void StandardHighLow() [TestMethod] public void Atr() { - List results = quotes - .GetRenkoAtr(14, EndType.Close) + List results = Quotes + .GetRenkoAtr(14) .ToList(); // proper quantities @@ -110,7 +110,7 @@ public void Atr() [TestMethod] public void UseAsQuotes() { - IEnumerable renkoQuotes = quotes.GetRenko(2.5m); + IEnumerable renkoQuotes = Quotes.GetRenko(2.5m); IEnumerable renkoSma = renkoQuotes.GetSma(5); Assert.AreEqual(108, renkoSma.Count(x => x.Sma != null)); } @@ -118,7 +118,7 @@ public void UseAsQuotes() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetRenko(100m) .ToList(); @@ -128,7 +128,7 @@ public override void BadData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetRenko(0.01m) .ToList(); @@ -140,10 +140,10 @@ public void Exceptions() { // bad arguments Assert.ThrowsException(() - => quotes.GetRenko(0)); + => Quotes.GetRenko(0)); // bad end type Assert.ThrowsException(() - => quotes.GetRenko(2, (EndType)int.MaxValue)); + => Quotes.GetRenko(2, (EndType)int.MaxValue)); } } diff --git a/tests/indicators/m-r/Roc/Roc.Tests.cs b/tests/indicators/m-r/Roc/Roc.Tests.cs index 983376b74..df1f4f702 100644 --- a/tests/indicators/m-r/Roc/Roc.Tests.cs +++ b/tests/indicators/m-r/Roc/Roc.Tests.cs @@ -6,7 +6,7 @@ public class RocTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetRoc(20) .ToList(); @@ -32,7 +32,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetRoc(20) .ToList(); @@ -44,7 +44,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetRoc(20) .ToList(); @@ -56,7 +56,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetRoc(20) .GetSma(10) .ToList(); @@ -68,24 +68,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetRoc(35) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Roc is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Roc is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetRoc(5) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetRoc(5) .ToList(); @@ -95,7 +95,7 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes + List results = Quotes .GetRoc(20) .RemoveWarmupPeriods() .ToList(); @@ -111,5 +111,5 @@ public void Removed() public void Exceptions() => // bad lookback period Assert.ThrowsException(() => - quotes.GetRoc(0)); + Quotes.GetRoc(0)); } diff --git a/tests/indicators/m-r/RocWb/RocWb.Tests.cs b/tests/indicators/m-r/RocWb/RocWb.Tests.cs index cb2c06821..28909092c 100644 --- a/tests/indicators/m-r/RocWb/RocWb.Tests.cs +++ b/tests/indicators/m-r/RocWb/RocWb.Tests.cs @@ -6,7 +6,7 @@ public class RocWbTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetRocWb(20, 3, 20) .ToList(); @@ -70,7 +70,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetRocWb(20, 3, 20) .ToList(); @@ -82,7 +82,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetRocWb(20, 3, 20) .ToList(); @@ -94,7 +94,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetRocWb(20, 3, 20) .GetSma(10) .ToList(); @@ -106,24 +106,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetRocWb(35, 3, 35) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Roc is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Roc is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetRocWb(5, 3, 2) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetRocWb(5, 3, 2) .ToList(); @@ -133,7 +133,7 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes + List results = Quotes .GetRocWb(20, 3, 20) .RemoveWarmupPeriods() .ToList(); @@ -153,14 +153,14 @@ public void Exceptions() { // bad lookback period Assert.ThrowsException(() => - quotes.GetRocWb(0, 3, 12)); + Quotes.GetRocWb(0, 3, 12)); // bad EMA period Assert.ThrowsException(() => - quotes.GetRocWb(14, 0, 14)); + Quotes.GetRocWb(14, 0, 14)); // bad STDDEV period Assert.ThrowsException(() => - quotes.GetRocWb(15, 3, 16)); + Quotes.GetRocWb(15, 3, 16)); } } diff --git a/tests/indicators/m-r/RollingPivots/RollingPivots.Tests.cs b/tests/indicators/m-r/RollingPivots/RollingPivots.Tests.cs index 1678cde72..0abb1ab11 100644 --- a/tests/indicators/m-r/RollingPivots/RollingPivots.Tests.cs +++ b/tests/indicators/m-r/RollingPivots/RollingPivots.Tests.cs @@ -11,16 +11,16 @@ public override void Standard() PivotPointType pointType = PivotPointType.Standard; List results = - quotes.GetRollingPivots(windowPeriods, offsetPeriods, pointType) + Quotes.GetRollingPivots(windowPeriods, offsetPeriods, pointType) .ToList(); // proper quantities Assert.AreEqual(502, results.Count); - Assert.AreEqual(482, results.Count(x => x.PP != null)); + Assert.AreEqual(482, results.Count(x => x.Pp != null)); // sample values RollingPivotsResult r1 = results[19]; - Assert.AreEqual(null, r1.PP); + Assert.AreEqual(null, r1.Pp); Assert.AreEqual(null, r1.S1); Assert.AreEqual(null, r1.S2); Assert.AreEqual(null, r1.S3); @@ -31,7 +31,7 @@ public override void Standard() Assert.AreEqual(null, r1.R4); RollingPivotsResult r2 = results[20]; - Assert.AreEqual(213.6367m, r2.PP.Round(4)); + Assert.AreEqual(213.6367m, r2.Pp.Round(4)); Assert.AreEqual(212.1033m, r2.S1.Round(4)); Assert.AreEqual(209.9867m, r2.S2.Round(4)); Assert.AreEqual(208.4533m, r2.S3.Round(4)); @@ -42,7 +42,7 @@ public override void Standard() Assert.AreEqual(null, r2.R4); RollingPivotsResult r3 = results[149]; - Assert.AreEqual(233.6333m, r3.PP.Round(4)); + Assert.AreEqual(233.6333m, r3.Pp.Round(4)); Assert.AreEqual(231.3567m, r3.S1.Round(4)); Assert.AreEqual(227.3733m, r3.S2.Round(4)); Assert.AreEqual(225.0967m, r3.S3.Round(4)); @@ -53,7 +53,7 @@ public override void Standard() Assert.AreEqual(null, r3.R4); RollingPivotsResult r4 = results[249]; - Assert.AreEqual(253.9533m, r4.PP.Round(4)); + Assert.AreEqual(253.9533m, r4.Pp.Round(4)); Assert.AreEqual(251.5267m, r4.S1.Round(4)); Assert.AreEqual(247.4433m, r4.S2.Round(4)); Assert.AreEqual(245.0167m, r4.S3.Round(4)); @@ -64,7 +64,7 @@ public override void Standard() Assert.AreEqual(null, r4.R4); RollingPivotsResult r5 = results[501]; - Assert.AreEqual(260.0267m, r5.PP.Round(4)); + Assert.AreEqual(260.0267m, r5.Pp.Round(4)); Assert.AreEqual(246.4633m, r5.S1.Round(4)); Assert.AreEqual(238.7767m, r5.S2.Round(4)); Assert.AreEqual(225.2133m, r5.S3.Round(4)); @@ -90,13 +90,13 @@ public void Camarilla() // proper quantities Assert.AreEqual(38, results.Count); - Assert.AreEqual(28, results.Count(x => x.PP != null)); + Assert.AreEqual(28, results.Count(x => x.Pp != null)); // sample values RollingPivotsResult r1 = results[9]; Assert.AreEqual(null, r1.R4); Assert.AreEqual(null, r1.R3); - Assert.AreEqual(null, r1.PP); + Assert.AreEqual(null, r1.Pp); Assert.AreEqual(null, r1.S1); Assert.AreEqual(null, r1.S2); Assert.AreEqual(null, r1.R1); @@ -105,7 +105,7 @@ public void Camarilla() Assert.AreEqual(null, r1.S4); RollingPivotsResult r2 = results[10]; - Assert.AreEqual(267.0800m, r2.PP.Round(4)); + Assert.AreEqual(267.0800m, r2.Pp.Round(4)); Assert.AreEqual(265.8095m, r2.S1.Round(4)); Assert.AreEqual(264.5390m, r2.S2.Round(4)); Assert.AreEqual(263.2685m, r2.S3.Round(4)); @@ -116,7 +116,7 @@ public void Camarilla() Assert.AreEqual(274.7030m, r2.R4.Round(4)); RollingPivotsResult r3 = results[22]; - Assert.AreEqual(263.2900m, r3.PP.Round(4)); + Assert.AreEqual(263.2900m, r3.Pp.Round(4)); Assert.AreEqual(261.6840m, r3.S1.Round(4)); Assert.AreEqual(260.0780m, r3.S2.Round(4)); Assert.AreEqual(258.4720m, r3.S3.Round(4)); @@ -127,7 +127,7 @@ public void Camarilla() Assert.AreEqual(272.9260m, r3.R4.Round(4)); RollingPivotsResult r4 = results[23]; - Assert.AreEqual(257.1700m, r4.PP.Round(4)); + Assert.AreEqual(257.1700m, r4.Pp.Round(4)); Assert.AreEqual(255.5640m, r4.S1.Round(4)); Assert.AreEqual(253.9580m, r4.S2.Round(4)); Assert.AreEqual(252.3520m, r4.S3.Round(4)); @@ -138,7 +138,7 @@ public void Camarilla() Assert.AreEqual(266.8060m, r4.R4.Round(4)); RollingPivotsResult r5 = results[37]; - Assert.AreEqual(243.1500m, r5.PP.Round(4)); + Assert.AreEqual(243.1500m, r5.Pp.Round(4)); Assert.AreEqual(240.5650m, r5.S1.Round(4)); Assert.AreEqual(237.9800m, r5.S2.Round(4)); Assert.AreEqual(235.3950m, r5.S3.Round(4)); @@ -156,17 +156,17 @@ public void Demark() int offsetPeriods = 10; PivotPointType pointType = PivotPointType.Demark; - List results = quotes + List results = Quotes .GetRollingPivots(windowPeriods, offsetPeriods, pointType) .ToList(); // proper quantities Assert.AreEqual(502, results.Count); - Assert.AreEqual(482, results.Count(x => x.PP != null)); + Assert.AreEqual(482, results.Count(x => x.Pp != null)); // sample values RollingPivotsResult r1 = results[19]; - Assert.AreEqual(null, r1.PP); + Assert.AreEqual(null, r1.Pp); Assert.AreEqual(null, r1.S1); Assert.AreEqual(null, r1.S2); Assert.AreEqual(null, r1.S3); @@ -177,7 +177,7 @@ public void Demark() Assert.AreEqual(null, r1.R4); RollingPivotsResult r2 = results[20]; - Assert.AreEqual(212.9900m, r2.PP.Round(4)); + Assert.AreEqual(212.9900m, r2.Pp.Round(4)); Assert.AreEqual(210.8100m, r2.S1.Round(4)); Assert.AreEqual(214.4600m, r2.R1.Round(4)); Assert.AreEqual(null, r2.R2); @@ -188,7 +188,7 @@ public void Demark() Assert.AreEqual(null, r2.S4); RollingPivotsResult r3 = results[149]; - Assert.AreEqual(232.6525m, r3.PP.Round(4)); + Assert.AreEqual(232.6525m, r3.Pp.Round(4)); Assert.AreEqual(229.3950m, r3.S1.Round(4)); Assert.AreEqual(235.6550m, r3.R1.Round(4)); Assert.AreEqual(null, r3.R2); @@ -199,7 +199,7 @@ public void Demark() Assert.AreEqual(null, r3.S4); RollingPivotsResult r4 = results[250]; - Assert.AreEqual(252.9325m, r4.PP.Round(4)); + Assert.AreEqual(252.9325m, r4.Pp.Round(4)); Assert.AreEqual(249.4850m, r4.S1.Round(4)); Assert.AreEqual(255.9950m, r4.R1.Round(4)); Assert.AreEqual(null, r4.R2); @@ -210,7 +210,7 @@ public void Demark() Assert.AreEqual(null, r4.S4); RollingPivotsResult r5 = results[251]; - Assert.AreEqual(252.6700m, r5.PP.Round(4)); + Assert.AreEqual(252.6700m, r5.Pp.Round(4)); Assert.AreEqual(248.9600m, r5.S1.Round(4)); Assert.AreEqual(255.4700m, r5.R1.Round(4)); Assert.AreEqual(null, r5.R2); @@ -221,7 +221,7 @@ public void Demark() Assert.AreEqual(null, r5.S4); RollingPivotsResult r6 = results[501]; - Assert.AreEqual(264.6125m, r6.PP.Round(4)); + Assert.AreEqual(264.6125m, r6.Pp.Round(4)); Assert.AreEqual(255.6350m, r6.S1.Round(4)); Assert.AreEqual(276.8850m, r6.R1.Round(4)); Assert.AreEqual(null, r6.R2); @@ -247,13 +247,13 @@ public void Fibonacci() // proper quantities Assert.AreEqual(300, results.Count); - Assert.AreEqual(241, results.Count(x => x.PP != null)); + Assert.AreEqual(241, results.Count(x => x.Pp != null)); // sample values RollingPivotsResult r1 = results[58]; Assert.AreEqual(null, r1.R4); Assert.AreEqual(null, r1.R3); - Assert.AreEqual(null, r1.PP); + Assert.AreEqual(null, r1.Pp); Assert.AreEqual(null, r1.S1); Assert.AreEqual(null, r1.S2); Assert.AreEqual(null, r1.R1); @@ -262,7 +262,7 @@ public void Fibonacci() Assert.AreEqual(null, r1.S4); RollingPivotsResult r2 = results[59]; - Assert.AreEqual(368.4283m, r2.PP.Round(4)); + Assert.AreEqual(368.4283m, r2.Pp.Round(4)); Assert.AreEqual(367.8553m, r2.S1.Round(4)); Assert.AreEqual(367.5013m, r2.S2.Round(4)); Assert.AreEqual(366.9283m, r2.S3.Round(4)); @@ -271,7 +271,7 @@ public void Fibonacci() Assert.AreEqual(369.9283m, r2.R3.Round(4)); RollingPivotsResult r3 = results[118]; - Assert.AreEqual(369.1573m, r3.PP.Round(4)); + Assert.AreEqual(369.1573m, r3.Pp.Round(4)); Assert.AreEqual(368.7333m, r3.S1.Round(4)); Assert.AreEqual(368.4713m, r3.S2.Round(4)); Assert.AreEqual(368.0473m, r3.S3.Round(4)); @@ -280,7 +280,7 @@ public void Fibonacci() Assert.AreEqual(370.2673m, r3.R3.Round(4)); RollingPivotsResult r4 = results[119]; - Assert.AreEqual(369.1533m, r4.PP.Round(4)); + Assert.AreEqual(369.1533m, r4.Pp.Round(4)); Assert.AreEqual(368.7293m, r4.S1.Round(4)); Assert.AreEqual(368.4674m, r4.S2.Round(4)); Assert.AreEqual(368.0433m, r4.S3.Round(4)); @@ -289,7 +289,7 @@ public void Fibonacci() Assert.AreEqual(370.2633m, r4.R3.Round(4)); RollingPivotsResult r5 = results[149]; - Assert.AreEqual(369.0183m, r5.PP.Round(4)); + Assert.AreEqual(369.0183m, r5.Pp.Round(4)); Assert.AreEqual(368.6593m, r5.S1.Round(4)); Assert.AreEqual(368.4374m, r5.S2.Round(4)); Assert.AreEqual(368.0783m, r5.S3.Round(4)); @@ -298,7 +298,7 @@ public void Fibonacci() Assert.AreEqual(369.9583m, r5.R3.Round(4)); RollingPivotsResult r6 = results[299]; - Assert.AreEqual(367.7567m, r6.PP.Round(4)); + Assert.AreEqual(367.7567m, r6.Pp.Round(4)); Assert.AreEqual(367.3174m, r6.S1.Round(4)); Assert.AreEqual(367.0460m, r6.S2.Round(4)); Assert.AreEqual(366.6067m, r6.S3.Round(4)); @@ -314,7 +314,7 @@ public void Woodie() int offsetPeriods = 16; PivotPointType pointType = PivotPointType.Woodie; - IEnumerable h = TestData.GetIntraday(1564); + IEnumerable h = TestData.GetIntraday(); List results = h .GetRollingPivots(windowPeriods, offsetPeriods, pointType) @@ -322,13 +322,13 @@ public void Woodie() // proper quantities Assert.AreEqual(1564, results.Count); - Assert.AreEqual(1173, results.Count(x => x.PP != null)); + Assert.AreEqual(1173, results.Count(x => x.Pp != null)); // sample values RollingPivotsResult r2 = results[390]; Assert.AreEqual(null, r2.R4); Assert.AreEqual(null, r2.R3); - Assert.AreEqual(null, r2.PP); + Assert.AreEqual(null, r2.Pp); Assert.AreEqual(null, r2.S1); Assert.AreEqual(null, r2.S2); Assert.AreEqual(null, r2.R1); @@ -337,7 +337,7 @@ public void Woodie() Assert.AreEqual(null, r2.S4); RollingPivotsResult r3 = results[391]; - Assert.AreEqual(368.7850m, r3.PP.Round(4)); + Assert.AreEqual(368.7850m, r3.Pp.Round(4)); Assert.AreEqual(367.9901m, r3.S1.Round(4)); Assert.AreEqual(365.1252m, r3.S2.Round(4)); Assert.AreEqual(364.3303m, r3.S3.Round(4)); @@ -346,7 +346,7 @@ public void Woodie() Assert.AreEqual(375.3097m, r3.R3.Round(4)); RollingPivotsResult r4 = results[1172]; - Assert.AreEqual(371.75m, r4.PP.Round(4)); + Assert.AreEqual(371.75m, r4.Pp.Round(4)); Assert.AreEqual(371.04m, r4.S1.Round(4)); Assert.AreEqual(369.35m, r4.S2.Round(4)); Assert.AreEqual(368.64m, r4.S3.Round(4)); @@ -355,7 +355,7 @@ public void Woodie() Assert.AreEqual(375.84m, r4.R3.Round(4)); RollingPivotsResult r5 = results[1173]; - Assert.AreEqual(371.3625m, r5.PP.Round(4)); + Assert.AreEqual(371.3625m, r5.Pp.Round(4)); Assert.AreEqual(370.2650m, r5.S1.Round(4)); Assert.AreEqual(369.9525m, r5.S2.Round(4)); Assert.AreEqual(368.8550m, r5.S3.Round(4)); @@ -364,7 +364,7 @@ public void Woodie() Assert.AreEqual(373.0850m, r5.R3.Round(4)); RollingPivotsResult r6 = results[1563]; - Assert.AreEqual(369.38m, r6.PP.Round(4)); + Assert.AreEqual(369.38m, r6.Pp.Round(4)); Assert.AreEqual(366.52m, r6.S1.Round(4)); Assert.AreEqual(364.16m, r6.S2.Round(4)); Assert.AreEqual(361.30m, r6.S3.Round(4)); @@ -376,7 +376,7 @@ public void Woodie() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetRollingPivots(5, 5) .ToList(); @@ -386,13 +386,13 @@ public override void BadData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetRollingPivots(5, 2) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetRollingPivots(5, 2) .ToList(); @@ -406,7 +406,7 @@ public void Removed() int offsetPeriods = 9; PivotPointType pointType = PivotPointType.Standard; - List results = quotes + List results = Quotes .GetRollingPivots(windowPeriods, offsetPeriods, pointType) .RemoveWarmupPeriods() .ToList(); @@ -415,7 +415,7 @@ public void Removed() Assert.AreEqual(502 - (windowPeriods + offsetPeriods), results.Count); RollingPivotsResult last = results.LastOrDefault(); - Assert.AreEqual(260.0267m, last.PP.Round(4)); + Assert.AreEqual(260.0267m, last.Pp.Round(4)); Assert.AreEqual(246.4633m, last.S1.Round(4)); Assert.AreEqual(238.7767m, last.S2.Round(4)); Assert.AreEqual(225.2133m, last.S3.Round(4)); @@ -431,10 +431,10 @@ public void Exceptions() { // bad window period Assert.ThrowsException(() => - quotes.GetRollingPivots(0, 10)); + Quotes.GetRollingPivots(0, 10)); // bad offset period Assert.ThrowsException(() => - quotes.GetRollingPivots(10, -1)); + Quotes.GetRollingPivots(10, -1)); } } diff --git a/tests/indicators/m-r/Rsi/Rsi.Tests.cs b/tests/indicators/m-r/Rsi/Rsi.Tests.cs index fecc5b62d..a2dbd70bf 100644 --- a/tests/indicators/m-r/Rsi/Rsi.Tests.cs +++ b/tests/indicators/m-r/Rsi/Rsi.Tests.cs @@ -6,8 +6,8 @@ public class RsiTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetRsi(14) + List results = Quotes + .GetRsi() .ToList(); // proper quantities @@ -32,7 +32,7 @@ public override void Standard() public void SmallLookback() { int lookbackPeriods = 1; - List results = quotes + List results = Quotes .GetRsi(lookbackPeriods) .ToList(); @@ -63,9 +63,9 @@ public void CryptoData() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) - .GetRsi(14) + .GetRsi() .ToList(); Assert.AreEqual(502, results.Count); @@ -75,9 +75,9 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) - .GetRsi(14) + .GetRsi() .ToList(); Assert.AreEqual(502, results.Count); @@ -87,8 +87,8 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes - .GetRsi(14) + List results = Quotes + .GetRsi() .GetSma(10) .ToList(); @@ -100,32 +100,32 @@ public void Chainor() public void NaN() { IEnumerable r = TestData.GetBtcUsdNan() - .GetRsi(14); + .GetRsi(); - Assert.AreEqual(0, r.Count(x => x.Rsi is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Rsi is double.NaN)); } [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetRsi(20) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Rsi is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Rsi is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetRsi() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetRsi() .ToList(); @@ -135,13 +135,13 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes - .GetRsi(14) + List results = Quotes + .GetRsi() .RemoveWarmupPeriods() .ToList(); // assertions - Assert.AreEqual(502 - (10 * 14), results.Count); + Assert.AreEqual(502 - 10 * 14, results.Count); RsiResult last = results.LastOrDefault(); Assert.AreEqual(42.0773, last.Rsi.Round(4)); @@ -151,5 +151,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetRsi(0)); + => Quotes.GetRsi(0)); } diff --git a/tests/indicators/s-z/Slope/Slope.Tests.cs b/tests/indicators/s-z/Slope/Slope.Tests.cs index 922f6cfdf..439f78bd0 100644 --- a/tests/indicators/s-z/Slope/Slope.Tests.cs +++ b/tests/indicators/s-z/Slope/Slope.Tests.cs @@ -6,7 +6,7 @@ public class SlopeTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetSlope(20) .ToList(); @@ -42,7 +42,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetSlope(20) .ToList(); @@ -54,7 +54,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetSlope(20) .ToList(); @@ -66,7 +66,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetSlope(20) .GetSma(10) .ToList(); @@ -78,18 +78,18 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetSlope(15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Slope is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Slope is double.NaN)); } [TestMethod] public void BigData() { - List r = bigQuotes + List r = BigQuotes .GetSlope(250) .ToList(); @@ -99,13 +99,13 @@ public void BigData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetSlope(5) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetSlope(5) .ToList(); @@ -115,7 +115,7 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes + List results = Quotes .GetSlope(20) .RemoveWarmupPeriods() .ToList(); @@ -135,5 +135,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetSlope(1)); + => Quotes.GetSlope(1)); } diff --git a/tests/indicators/s-z/Sma/Sma.Analysis.Tests.cs b/tests/indicators/s-z/Sma/Sma.Analysis.Tests.cs index 9b29fbe29..5ad618680 100644 --- a/tests/indicators/s-z/Sma/Sma.Analysis.Tests.cs +++ b/tests/indicators/s-z/Sma/Sma.Analysis.Tests.cs @@ -6,7 +6,7 @@ public class SmaAnalysisTests : SeriesTestBase [TestMethod] public void Analysis() { - List results = quotes + List results = Quotes .GetSmaAnalysis(20) .ToList(); @@ -25,7 +25,7 @@ public void Analysis() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetSmaAnalysis(20) .ToList(); @@ -37,7 +37,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetSmaAnalysis(20) .ToList(); @@ -49,7 +49,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetSmaAnalysis(10) .GetEma(10) .ToList(); @@ -61,24 +61,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetSmaAnalysis(15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Mape is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Mape is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetSmaAnalysis(6) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetSmaAnalysis(6) .ToList(); @@ -88,7 +88,7 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes + List results = Quotes .GetSmaAnalysis(20) .RemoveWarmupPeriods() .ToList(); @@ -102,5 +102,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetSmaAnalysis(0)); + => Quotes.GetSmaAnalysis(0)); } diff --git a/tests/indicators/s-z/Sma/Sma.Series.Tests.cs b/tests/indicators/s-z/Sma/Sma.Series.Tests.cs index e061b0bed..43dc0c3b9 100644 --- a/tests/indicators/s-z/Sma/Sma.Series.Tests.cs +++ b/tests/indicators/s-z/Sma/Sma.Series.Tests.cs @@ -6,7 +6,7 @@ public class SmaTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetSma(20) .ToList(); @@ -26,7 +26,7 @@ public override void Standard() [TestMethod] public void CandlePartOpen() { - List results = quotes + List results = Quotes .Use(CandlePart.Open) .GetSma(20) .ToList(); @@ -46,7 +46,7 @@ public void CandlePartOpen() [TestMethod] public void CandlePartVolume() { - List results = quotes + List results = Quotes .Use(CandlePart.Volume) .GetSma(20) .ToList(); @@ -62,14 +62,14 @@ public void CandlePartVolume() Assert.AreEqual(157958070.8, r290.Sma); SmaResult r501 = results[501]; - Assert.AreEqual(DateTime.ParseExact("12/31/2018", "MM/dd/yyyy", EnglishCulture), r501.Timestamp); + Assert.AreEqual(DateTime.ParseExact("12/31/2018", "MM/dd/yyyy", englishCulture), r501.Timestamp); Assert.AreEqual(163695200, r501.Sma); } [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetSma(10) .GetEma(10) .ToList(); @@ -85,30 +85,30 @@ public void NaN() .GetSma(50) .ToList(); - Assert.AreEqual(0, r.Count(x => x.Sma is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Sma is double.NaN)); } [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetSma(15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Sma is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Sma is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetSma(5) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetSma(5) .ToList(); @@ -118,7 +118,7 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes + List results = Quotes .GetSma(20) .RemoveWarmupPeriods() .ToList(); @@ -131,20 +131,11 @@ public void Removed() [TestMethod] public void Equality() { - SmaResult r1 = new() { - Timestamp = evalDate, - Sma = 1d - }; + SmaResult r1 = new(Timestamp: EvalDate, Sma: 1d); - SmaResult r2 = new() { - Timestamp = evalDate, - Sma = 1d - }; + SmaResult r2 = new(Timestamp: EvalDate, Sma: 1d); - SmaResult r3 = new() { - Timestamp = evalDate, - Sma = 2d - }; + SmaResult r3 = new(Timestamp: EvalDate, Sma: 2d); Assert.IsTrue(Equals(r1, r2)); Assert.IsFalse(Equals(r1, r3)); @@ -163,5 +154,5 @@ public void Equality() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetSma(0)); + => Quotes.GetSma(0)); } diff --git a/tests/indicators/s-z/Sma/Sma.Stream.Tests.cs b/tests/indicators/s-z/Sma/Sma.Stream.Tests.cs index e371f5211..b818d82ec 100644 --- a/tests/indicators/s-z/Sma/Sma.Stream.Tests.cs +++ b/tests/indicators/s-z/Sma/Sma.Stream.Tests.cs @@ -6,7 +6,7 @@ public class SmaTests : StreamTestBase, ITestChainObserver, ITestChainProvider [TestMethod] public override void QuoteObserver() { - List quotesList = quotes + List quotesList = Quotes .ToSortedList(); int length = quotesList.Count; @@ -16,7 +16,7 @@ public override void QuoteObserver() // initialize observer Sma observer = provider - .ToSma(20); + .ToSma(20); // fetch initial results (early) IEnumerable results @@ -54,7 +54,7 @@ List streamList // time-series, for comparison List seriesList = quotesList - .GetSma(20) + .GetSma(20) .ToList(); // assert, should equal series @@ -77,7 +77,7 @@ public void ChainProvider() int emaPeriods = 12; int smaPeriods = 8; - List quotesList = quotes + List quotesList = Quotes .ToSortedList(); int length = quotesList.Count; @@ -127,7 +127,7 @@ List streamList [TestMethod] public void ChainObserver() { - List quotesList = quotes + List quotesList = Quotes .ToSortedList(); int length = quotesList.Count; @@ -143,7 +143,7 @@ public void ChainObserver() // initialize observer Sma observer = provider - .Use(CandlePart.OC2) + .Use(CandlePart.Oc2) .ToSma(11); // emulate quote stream @@ -158,8 +158,8 @@ public void ChainObserver() [.. observer.Results]; // time-series, for comparison - List staticSma = quotes - .Use(CandlePart.OC2) + List staticSma = Quotes + .Use(CandlePart.Oc2) .GetSma(11) .ToList(); diff --git a/tests/indicators/s-z/Smi/Smi.Tests.cs b/tests/indicators/s-z/Smi/Smi.Tests.cs index c1a66b3bc..8beeb6398 100644 --- a/tests/indicators/s-z/Smi/Smi.Tests.cs +++ b/tests/indicators/s-z/Smi/Smi.Tests.cs @@ -6,8 +6,8 @@ public class SmiTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetSmi(14, 20, 5, 3) + List results = Quotes + .GetSmi(14, 20, 5) .ToList(); // proper quantities @@ -48,8 +48,8 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes - .GetSmi(14, 20, 5, 3) + List results = Quotes + .GetSmi(14, 20, 5) .GetSma(10) .ToList(); @@ -60,7 +60,7 @@ public void Chainor() [TestMethod] public void NoSignal() { - List results = quotes + List results = Quotes .GetSmi(5, 20, 20, 1) .ToList(); @@ -75,7 +75,7 @@ public void NoSignal() [TestMethod] public void SmallPeriods() { - List results = quotes + List results = Quotes .GetSmi(1, 1, 1, 5) .ToList(); @@ -96,24 +96,24 @@ public void SmallPeriods() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetSmi(5, 5, 1, 5) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Smi is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Smi is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes - .GetSmi(5, 5, 2) + List r0 = Noquotes + .GetSmi(5, 5) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetSmi(5, 3, 3) .ToList(); @@ -123,8 +123,8 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes - .GetSmi(14, 20, 5, 3) + List results = Quotes + .GetSmi(14, 20, 5) .RemoveWarmupPeriods() .ToList(); @@ -141,18 +141,18 @@ public void Exceptions() { // bad lookback period Assert.ThrowsException(() => - quotes.GetSmi(0, 5, 5, 5)); + Quotes.GetSmi(0, 5, 5, 5)); // bad first smooth period Assert.ThrowsException(() => - quotes.GetSmi(14, 0, 5, 5)); + Quotes.GetSmi(14, 0, 5, 5)); // bad second smooth period Assert.ThrowsException(() => - quotes.GetSmi(14, 3, 0, 5)); + Quotes.GetSmi(14, 3, 0, 5)); // bad signal Assert.ThrowsException(() => - quotes.GetSmi(9, 3, 1, 0)); + Quotes.GetSmi(9, 3, 1, 0)); } } diff --git a/tests/indicators/s-z/Smma/Smma.Tests.cs b/tests/indicators/s-z/Smma/Smma.Tests.cs index eeb19ab87..96578d506 100644 --- a/tests/indicators/s-z/Smma/Smma.Tests.cs +++ b/tests/indicators/s-z/Smma/Smma.Tests.cs @@ -6,7 +6,7 @@ public class SmmaTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetSmma(20) .ToList(); @@ -29,7 +29,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetSmma(20) .ToList(); @@ -41,7 +41,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetSmma(20) .ToList(); @@ -53,7 +53,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetSmma(20) .GetSma(10) .ToList(); @@ -65,24 +65,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetSmma(15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Smma is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Smma is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetSmma(5) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetSmma(5) .ToList(); @@ -92,7 +92,7 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes + List results = Quotes .GetSmma(20) .RemoveWarmupPeriods() .ToList(); @@ -106,5 +106,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetSmma(0)); + => Quotes.GetSmma(0)); } diff --git a/tests/indicators/s-z/StarcBands/StarcBands.Tests.cs b/tests/indicators/s-z/StarcBands/StarcBands.Tests.cs index 1adabebfe..205180b25 100644 --- a/tests/indicators/s-z/StarcBands/StarcBands.Tests.cs +++ b/tests/indicators/s-z/StarcBands/StarcBands.Tests.cs @@ -10,7 +10,7 @@ public override void Standard() int multiplier = 2; int atrPeriods = 14; - List results = quotes + List results = Quotes .GetStarcBands(smaPeriods, multiplier, atrPeriods) .ToList(); @@ -50,24 +50,24 @@ public override void Standard() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetStarcBands(10, 3, 15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.UpperBand is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.UpperBand is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetStarcBands(10) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetStarcBands(10) .ToList(); @@ -82,7 +82,7 @@ public void Condense() int atrPeriods = 14; int lookbackPeriods = Math.Max(smaPeriods, atrPeriods); - List results = quotes + List results = Quotes .GetStarcBands(smaPeriods, multiplier, atrPeriods) .Condense() .ToList(); @@ -104,7 +104,7 @@ public void Removed() int atrPeriods = 14; int lookbackPeriods = Math.Max(smaPeriods, atrPeriods); - List results = quotes + List results = Quotes .GetStarcBands(smaPeriods, multiplier, atrPeriods) .RemoveWarmupPeriods() .ToList(); @@ -123,14 +123,14 @@ public void Exceptions() { // bad EMA period Assert.ThrowsException(() => - quotes.GetStarcBands(1, 2, 10)); + Quotes.GetStarcBands(1)); // bad ATR period Assert.ThrowsException(() => - quotes.GetStarcBands(20, 2, 1)); + Quotes.GetStarcBands(20, 2, 1)); // bad multiplier Assert.ThrowsException(() => - quotes.GetStarcBands(20, 0, 10)); + Quotes.GetStarcBands(20, 0)); } } diff --git a/tests/indicators/s-z/Stc/Stc.Tests.cs b/tests/indicators/s-z/Stc/Stc.Tests.cs index b59d27b6d..8f92b0c46 100644 --- a/tests/indicators/s-z/Stc/Stc.Tests.cs +++ b/tests/indicators/s-z/Stc/Stc.Tests.cs @@ -10,7 +10,7 @@ public override void Standard() int fastPeriods = 12; int slowPeriods = 26; - List results = quotes + List results = Quotes .GetStc(cyclePeriods, fastPeriods, slowPeriods) .ToList(); @@ -38,7 +38,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetStc(9, 12, 26) .ToList(); @@ -50,7 +50,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetStc(9, 12, 26) .ToList(); @@ -62,7 +62,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetStc(9, 12, 26) .GetSma(10) .ToList(); @@ -74,24 +74,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes - .GetStc(10, 23, 50) + List r = BadQuotes + .GetStc() .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Stc is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Stc is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetStc() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetStc() .ToList(); @@ -106,7 +106,7 @@ public void Issue1107() RandomGbm quotes = new(58); List results = quotes - .GetStc(10, 23, 50) + .GetStc() .ToList(); Assert.AreEqual(58, results.Count); @@ -119,7 +119,7 @@ public void Removed() int fastPeriods = 12; int slowPeriods = 26; - List results = quotes + List results = Quotes .GetStc(cyclePeriods, fastPeriods, slowPeriods) .RemoveWarmupPeriods() .ToList(); @@ -136,14 +136,14 @@ public void Exceptions() { // bad fast period Assert.ThrowsException(() => - quotes.GetStc(9, 0, 26)); + Quotes.GetStc(9, 0, 26)); // bad slow periods must be larger than faster period Assert.ThrowsException(() => - quotes.GetStc(9, 12, 12)); + Quotes.GetStc(9, 12, 12)); // bad signal period Assert.ThrowsException(() => - quotes.GetStc(-1, 12, 26)); + Quotes.GetStc(-1, 12, 26)); } } diff --git a/tests/indicators/s-z/StdDev/StdDev.Tests.cs b/tests/indicators/s-z/StdDev/StdDev.Tests.cs index c219bda0f..8185aa060 100644 --- a/tests/indicators/s-z/StdDev/StdDev.Tests.cs +++ b/tests/indicators/s-z/StdDev/StdDev.Tests.cs @@ -6,7 +6,7 @@ public class StdDevTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetStdDev(10) .ToList(); @@ -40,7 +40,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetStdDev(10) .ToList(); @@ -52,7 +52,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetStdDev(10) .ToList(); @@ -64,7 +64,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetStdDev(10) .GetSma(10) .ToList(); @@ -76,18 +76,18 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetStdDev(15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.StdDev is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.StdDev is double.NaN)); } [TestMethod] public void BigData() { - List r = bigQuotes + List r = BigQuotes .GetStdDev(200) .ToList(); @@ -97,13 +97,13 @@ public void BigData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetStdDev(10) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetStdDev(10) .ToList(); @@ -113,7 +113,7 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes + List results = Quotes .GetStdDev(10) .RemoveWarmupPeriods() .ToList(); @@ -132,5 +132,5 @@ public void Exceptions() => // bad lookback period Assert.ThrowsException(() => - quotes.GetStdDev(1)); + Quotes.GetStdDev(1)); } diff --git a/tests/indicators/s-z/StdDevChannels/StdDevChannels.Tests.cs b/tests/indicators/s-z/StdDevChannels/StdDevChannels.Tests.cs index 3ac612f91..ff6d1077b 100644 --- a/tests/indicators/s-z/StdDevChannels/StdDevChannels.Tests.cs +++ b/tests/indicators/s-z/StdDevChannels/StdDevChannels.Tests.cs @@ -10,7 +10,7 @@ public override void Standard() double standardDeviations = 2; List results = - quotes.GetStdDevChannels(lookbackPeriods, standardDeviations) + Quotes.GetStdDevChannels(lookbackPeriods, standardDeviations) .ToList(); // proper quantities @@ -69,7 +69,7 @@ public void FullHistory() // null provided for lookback period List results = - quotes.GetStdDevChannels(null, 2) + Quotes.GetStdDevChannels(null) .ToList(); // proper quantities @@ -100,9 +100,9 @@ public void FullHistory() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) - .GetStdDevChannels(20, 2) + .GetStdDevChannels() .ToList(); Assert.AreEqual(502, results.Count); @@ -112,9 +112,9 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) - .GetStdDevChannels(20, 2) + .GetStdDevChannels() .ToList(); Assert.AreEqual(502, results.Count); @@ -124,24 +124,24 @@ public void Chainee() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetStdDevChannels() .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.UpperChannel is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.UpperChannel is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetStdDevChannels() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetStdDevChannels() .ToList(); @@ -154,7 +154,7 @@ public void Condense() int lookbackPeriods = 20; double standardDeviations = 2; - List results = quotes + List results = Quotes .GetStdDevChannels(lookbackPeriods, standardDeviations) .Condense() .ToList(); @@ -174,7 +174,7 @@ public void Removed() int lookbackPeriods = 20; double standardDeviations = 2; - List results = quotes + List results = Quotes .GetStdDevChannels(lookbackPeriods, standardDeviations) .RemoveWarmupPeriods() .ToList(); @@ -193,10 +193,10 @@ public void Exceptions() { // bad lookback period Assert.ThrowsException(() => - quotes.GetStdDevChannels(0)); + Quotes.GetStdDevChannels(0)); // bad standard deviations Assert.ThrowsException(() => - quotes.GetStdDevChannels(20, 0)); + Quotes.GetStdDevChannels(20, 0)); } } diff --git a/tests/indicators/s-z/Stoch/Stoch.Tests.cs b/tests/indicators/s-z/Stoch/Stoch.Tests.cs index 580d83095..9957a303c 100644 --- a/tests/indicators/s-z/Stoch/Stoch.Tests.cs +++ b/tests/indicators/s-z/Stoch/Stoch.Tests.cs @@ -10,7 +10,7 @@ public override void Standard() // Slow int signalPeriods = 3; int smoothPeriods = 3; - List results = quotes + List results = Quotes .GetStoch(lookbackPeriods, signalPeriods, smoothPeriods) .ToList(); @@ -47,10 +47,8 @@ public override void Standard() // Slow // test boundary condition - for (int i = 0; i < results.Count; i++) + foreach (StochResult r in results) { - StochResult r = results[i]; - if (r.Oscillator is not null) { Assert.IsTrue(r.Oscillator >= 0); @@ -72,10 +70,10 @@ public override void Standard() // Slow } [TestMethod] - public void Extended() // with extra parameteres + public void Extended() // with extra parameters { List results = - quotes.GetStoch(9, 3, 3, 5, 4, MaType.SMMA) + Quotes.GetStoch(9, 3, 3, 5, 4, MaType.Smma) .ToList(); // proper quantities @@ -118,7 +116,7 @@ public void Extended() // with extra parameteres [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetStoch() .GetSma(10) .ToList(); @@ -130,11 +128,11 @@ public void Chainor() [TestMethod] public void NoSignal() { - int lookbackPeriods = 5; - int signalPeriods = 1; - int smoothPeriods = 3; + const int lookbackPeriods = 5; + const int signalPeriods = 1; + const int smoothPeriods = 3; - List results = quotes + List results = Quotes .GetStoch(lookbackPeriods, signalPeriods, smoothPeriods) .ToList(); @@ -153,7 +151,7 @@ public void Fast() int signalPeriods = 10; int smoothPeriods = 1; - List results = quotes + List results = Quotes .GetStoch(lookbackPeriods, signalPeriods, smoothPeriods) .ToList(); @@ -174,7 +172,7 @@ public void FastSmall() int signalPeriods = 10; int smoothPeriods = 1; - List results = quotes + List results = Quotes .GetStoch(lookbackPeriods, signalPeriods, smoothPeriods) .ToList(); @@ -189,24 +187,24 @@ public void FastSmall() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetStoch(15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Oscillator is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Oscillator is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetStoch() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetStoch() .ToList(); @@ -220,7 +218,7 @@ public void Removed() int signalPeriods = 3; int smoothPeriods = 3; - List results = quotes + List results = Quotes .GetStoch(lookbackPeriods, signalPeriods, smoothPeriods) .RemoveWarmupPeriods() .ToList(); @@ -277,26 +275,26 @@ public void Exceptions() { // bad lookback period Assert.ThrowsException(() => - quotes.GetStoch(0)); + Quotes.GetStoch(0)); // bad signal period Assert.ThrowsException(() => - quotes.GetStoch(14, 0)); + Quotes.GetStoch(14, 0)); // bad smoothing period Assert.ThrowsException(() => - quotes.GetStoch(14, 3, 0)); + Quotes.GetStoch(14, 3, 0)); // bad kFactor Assert.ThrowsException(() => - quotes.GetStoch(9, 3, 1, 0, 2, MaType.SMA)); + Quotes.GetStoch(9, 3, 1, 0, 2, MaType.Sma)); // bad dFactor Assert.ThrowsException(() => - quotes.GetStoch(9, 3, 1, 3, 0, MaType.SMA)); + Quotes.GetStoch(9, 3, 1, 3, 0, MaType.Sma)); // bad MA type Assert.ThrowsException(() => - quotes.GetStoch(9, 3, 3, 3, 2, MaType.ALMA)); + Quotes.GetStoch(9, 3, 3, 3, 2, MaType.Alma)); } } diff --git a/tests/indicators/s-z/StochRsi/StochRsi.Tests.cs b/tests/indicators/s-z/StochRsi/StochRsi.Tests.cs index bc05a678a..c4933c46d 100644 --- a/tests/indicators/s-z/StochRsi/StochRsi.Tests.cs +++ b/tests/indicators/s-z/StochRsi/StochRsi.Tests.cs @@ -12,7 +12,7 @@ public void FastRsi() int smoothPeriods = 1; List results = - quotes.GetStochRsi(rsiPeriods, stochPeriods, signalPeriods, smoothPeriods) + Quotes.GetStochRsi(rsiPeriods, stochPeriods, signalPeriods, smoothPeriods) .ToList(); // assertions @@ -49,7 +49,7 @@ public void SlowRsi() int smoothPeriods = 3; List results = - quotes.GetStochRsi(rsiPeriods, stochPeriods, signalPeriods, smoothPeriods) + Quotes.GetStochRsi(rsiPeriods, stochPeriods, signalPeriods, smoothPeriods) .ToList(); // assertions @@ -80,22 +80,22 @@ public void SlowRsi() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) - .GetStochRsi(14, 14, 3, 1) + .GetStochRsi(14, 14, 3) .ToList(); Assert.AreEqual(502, results.Count); Assert.AreEqual(475, results.Count(x => x.StochRsi != null)); - Assert.AreEqual(0, results.Count(x => x.StochRsi is double and double.NaN)); + Assert.AreEqual(0, results.Count(x => x.StochRsi is double.NaN)); } [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) - .GetStochRsi(14, 14, 3, 1) + .GetStochRsi(14, 14, 3) .ToList(); Assert.AreEqual(502, results.Count); @@ -105,7 +105,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetStochRsi(14, 14, 3, 3) .GetSma(10) .ToList(); @@ -117,24 +117,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetStochRsi(15, 20, 3, 2) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.StochRsi is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.StochRsi is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetStochRsi(10, 20, 3) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetStochRsi(8, 13, 2) .ToList(); @@ -149,7 +149,7 @@ public void Removed() int signalPeriods = 3; int smoothPeriods = 3; - List results = quotes + List results = Quotes .GetStochRsi(rsiPeriods, stochPeriods, signalPeriods, smoothPeriods) .RemoveWarmupPeriods() .ToList(); @@ -168,18 +168,18 @@ public void Exceptions() { // bad RSI period Assert.ThrowsException(() => - quotes.GetStochRsi(0, 14, 3, 1)); + Quotes.GetStochRsi(0, 14, 3)); // bad STO period Assert.ThrowsException(() => - quotes.GetStochRsi(14, 0, 3, 3)); + Quotes.GetStochRsi(14, 0, 3, 3)); // bad STO signal period Assert.ThrowsException(() => - quotes.GetStochRsi(14, 14, 0)); + Quotes.GetStochRsi(14, 14, 0)); // bad STO smoothing period Assert.ThrowsException(() => - quotes.GetStochRsi(14, 14, 3, 0)); + Quotes.GetStochRsi(14, 14, 3, 0)); } } diff --git a/tests/indicators/s-z/SuperTrend/SuperTrend.Tests.cs b/tests/indicators/s-z/SuperTrend/SuperTrend.Tests.cs index 03c974987..7b7d8a2b6 100644 --- a/tests/indicators/s-z/SuperTrend/SuperTrend.Tests.cs +++ b/tests/indicators/s-z/SuperTrend/SuperTrend.Tests.cs @@ -6,10 +6,10 @@ public class SuperTrendTests : SeriesTestBase [TestMethod] public override void Standard() { - int lookbackPeriods = 14; - double multiplier = 3; + const int lookbackPeriods = 14; + const double multiplier = 3; - List results = quotes + List results = Quotes .GetSuperTrend(lookbackPeriods, multiplier) .ToList(); @@ -55,7 +55,7 @@ public void Bitcoin() IEnumerable h = TestData.GetBitcoin(); List results = h - .GetSuperTrend(10, 3) + .GetSuperTrend() .ToList(); Assert.AreEqual(1246, results.Count); @@ -67,7 +67,7 @@ public void Bitcoin() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetSuperTrend(7) .ToList(); @@ -77,13 +77,13 @@ public override void BadData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetSuperTrend() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetSuperTrend() .ToList(); @@ -96,7 +96,7 @@ public void Condense() int lookbackPeriods = 14; double multiplier = 3; - List results = quotes + List results = Quotes .GetSuperTrend(lookbackPeriods, multiplier) .Condense() .ToList(); @@ -116,7 +116,7 @@ public void Removed() int lookbackPeriods = 14; double multiplier = 3; - List results = quotes + List results = Quotes .GetSuperTrend(lookbackPeriods, multiplier) .RemoveWarmupPeriods() .ToList(); @@ -135,10 +135,10 @@ public void Exceptions() { // bad lookback period Assert.ThrowsException(() => - quotes.GetSuperTrend(1)); + Quotes.GetSuperTrend(1)); // bad multiplier Assert.ThrowsException(() => - quotes.GetSuperTrend(7, 0)); + Quotes.GetSuperTrend(7, 0)); } } diff --git a/tests/indicators/s-z/T3/T3.Tests.cs b/tests/indicators/s-z/T3/T3.Tests.cs index b2916492c..373a839db 100644 --- a/tests/indicators/s-z/T3/T3.Tests.cs +++ b/tests/indicators/s-z/T3/T3.Tests.cs @@ -6,8 +6,8 @@ public class T3Tests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetT3(5, 0.7) + List results = Quotes + .GetT3() .ToList(); // proper quantities @@ -37,7 +37,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetT3() .ToList(); @@ -49,7 +49,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetT3() .ToList(); @@ -61,7 +61,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetT3() .GetSma(10) .ToList(); @@ -72,24 +72,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetT3() .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.T3 is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.T3 is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetT3() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetT3() .ToList(); @@ -101,10 +101,10 @@ public void Exceptions() { // bad lookback period Assert.ThrowsException(() => - quotes.GetT3(0)); + Quotes.GetT3(0)); // bad volume factor Assert.ThrowsException(() => - quotes.GetT3(25, 0)); + Quotes.GetT3(25, 0)); } } diff --git a/tests/indicators/s-z/Tema/Tema.Tests.cs b/tests/indicators/s-z/Tema/Tema.Tests.cs index 86325d7cc..5e7608ed5 100644 --- a/tests/indicators/s-z/Tema/Tema.Tests.cs +++ b/tests/indicators/s-z/Tema/Tema.Tests.cs @@ -6,7 +6,7 @@ public class TemaTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetTema(20) .ToList(); @@ -31,7 +31,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetTema(20) .ToList(); @@ -43,7 +43,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetTema(20) .ToList(); @@ -55,7 +55,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetTema(20) .GetSma(10) .ToList(); @@ -67,24 +67,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetTema(15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Tema is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Tema is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetTema(5) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetTema(5) .ToList(); @@ -94,13 +94,13 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes + List results = Quotes .GetTema(20) .RemoveWarmupPeriods() .ToList(); // assertions - Assert.AreEqual(502 - ((3 * 20) + 100), results.Count); + Assert.AreEqual(502 - (3 * 20 + 100), results.Count); TemaResult last = results.LastOrDefault(); Assert.AreEqual(238.7690, last.Tema.Round(4)); @@ -110,5 +110,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetTema(0)); + => Quotes.GetTema(0)); } diff --git a/tests/indicators/s-z/Tr/Tr.Tests.cs b/tests/indicators/s-z/Tr/Tr.Tests.cs index 8e5252384..b9310be9e 100644 --- a/tests/indicators/s-z/Tr/Tr.Tests.cs +++ b/tests/indicators/s-z/Tr/Tr.Tests.cs @@ -6,7 +6,7 @@ public class TrTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetTr() .ToList(); @@ -41,13 +41,13 @@ public override void Standard() public void Chainor() { // same as ATR - List results = quotes + List results = Quotes .GetTr() .GetSmma(14) .ToList(); - List atrResults = quotes - .GetAtr(14) + List atrResults = Quotes + .GetAtr() .ToList(); for (int i = 0; i < results.Count; i++) @@ -63,24 +63,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetTr() .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Tr is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Tr is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetTr() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetTr() .ToList(); diff --git a/tests/indicators/s-z/Trix/Trix.Tests.cs b/tests/indicators/s-z/Trix/Trix.Tests.cs index ade3ca62c..76f3b844a 100644 --- a/tests/indicators/s-z/Trix/Trix.Tests.cs +++ b/tests/indicators/s-z/Trix/Trix.Tests.cs @@ -6,7 +6,7 @@ public class TrixTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetTrix(20) .ToList(); @@ -36,7 +36,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetTrix(20) .ToList(); @@ -48,7 +48,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetTrix(20) .ToList(); @@ -60,7 +60,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetTrix(20) .GetSma(10) .ToList(); @@ -72,24 +72,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetTrix(15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Trix is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Trix is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetTrix(5) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetTrix(5) .ToList(); @@ -99,13 +99,13 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes + List results = Quotes .GetTrix(20) .RemoveWarmupPeriods() .ToList(); // assertions - Assert.AreEqual(502 - ((3 * 20) + 100), results.Count); + Assert.AreEqual(502 - (3 * 20 + 100), results.Count); TrixResult last = results.LastOrDefault(); Assert.AreEqual(263.3216, last.Ema3.Round(4)); @@ -116,5 +116,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetTrix(0)); + => Quotes.GetTrix(0)); } diff --git a/tests/indicators/s-z/Tsi/Tsi.Tests.cs b/tests/indicators/s-z/Tsi/Tsi.Tests.cs index cfec8a19a..8d5fbc5d2 100644 --- a/tests/indicators/s-z/Tsi/Tsi.Tests.cs +++ b/tests/indicators/s-z/Tsi/Tsi.Tests.cs @@ -6,8 +6,8 @@ public class TsiTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetTsi(25, 13, 7) + List results = Quotes + .GetTsi() .ToList(); // proper quantities @@ -20,13 +20,13 @@ public override void Standard() Assert.AreEqual(53.1204, r2.Tsi.Round(4)); Assert.AreEqual(null, r2.Signal); - TsiResult r3a = results[43]; - Assert.AreEqual(46.0960, r3a.Tsi.Round(4)); - Assert.AreEqual(51.6916, r3a.Signal.Round(4)); + TsiResult r3A = results[43]; + Assert.AreEqual(46.0960, r3A.Tsi.Round(4)); + Assert.AreEqual(51.6916, r3A.Signal.Round(4)); - TsiResult r3b = results[44]; - Assert.AreEqual(42.5121, r3b.Tsi.Round(4)); - Assert.AreEqual(49.3967, r3b.Signal.Round(4)); + TsiResult r3B = results[44]; + Assert.AreEqual(42.5121, r3B.Tsi.Round(4)); + Assert.AreEqual(49.3967, r3B.Signal.Round(4)); TsiResult r4 = results[149]; Assert.AreEqual(29.0936, r4.Tsi.Round(4)); @@ -44,7 +44,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetTsi() .ToList(); @@ -56,7 +56,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetTsi() .ToList(); @@ -68,7 +68,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetTsi() .GetSma(10) .ToList(); @@ -80,18 +80,18 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetTsi() .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Tsi is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Tsi is double.NaN)); } [TestMethod] public void BigData() { - List r = bigQuotes + List r = BigQuotes .GetTsi() .ToList(); @@ -101,13 +101,13 @@ public void BigData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetTsi() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetTsi() .ToList(); @@ -117,8 +117,8 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes - .GetTsi(25, 13, 7) + List results = Quotes + .GetTsi() .RemoveWarmupPeriods() .ToList(); @@ -135,14 +135,14 @@ public void Exceptions() { // bad lookback period Assert.ThrowsException(() => - quotes.GetTsi(0)); + Quotes.GetTsi(0)); // bad smoothing period Assert.ThrowsException(() => - quotes.GetTsi(25, 0)); + Quotes.GetTsi(25, 0)); // bad signal period Assert.ThrowsException(() => - quotes.GetTsi(25, 13, -1)); + Quotes.GetTsi(25, 13, -1)); } } diff --git a/tests/indicators/s-z/UlcerIndex/UlcerIndex.Tests.cs b/tests/indicators/s-z/UlcerIndex/UlcerIndex.Tests.cs index e95f7acc6..156adbd3a 100644 --- a/tests/indicators/s-z/UlcerIndex/UlcerIndex.Tests.cs +++ b/tests/indicators/s-z/UlcerIndex/UlcerIndex.Tests.cs @@ -6,8 +6,8 @@ public class UlcerIndexTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetUlcerIndex(14) + List results = Quotes + .GetUlcerIndex() .ToList(); // proper quantities @@ -22,9 +22,9 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) - .GetUlcerIndex(14) + .GetUlcerIndex() .ToList(); Assert.AreEqual(502, results.Count); @@ -34,9 +34,9 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) - .GetUlcerIndex(14) + .GetUlcerIndex() .ToList(); Assert.AreEqual(502, results.Count); @@ -46,8 +46,8 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes - .GetUlcerIndex(14) + List results = Quotes + .GetUlcerIndex() .GetSma(10) .ToList(); @@ -58,24 +58,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetUlcerIndex(15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.UlcerIndex is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.UlcerIndex is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetUlcerIndex() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetUlcerIndex() .ToList(); @@ -85,8 +85,8 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes - .GetUlcerIndex(14) + List results = Quotes + .GetUlcerIndex() .RemoveWarmupPeriods() .ToList(); @@ -101,5 +101,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetUlcerIndex(0)); + => Quotes.GetUlcerIndex(0)); } diff --git a/tests/indicators/s-z/Ultimate/Ultimate.Tests.cs b/tests/indicators/s-z/Ultimate/Ultimate.Tests.cs index 06b4c503d..46e245db8 100644 --- a/tests/indicators/s-z/Ultimate/Ultimate.Tests.cs +++ b/tests/indicators/s-z/Ultimate/Ultimate.Tests.cs @@ -6,8 +6,8 @@ public class UltimateTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetUltimate(7, 14, 28) + List results = Quotes + .GetUltimate() .ToList(); // proper quantities @@ -28,7 +28,7 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetUltimate() .GetSma(10) .ToList(); @@ -40,24 +40,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetUltimate(1, 2, 3) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Ultimate is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Ultimate is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetUltimate() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetUltimate() .ToList(); @@ -67,8 +67,8 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes - .GetUltimate(7, 14, 28) + List results = Quotes + .GetUltimate() .RemoveWarmupPeriods() .ToList(); @@ -84,14 +84,14 @@ public void Exceptions() { // bad short period Assert.ThrowsException(() => - quotes.GetUltimate(0)); + Quotes.GetUltimate(0)); // bad middle period Assert.ThrowsException(() => - quotes.GetUltimate(7, 6)); + Quotes.GetUltimate(7, 6)); // bad long period Assert.ThrowsException(() => - quotes.GetUltimate(7, 14, 11)); + Quotes.GetUltimate(7, 14, 11)); } } diff --git a/tests/indicators/s-z/VolatilityStop/VolatilityStop.Tests.cs b/tests/indicators/s-z/VolatilityStop/VolatilityStop.Tests.cs index fd319660f..ed310c4d4 100644 --- a/tests/indicators/s-z/VolatilityStop/VolatilityStop.Tests.cs +++ b/tests/indicators/s-z/VolatilityStop/VolatilityStop.Tests.cs @@ -7,7 +7,7 @@ public class VolatilityStopTests : SeriesTestBase public override void Standard() { List results = - quotes.GetVolatilityStop(14, 3) + Quotes.GetVolatilityStop(14) .ToList(); // proper quantities @@ -64,7 +64,7 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetVolatilityStop() .GetSma(10) .ToList(); @@ -76,24 +76,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetVolatilityStop() .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Sar is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Sar is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetVolatilityStop() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetVolatilityStop() .ToList(); @@ -103,8 +103,8 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes - .GetVolatilityStop(14, 3) + List results = Quotes + .GetVolatilityStop(14) .RemoveWarmupPeriods() .ToList(); @@ -121,10 +121,10 @@ public void Exceptions() { // bad lookback period Assert.ThrowsException(() => - quotes.GetVolatilityStop(1)); + Quotes.GetVolatilityStop(1)); // bad multiplier Assert.ThrowsException(() => - quotes.GetVolatilityStop(20, 0)); + Quotes.GetVolatilityStop(20, 0)); } } diff --git a/tests/indicators/s-z/Vortex/Vortex.Tests.cs b/tests/indicators/s-z/Vortex/Vortex.Tests.cs index 85e436c22..59e5b1753 100644 --- a/tests/indicators/s-z/Vortex/Vortex.Tests.cs +++ b/tests/indicators/s-z/Vortex/Vortex.Tests.cs @@ -6,7 +6,7 @@ public class VortexTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetVortex(14) .ToList(); @@ -39,24 +39,24 @@ public override void Standard() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetVortex(20) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Pvi is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Pvi is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetVortex(5) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetVortex(5) .ToList(); @@ -66,7 +66,7 @@ public override void NoQuotes() [TestMethod] public void Condense() { - List results = quotes + List results = Quotes .GetVortex(14) .Condense() .ToList(); @@ -82,7 +82,7 @@ public void Condense() [TestMethod] public void Removed() { - List results = quotes + List results = Quotes .GetVortex(14) .RemoveWarmupPeriods() .ToList(); @@ -99,5 +99,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetVortex(1)); + => Quotes.GetVortex(1)); } diff --git a/tests/indicators/s-z/Vwap/Vwap.Tests.cs b/tests/indicators/s-z/Vwap/Vwap.Tests.cs index ed324cae6..df3e98fbd 100644 --- a/tests/indicators/s-z/Vwap/Vwap.Tests.cs +++ b/tests/indicators/s-z/Vwap/Vwap.Tests.cs @@ -3,14 +3,14 @@ namespace Tests.Indicators.Series; [TestClass] public class VwapTests : SeriesTestBase { - private readonly IEnumerable intraday = TestData.GetIntraday() + private readonly IEnumerable _intraday = TestData.GetIntraday() .OrderBy(x => x.Timestamp) .Take(391); [TestMethod] public override void Standard() { - List results = intraday.GetVwap() + List results = _intraday.GetVwap() .ToList(); // proper quantities @@ -35,9 +35,9 @@ public override void Standard() public void WithStartDate() { DateTime startDate = - DateTime.ParseExact("2020-12-15 10:00", "yyyy-MM-dd h:mm", EnglishCulture); + DateTime.ParseExact("2020-12-15 10:00", "yyyy-MM-dd h:mm", englishCulture); - List results = intraday + List results = _intraday .GetVwap(startDate) .ToList(); @@ -62,7 +62,7 @@ public void WithStartDate() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetVwap() .GetSma(10) .ToList(); @@ -74,24 +74,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetVwap() .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Vwap is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Vwap is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetVwap() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetVwap() .ToList(); @@ -102,7 +102,7 @@ public override void NoQuotes() public void Removed() { // no start date - List results = intraday + List results = _intraday .GetVwap() .RemoveWarmupPeriods() .ToList(); @@ -115,9 +115,9 @@ public void Removed() // with start date DateTime startDate = - DateTime.ParseExact("2020-12-15 10:00", "yyyy-MM-dd h:mm", EnglishCulture); + DateTime.ParseExact("2020-12-15 10:00", "yyyy-MM-dd h:mm", englishCulture); - List sdResults = intraday + List sdResults = _intraday .GetVwap(startDate) .RemoveWarmupPeriods() .ToList(); @@ -134,9 +134,9 @@ public void Exceptions() { // bad SMA period DateTime startDate = - DateTime.ParseExact("2000-12-15", "yyyy-MM-dd", EnglishCulture); + DateTime.ParseExact("2000-12-15", "yyyy-MM-dd", englishCulture); Assert.ThrowsException(() => - quotes.GetVwap(startDate)); + Quotes.GetVwap(startDate)); } } diff --git a/tests/indicators/s-z/Vwma/Vwma.Tests.cs b/tests/indicators/s-z/Vwma/Vwma.Tests.cs index 5dcd700c3..e9601c74a 100644 --- a/tests/indicators/s-z/Vwma/Vwma.Tests.cs +++ b/tests/indicators/s-z/Vwma/Vwma.Tests.cs @@ -6,7 +6,7 @@ public class VwmaTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetVwma(10) .ToList(); @@ -28,7 +28,7 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetVwma(10) .GetSma(10) .ToList(); @@ -40,24 +40,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetVwma(15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Vwma is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Vwma is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetVwma(4) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetVwma(4) .ToList(); @@ -67,7 +67,7 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes + List results = Quotes .GetVwma(10) .RemoveWarmupPeriods() .ToList(); @@ -83,5 +83,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetVwma(0)); + => Quotes.GetVwma(0)); } diff --git a/tests/indicators/s-z/WilliamsR/WilliamsR.Tests.cs b/tests/indicators/s-z/WilliamsR/WilliamsR.Tests.cs index dea4c9c18..568d9c1c0 100644 --- a/tests/indicators/s-z/WilliamsR/WilliamsR.Tests.cs +++ b/tests/indicators/s-z/WilliamsR/WilliamsR.Tests.cs @@ -6,8 +6,8 @@ public class WilliamsRTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes - .GetWilliamsR(14) + List results = Quotes + .GetWilliamsR() .ToList(); // proper quantities @@ -37,7 +37,7 @@ public override void Standard() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetWilliamsR() .GetSma(10) .ToList(); @@ -49,27 +49,24 @@ public void Chainor() [TestMethod] public override void BadData() { - List quotes = badQuotes - .ToSortedList(); - - List results = badQuotes + List results = BadQuotes .GetWilliamsR(20) .ToList(); Assert.AreEqual(502, results.Count); - Assert.AreEqual(0, results.Count(x => x.WilliamsR is double and double.NaN)); + Assert.AreEqual(0, results.Count(x => x.WilliamsR is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetWilliamsR() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetWilliamsR() .ToList(); @@ -79,8 +76,8 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes - .GetWilliamsR(14) + List results = Quotes + .GetWilliamsR() .RemoveWarmupPeriods() .ToList(); @@ -96,7 +93,7 @@ public void Boundary() { List results = TestData .GetRandom(2500) - .GetWilliamsR(14) + .GetWilliamsR() .ToList(); // analyze boundary @@ -125,8 +122,8 @@ public void Issue1127() int length = quotesList.Count; // get indicators - List resultsList = test1127 - .GetWilliamsR(14) + List resultsList = quotesList + .GetWilliamsR() .ToList(); Console.WriteLine($"%R from {length} quotes."); @@ -151,5 +148,5 @@ public void Issue1127() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetWilliamsR(0)); + => Quotes.GetWilliamsR(0)); } diff --git a/tests/indicators/s-z/Wma/Wma.Tests.cs b/tests/indicators/s-z/Wma/Wma.Tests.cs index 88e3ce1a3..78d220000 100644 --- a/tests/indicators/s-z/Wma/Wma.Tests.cs +++ b/tests/indicators/s-z/Wma/Wma.Tests.cs @@ -6,7 +6,7 @@ public class WmaTests : SeriesTestBase [TestMethod] public override void Standard() { - List results = quotes + List results = Quotes .GetWma(20) .ToList(); @@ -25,7 +25,7 @@ public override void Standard() [TestMethod] public void UseReusable() { - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetWma(20) .ToList(); @@ -37,7 +37,7 @@ public void UseReusable() [TestMethod] public void Chainee() { - List results = quotes + List results = Quotes .GetSma(2) .GetWma(20) .ToList(); @@ -49,7 +49,7 @@ public void Chainee() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetWma(20) .GetSma(10) .ToList(); @@ -61,11 +61,11 @@ public void Chainor() [TestMethod] public void Chaining() { - List standard = quotes + List standard = Quotes .GetWma(17) .ToList(); - List results = quotes + List results = Quotes .Use(CandlePart.Close) .GetWma(17) .ToList(); @@ -84,24 +84,24 @@ public void Chaining() [TestMethod] public override void BadData() { - List r = badQuotes + List r = BadQuotes .GetWma(15) .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Wma is double and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Wma is double.NaN)); } [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetWma(5) .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetWma(5) .ToList(); @@ -111,7 +111,7 @@ public override void NoQuotes() [TestMethod] public void Removed() { - List results = quotes + List results = Quotes .GetWma(20) .RemoveWarmupPeriods() .ToList(); @@ -127,5 +127,5 @@ public void Removed() [TestMethod] public void Exceptions() => Assert.ThrowsException(() - => quotes.GetWma(0)); + => Quotes.GetWma(0)); } diff --git a/tests/indicators/s-z/ZigZag/ZigZag.Tests.cs b/tests/indicators/s-z/ZigZag/ZigZag.Tests.cs index fa8f1fd84..3e0537e4e 100644 --- a/tests/indicators/s-z/ZigZag/ZigZag.Tests.cs +++ b/tests/indicators/s-z/ZigZag/ZigZag.Tests.cs @@ -9,7 +9,7 @@ public class ZigZagTests : SeriesTestBase public void StandardClose() { List results = - quotes.GetZigZag(EndType.Close, 3) + Quotes.GetZigZag(EndType.Close, 3) .ToList(); // proper quantities @@ -61,7 +61,7 @@ public void StandardClose() public void StandardHighLow() { List results = - quotes.GetZigZag(EndType.HighLow, 3) + Quotes.GetZigZag(EndType.HighLow, 3) .ToList(); // proper quantities @@ -112,7 +112,7 @@ public void StandardHighLow() [TestMethod] public void Chainor() { - List results = quotes + List results = Quotes .GetZigZag(EndType.Close, 3) .GetSma(10) .ToList(); @@ -131,7 +131,7 @@ public void NoEntry() .DeserializeObject>(json); List results = quotes - .GetZigZag(EndType.Close, 5m) + .GetZigZag() .ToList(); Assert.AreEqual(0, results.Count(x => x.PointType != null)); @@ -148,7 +148,7 @@ public void Issue632() .ToList(); List resultsList = quotesList - .GetZigZag(EndType.Close, 5m) + .GetZigZag() .ToList(); Assert.AreEqual(17, resultsList.Count); @@ -157,13 +157,13 @@ public void Issue632() [TestMethod] public override void BadData() { - List r1 = badQuotes - .GetZigZag(EndType.Close) + List r1 = BadQuotes + .GetZigZag() .ToList(); Assert.AreEqual(502, r1.Count); - List r2 = badQuotes + List r2 = BadQuotes .GetZigZag(EndType.HighLow) .ToList(); @@ -173,13 +173,13 @@ public override void BadData() [TestMethod] public override void NoQuotes() { - List r0 = noquotes + List r0 = Noquotes .GetZigZag() .ToList(); Assert.AreEqual(0, r0.Count); - List r1 = onequote + List r1 = Onequote .GetZigZag() .ToList(); @@ -189,7 +189,7 @@ public override void NoQuotes() [TestMethod] public void Condense() { - List results = quotes + List results = Quotes .GetZigZag(EndType.Close, 3) .Condense() .ToList(); @@ -222,10 +222,10 @@ public void Exceptions() { // bad lookback period Assert.ThrowsException(() - => quotes.GetZigZag(EndType.Close, 0)); + => Quotes.GetZigZag(EndType.Close, 0)); // bad end type Assert.ThrowsException(() - => quotes.GetZigZag((EndType)int.MaxValue, 2)); + => Quotes.GetZigZag((EndType)int.MaxValue, 2)); } } diff --git a/tests/observe/Program.cs b/tests/observe/Program.cs index 53358f4d2..fe6bc5ee8 100644 --- a/tests/observe/Program.cs +++ b/tests/observe/Program.cs @@ -19,23 +19,23 @@ private static async Task Main(string[] args) public class QuoteStream { - private readonly string ALPACA_KEY = Environment.GetEnvironmentVariable("ALPACA_KEY"); - private readonly string ALPACA_SECRET = Environment.GetEnvironmentVariable("ALPACA_SECRET"); + private readonly string _alpacaKey = Environment.GetEnvironmentVariable("ALPACA_KEY"); + private readonly string _alpacaSecret = Environment.GetEnvironmentVariable("ALPACA_SECRET"); internal QuoteStream() { - if (string.IsNullOrEmpty(ALPACA_KEY)) + if (string.IsNullOrEmpty(_alpacaKey)) { throw new ArgumentNullException( - ALPACA_KEY, - $"API KEY missing, use `setx ALPACA_KEY \"MY_ALPACA_KEY\"` to set."); + _alpacaKey, + "API KEY missing, use `setx ALPACA_KEY \"MY_ALPACA_KEY\"` to set."); } - if (string.IsNullOrEmpty(ALPACA_SECRET)) + if (string.IsNullOrEmpty(_alpacaSecret)) { throw new ArgumentNullException( - ALPACA_SECRET, - $"API SECRET missing, use `setx ALPACA_SECRET \"MY_ALPACA_SECRET\"` to set."); + _alpacaSecret, + "API SECRET missing, use `setx ALPACA_SECRET \"MY_ALPACA_SECRET\"` to set."); } } @@ -44,14 +44,14 @@ public async Task SubscribeToQuotes(string symbol) Console.WriteLine("Press any key to exit the process..."); Console.WriteLine("PLEASE WAIT. QUOTES ARRIVE EVERY MINUTE."); - if (string.IsNullOrEmpty(ALPACA_KEY)) + if (string.IsNullOrEmpty(_alpacaKey)) { - throw new ArgumentNullException(ALPACA_KEY); + throw new ArgumentNullException(_alpacaKey); } - if (string.IsNullOrEmpty(ALPACA_SECRET)) + if (string.IsNullOrEmpty(_alpacaSecret)) { - throw new ArgumentNullException(ALPACA_SECRET); + throw new ArgumentNullException(_alpacaSecret); } // initialize our quote provider and a few subscribers @@ -60,14 +60,14 @@ public async Task SubscribeToQuotes(string symbol) Sma sma = provider.ToSma(3); Ema ema = provider.ToEma(5); Ema useChain = provider - .Use(CandlePart.HL2) + .Use(CandlePart.Hl2) .ToEma(7); Ema emaChain = provider .ToSma(4) .ToEma(4); // connect to Alpaca websocket - SecretKey secretKey = new(ALPACA_KEY, ALPACA_SECRET); + SecretKey secretKey = new(_alpacaKey, _alpacaSecret); IAlpacaCryptoStreamingClient client = Environments @@ -76,9 +76,6 @@ IAlpacaCryptoStreamingClient client await client.ConnectAndAuthenticateAsync(); - // TODO: is this needed? - AutoResetEvent[] waitObjects = [new AutoResetEvent(false)]; - IAlpacaDataSubscription quoteSubscription = client.GetMinuteBarSubscription(symbol); @@ -94,7 +91,7 @@ IAlpacaDataSubscription quoteSubscription Console.WriteLine("----------------------------------------------------------------------------------"); // handle new quotes - quoteSubscription.Received += (q) => { + quoteSubscription.Received += q => { // add to our provider provider.Add(new Quote { Timestamp = q.TimeUtc, diff --git a/tests/other/Convergence.Tests.cs b/tests/other/Convergence.Tests.cs index 6e0b5fd26..9d8e3f277 100644 --- a/tests/other/Convergence.Tests.cs +++ b/tests/other/Convergence.Tests.cs @@ -1,3 +1,4 @@ +// ReSharper disable All namespace Tests.Other; [TestClass] @@ -11,11 +12,11 @@ public void Adx() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetAdx(14); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetAdx(); AdxResult l = r.LastOrDefault(); - Console.WriteLine($"ADX(14) on {l.Timestamp:d} with {quotes.Count(),4} historical quotes: {l.Adx:N8}"); + Console.WriteLine($"ADX(14) on {l.Timestamp:d} with {qts.Count(),4} historical qts: {l.Adx:N8}"); } } @@ -24,11 +25,11 @@ public void Atr() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetAtr(14); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetAtr(); AtrResult l = r.LastOrDefault(); - Console.WriteLine($"ATR(14) on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.Atr:N8}"); + Console.WriteLine($"ATR(14) on {l.Timestamp:d} with {qts.Count(),4} periods: {l.Atr:N8}"); } } @@ -37,11 +38,11 @@ public void ChaikinOsc() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetChaikinOsc(); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetChaikinOsc(); ChaikinOscResult l = r.LastOrDefault(); - Console.WriteLine($"CHAIKIN OSC on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.Oscillator:N8}"); + Console.WriteLine($"CHAIKIN OSC on {l.Timestamp:d} with {qts.Count(),4} periods: {l.Oscillator:N8}"); } } @@ -50,11 +51,11 @@ public void ConnorsRsi() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetConnorsRsi(3, 2, 10); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetConnorsRsi(3, 2, 10); ConnorsRsiResult l = r.LastOrDefault(); - Console.WriteLine($"CRSI on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.ConnorsRsi:N8}"); + Console.WriteLine($"CRSI on {l.Timestamp:d} with {qts.Count(),4} periods: {l.ConnorsRsi:N8}"); } } @@ -63,11 +64,11 @@ public void Dema() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetDema(15); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetDema(15); DemaResult l = r.LastOrDefault(); - Console.WriteLine($"DEMA(15) on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.Dema:N8}"); + Console.WriteLine($"DEMA(15) on {l.Timestamp:d} with {qts.Count(),4} periods: {l.Dema:N8}"); } } @@ -76,11 +77,11 @@ public void Dynamic() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetDynamic(100); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetDynamic(100); DynamicResult l = r.LastOrDefault(); - Console.WriteLine($"DYNAMIC(15) on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.Dynamic:N8}"); + Console.WriteLine($"DYNAMIC(15) on {l.Timestamp:d} with {qts.Count(),4} periods: {l.Dynamic:N8}"); } } @@ -89,11 +90,11 @@ public void Ema() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetEma(15); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetEma(15); EmaResult l = r.LastOrDefault(); - Console.WriteLine($"EMA(15) on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.Ema:N8}"); + Console.WriteLine($"EMA(15) on {l.Timestamp:d} with {qts.Count(),4} periods: {l.Ema:N8}"); } } @@ -102,11 +103,11 @@ public void FisherTransform() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetFisherTransform(10); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetFisherTransform(); FisherTransformResult l = r.LastOrDefault(); - Console.WriteLine($"FT(10) on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.Fisher:N8}"); + Console.WriteLine($"FT(10) on {l.Timestamp:d} with {qts.Count(),4} periods: {l.Fisher:N8}"); } } @@ -115,11 +116,11 @@ public void HtTrendline() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetHtTrendline(); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetHtTrendline(); HtlResult l = r.LastOrDefault(); - Console.WriteLine($"HTL on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.Trendline:N8}"); + Console.WriteLine($"HTL on {l.Timestamp:d} with {qts.Count(),4} periods: {l.Trendline:N8}"); } } @@ -128,11 +129,11 @@ public void Kama() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetKama(10); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetKama(); KamaResult l = r.LastOrDefault(); - Console.WriteLine($"KAMA(10) on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.Kama:N8}"); + Console.WriteLine($"KAMA(10) on {l.Timestamp:d} with {qts.Count(),4} periods: {l.Kama:N8}"); } } @@ -141,11 +142,11 @@ public void Keltner() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetKeltner(100); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetKeltner(100); KeltnerResult l = r.LastOrDefault(); - Console.WriteLine($"KC-UP on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.UpperBand:N8}"); + Console.WriteLine($"KC-UP on {l.Timestamp:d} with {qts.Count(),4} periods: {l.UpperBand:N8}"); } } @@ -154,11 +155,11 @@ public void Macd() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(15 + qty); - IEnumerable r = quotes.GetMacd(); + IEnumerable qts = TestData.GetLongish(15 + qty); + IEnumerable r = qts.GetMacd(); MacdResult l = r.LastOrDefault(); - Console.WriteLine($"MACD on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.Macd:N8}"); + Console.WriteLine($"MACD on {l.Timestamp:d} with {qts.Count(),4} periods: {l.Macd:N8}"); } } @@ -167,11 +168,11 @@ public void Mama() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetMama(); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetMama(); MamaResult l = r.LastOrDefault(); - Console.WriteLine($"MAMA on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.Mama:N8}"); + Console.WriteLine($"MAMA on {l.Timestamp:d} with {qts.Count(),4} periods: {l.Mama:N8}"); } } @@ -180,11 +181,11 @@ public void Pmo() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetPmo(); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetPmo(); PmoResult l = r.LastOrDefault(); - Console.WriteLine($"PMO on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.Pmo:N8}"); + Console.WriteLine($"PMO on {l.Timestamp:d} with {qts.Count(),4} periods: {l.Pmo:N8}"); } } @@ -193,11 +194,11 @@ public void Pvo() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetPvo(); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetPvo(); PvoResult l = r.LastOrDefault(); - Console.WriteLine($"PVO on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.Pvo:N8}"); + Console.WriteLine($"PVO on {l.Timestamp:d} with {qts.Count(),4} periods: {l.Pvo:N8}"); } } @@ -206,11 +207,11 @@ public void Rsi() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetRsi(14); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetRsi(); RsiResult l = r.LastOrDefault(); - Console.WriteLine($"RSI(14) on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.Rsi:N8}"); + Console.WriteLine($"RSI(14) on {l.Timestamp:d} with {qts.Count(),4} periods: {l.Rsi:N8}"); } } @@ -219,11 +220,11 @@ public void Smi() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetDefault(qty); - IEnumerable r = quotes.GetSmi(14, 20, 5, 3); + IEnumerable qts = TestData.GetDefault(qty); + IEnumerable r = qts.GetSmi(14, 20, 5); SmiResult l = r.LastOrDefault(); - Console.WriteLine($"SMI on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.Smi:N8}"); + Console.WriteLine($"SMI on {l.Timestamp:d} with {qts.Count(),4} periods: {l.Smi:N8}"); } } @@ -232,11 +233,11 @@ public void Smma() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetSmma(15); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetSmma(15); SmmaResult l = r.LastOrDefault(); - Console.WriteLine($"SMMA(15) on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.Smma:N8}"); + Console.WriteLine($"SMMA(15) on {l.Timestamp:d} with {qts.Count(),4} periods: {l.Smma:N8}"); } } @@ -245,11 +246,11 @@ public void StarcBands() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetStarcBands(20); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetStarcBands(20); StarcBandsResult l = r.LastOrDefault(); - Console.WriteLine($"STARC UPPER on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.UpperBand:N8}"); + Console.WriteLine($"STARC UPPER on {l.Timestamp:d} with {qts.Count(),4} periods: {l.UpperBand:N8}"); } } @@ -258,11 +259,11 @@ public void StochRsi() { foreach (int qty in QuotesQuantities.Where(x => x <= 502)) { - IEnumerable quotes = TestData.GetDefault(qty); - IEnumerable r = quotes.GetStochRsi(14, 14, 3, 1); + IEnumerable qts = TestData.GetDefault(qty); + IEnumerable r = qts.GetStochRsi(14, 14, 3); StochRsiResult l = r.LastOrDefault(); - Console.WriteLine($"SRSI on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.StochRsi:N8}"); + Console.WriteLine($"SRSI on {l.Timestamp:d} with {qts.Count(),4} periods: {l.StochRsi:N8}"); } } @@ -271,11 +272,11 @@ public void T3() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetT3(20); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetT3(20); T3Result l = r.LastOrDefault(); - Console.WriteLine($"T3 on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.T3:N8}"); + Console.WriteLine($"T3 on {l.Timestamp:d} with {qts.Count(),4} periods: {l.T3:N8}"); } } @@ -284,11 +285,11 @@ public void Tema() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetTema(15); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetTema(15); TemaResult l = r.LastOrDefault(); - Console.WriteLine($"TEMA on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.Tema:N8}"); + Console.WriteLine($"TEMA on {l.Timestamp:d} with {qts.Count(),4} periods: {l.Tema:N8}"); } } @@ -297,11 +298,11 @@ public void Trix() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetTrix(15); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetTrix(15); TrixResult l = r.LastOrDefault(); - Console.WriteLine($"TRIX on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.Trix:N8}"); + Console.WriteLine($"TRIX on {l.Timestamp:d} with {qts.Count(),4} periods: {l.Trix:N8}"); } } @@ -310,11 +311,11 @@ public void Tsi() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(20 + qty); - IEnumerable r = quotes.GetTsi(); + IEnumerable qts = TestData.GetLongish(20 + qty); + IEnumerable r = qts.GetTsi(); TsiResult l = r.LastOrDefault(); - Console.WriteLine($"TSI on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.Tsi:N8}"); + Console.WriteLine($"TSI on {l.Timestamp:d} with {qts.Count(),4} periods: {l.Tsi:N8}"); } } @@ -323,11 +324,11 @@ public void Vortex() { foreach (int qty in QuotesQuantities) { - IEnumerable quotes = TestData.GetLongish(qty); - IEnumerable r = quotes.GetVortex(14); + IEnumerable qts = TestData.GetLongish(qty); + IEnumerable r = qts.GetVortex(14); VortexResult l = r.LastOrDefault(); - Console.WriteLine($"VI+ on {l.Timestamp:d} with {quotes.Count(),4} periods: {l.Pvi:N8}"); + Console.WriteLine($"VI+ on {l.Timestamp:d} with {qts.Count(),4} periods: {l.Pvi:N8}"); } } } diff --git a/tests/other/CustomIndicator.Tests.cs b/tests/other/CustomIndicator.Tests.cs index c801a2041..94d80986b 100644 --- a/tests/other/CustomIndicator.Tests.cs +++ b/tests/other/CustomIndicator.Tests.cs @@ -8,7 +8,7 @@ namespace Tests.CustomIndicators; public DateTime Timestamp { get; init; } public double? Sma { get; init; } - readonly double IReusable.Value + double IReusable.Value => Sma.Null2NaN(); } @@ -23,7 +23,7 @@ public static IEnumerable GetIndicator( .ToSortedCollection() .CalcIndicator(lookbackPeriods); - internal static List CalcIndicator( + private static List CalcIndicator( this Collection source, int lookbackPeriods) where T : IReusable @@ -43,8 +43,6 @@ internal static List CalcIndicator( { T s = source[i]; - MyResult result = new() { Timestamp = s.Timestamp }; - double? sma; if (i >= lookbackPeriods - 1) @@ -63,7 +61,7 @@ internal static List CalcIndicator( sma = null; } - results.Add(new MyResult() { + results.Add(new() { Timestamp = s.Timestamp, Sma = sma }); @@ -196,7 +194,7 @@ public void NaN() .GetIndicator(50) .ToList(); - Assert.AreEqual(0, r.Count(x => x.Sma is not null and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Sma is double.NaN)); } [TestMethod] @@ -207,7 +205,7 @@ public void BadData() .ToList(); Assert.AreEqual(502, r.Count); - Assert.AreEqual(0, r.Count(x => x.Sma is not null and double.NaN)); + Assert.AreEqual(0, r.Count(x => x.Sma is double.NaN)); } [TestMethod] diff --git a/tests/other/PublicApi.Tests.cs b/tests/other/PublicApi.Tests.cs index d9302dbdc..8cdf2feb9 100644 --- a/tests/other/PublicApi.Tests.cs +++ b/tests/other/PublicApi.Tests.cs @@ -2,12 +2,13 @@ [assembly: CLSCompliant(true)] namespace Tests.PublicApi; +// ReSharper disable All internal sealed class MyEma : IResult { - public DateTime Timestamp { get; set; } - public int Id { get; set; } - public bool MyProperty { get; set; } + public DateTime Timestamp { get; init; } + public int Id { get; init; } + public bool MyProperty { get; init; } public double? Ema { get; set; } } @@ -22,14 +23,14 @@ readonly decimal IQuote.Close // custom properties public int MyOtherProperty { get; set; } - public DateTime CloseDate { get; set; } - public decimal CloseValue { get; set; } + public DateTime CloseDate { get; init; } + public decimal CloseValue { get; init; } // required base properties - public decimal Open { get; set; } - public decimal High { get; set; } - public decimal Low { get; set; } - public decimal Volume { get; set; } + public decimal Open { get; init; } + public decimal High { get; init; } + public decimal Low { get; init; } + public decimal Volume { get; init; } readonly double IReusable.Value => (double)CloseValue; @@ -38,10 +39,10 @@ readonly double IReusable.Value [TestClass] public class PublicClassTests { - internal static readonly CultureInfo EnglishCulture + private static readonly CultureInfo EnglishCulture = new("en-US", false); - internal static readonly DateTime evalDate + private static readonly DateTime EvalDate = DateTime.ParseExact( "12/31/2018", "MM/dd/yyyy", EnglishCulture); @@ -50,9 +51,11 @@ public void ValidateHistory() { IEnumerable quotes = TestData.GetDefault(); - quotes.Validate(); - quotes.GetSma(6); - quotes.GetEma(5); + IEnumerable enumerable = quotes.ToList(); + + enumerable.Validate(); + enumerable.GetSma(6); + enumerable.GetEma(5); } [TestMethod] @@ -61,8 +64,6 @@ public void ReadQuoteClass() IEnumerable quotes = TestData.GetDefault(); IEnumerable h = quotes.Validate(); - QuoteProvider foo = new(); - Quote f = h.FirstOrDefault(); Console.WriteLine($"Quote:{f}"); } @@ -106,7 +107,7 @@ public void CustomQuoteSeries() public void EqualCustomQuotes() { MyCustomQuote q1 = new() { - CloseDate = evalDate, + CloseDate = EvalDate, Open = 1m, High = 1m, Low = 1m, @@ -115,7 +116,7 @@ public void EqualCustomQuotes() }; MyCustomQuote q2 = new() { - CloseDate = evalDate, + CloseDate = EvalDate, Open = 1m, High = 1m, Low = 1m, @@ -124,7 +125,7 @@ public void EqualCustomQuotes() }; MyCustomQuote q3 = new() { - CloseDate = evalDate, + CloseDate = EvalDate, Open = 1m, High = 1m, Low = 1m, @@ -235,7 +236,7 @@ public void CustomResultClassLinq() public void CustomResultClassFind() { IEnumerable quotes = TestData.GetDefault(); - IEnumerable emaResults = Indicator.GetEma(quotes, 20); + IEnumerable emaResults = quotes.GetEma(20); // can use a derive Indicator class using Linq diff --git a/tests/performance/Perf.Indicators.Series.cs b/tests/performance/Perf.Indicators.Series.cs index 5c26e75bf..a38937ef8 100644 --- a/tests/performance/Perf.Indicators.Series.cs +++ b/tests/performance/Perf.Indicators.Series.cs @@ -1,4 +1,5 @@ namespace Tests.Performance; +// ReSharper disable All public class IndicatorStaticTests { @@ -167,7 +168,7 @@ public static void SetupCompare() public object GetMacd() => q.GetMacd(); [Benchmark] - public object GetMaEnvelopes() => q.GetMaEnvelopes(20, 2.5, MaType.SMA); + public object GetMaEnvelopes() => q.GetMaEnvelopes(20, 2.5, MaType.Sma); [Benchmark] public object GetMama() => q.GetMama(); @@ -248,7 +249,7 @@ public static void SetupCompare() public object GetStoch() => q.GetStoch(); [Benchmark] - public object GetStochSMMA() => q.GetStoch(9, 3, 3, 3, 2, MaType.SMMA); + public object GetStochSMMA() => q.GetStoch(9, 3, 3, 3, 2, MaType.Smma); [Benchmark] public object GetStochRsi() => q.GetStochRsi(14, 14, 3); diff --git a/tests/performance/Perf.Indicators.Stream.External.cs b/tests/performance/Perf.Indicators.Stream.External.cs index 1ef908cec..5b36ba88b 100644 --- a/tests/performance/Perf.Indicators.Stream.External.cs +++ b/tests/performance/Perf.Indicators.Stream.External.cs @@ -1,4 +1,5 @@ namespace Tests.Performance; +// ReSharper disable All public class IndicatorStreamExternal { diff --git a/tests/performance/Perf.Indicators.Stream.cs b/tests/performance/Perf.Indicators.Stream.cs index cf59e1a9a..de1ba37fb 100644 --- a/tests/performance/Perf.Indicators.Stream.cs +++ b/tests/performance/Perf.Indicators.Stream.cs @@ -1,4 +1,5 @@ namespace Tests.Performance; +// ReSharper disable All public class IndicatorStreamTests { diff --git a/tests/performance/Perf.Library.Helpers.cs b/tests/performance/Perf.Library.Helpers.cs index 3ffd0d719..c73b0eaac 100644 --- a/tests/performance/Perf.Library.Helpers.cs +++ b/tests/performance/Perf.Library.Helpers.cs @@ -4,36 +4,36 @@ namespace Tests.Performance; public class LibraryHelpers { - private static IEnumerable h; - private static IEnumerable i; + private static IEnumerable _h; + private static IEnumerable _i; [GlobalSetup] - public static void Setup() => h = TestData.GetDefault(); + public static void Setup() => _h = TestData.GetDefault(); [GlobalSetup(Targets = [nameof(Aggregate)])] - public static void SetupIntraday() => i = TestData.GetIntraday(); + public static void SetupIntraday() => _i = TestData.GetIntraday(); [Benchmark] - public object ToSortedList() => h.ToSortedList(); + public object ToSortedList() => _h.ToSortedList(); [Benchmark] - public object ToSortedCollection() => h.ToSortedCollection(); + public object ToSortedCollection() => _h.ToSortedCollection(); [Benchmark] - public object ToListQuoteD() => h.ToQuoteD(); + public object ToListQuoteD() => _h.ToQuoteD(); [Benchmark] - public object ToReusableClose() => h.ToReusableList(CandlePart.Close); + public object ToReusableClose() => _h.ToReusableList(CandlePart.Close); [Benchmark] - public object ToReusableOHLC4() => h.ToReusableList(CandlePart.OHLC4); + public object ToReusableOhlc4() => _h.ToReusableList(CandlePart.Ohlc4); [Benchmark] - public object ToCandleResults() => h.ToCandleResults(); + public object ToCandleResults() => _h.ToCandleResults(); [Benchmark] - public object Validate() => h.Validate(); + public object Validate() => _h.Validate(); [Benchmark] - public object Aggregate() => i.Aggregate(PeriodSize.FifteenMinutes); + public object Aggregate() => _i.Aggregate(PeriodSize.FifteenMinutes); } diff --git a/tests/performance/Perf.Library.Internals.cs b/tests/performance/Perf.Library.Internals.cs index a36890b81..6951d662c 100644 --- a/tests/performance/Perf.Library.Internals.cs +++ b/tests/performance/Perf.Library.Internals.cs @@ -7,15 +7,15 @@ public class LibraryInternals [Params(20, 50, 250, 1000)] public int Periods; - private double[] values; + private double[] _values; // standard deviation [GlobalSetup(Targets = [nameof(StdDev)])] public void Setup() - => values = TestData.GetLongish(Periods) + => _values = TestData.GetLongish(Periods) .Select(x => (double)x.Close) .ToArray(); [Benchmark] - public object StdDev() => values.StdDev(); + public object StdDev() => _values.StdDev(); } diff --git a/tests/performance/_testdata/Helper.Importer.cs b/tests/performance/_testdata/Helper.Importer.cs index 0f115bfcc..bc253bbfb 100644 --- a/tests/performance/_testdata/Helper.Importer.cs +++ b/tests/performance/_testdata/Helper.Importer.cs @@ -12,7 +12,7 @@ internal static Quote QuoteFromCsv(string csvLine) { if (string.IsNullOrEmpty(csvLine)) { - return new Quote(); + return new(); } string[] csv = csvLine.Split(',');