From 697fa19cfa78638f17f553c85bfebe6703d4a0ad Mon Sep 17 00:00:00 2001 From: Miha Kralj Date: Mon, 30 Sep 2024 15:53:48 -0700 Subject: [PATCH] Sonarcloud fixes --- Tests/test_Trady.cs | 8 ++++---- Tests/test_Tulip.cs | 15 ++++++++------- Tests/test_iTBar.cs | 2 +- Tests/test_iTValue.cs | 2 +- Tests/test_skender.stock.cs | 2 +- Tests/test_talib.cs | 13 +++++++------ lib/statistics/Entropy.cs | 2 +- lib/statistics/Kurtosis.cs | 2 +- lib/statistics/Max.cs | 2 +- lib/statistics/Median.cs | 2 +- lib/statistics/Min.cs | 2 +- lib/statistics/Mode.cs | 2 +- lib/statistics/Percentile.cs | 4 ++-- lib/statistics/Skew.cs | 2 +- lib/statistics/Stddev.cs | 4 ++-- lib/statistics/Variance.cs | 4 ++-- lib/statistics/Zscore.cs | 2 +- 17 files changed, 36 insertions(+), 34 deletions(-) diff --git a/Tests/test_Trady.cs b/Tests/test_Trady.cs index 8037b8e3..ef8066b1 100644 --- a/Tests/test_Trady.cs +++ b/Tests/test_Trady.cs @@ -8,11 +8,11 @@ public class TradyTests { private readonly TBarSeries bars; private readonly GbmFeed feed; - private Random rnd; + private readonly Random rnd; private readonly double range; - private int period, iterations; - private int skip; - private IEnumerable Candles; + private readonly int period, iterations; + private readonly int skip; + private readonly IEnumerable Candles; public TradyTests() { diff --git a/Tests/test_Tulip.cs b/Tests/test_Tulip.cs index 159902ae..b56476db 100644 --- a/Tests/test_Tulip.cs +++ b/Tests/test_Tulip.cs @@ -6,12 +6,13 @@ public class TulipTests { private readonly TBarSeries bars; private readonly GbmFeed feed; - private Random rnd; + private readonly Random rnd; private readonly double range; - private int period, iterations; + private int period; + private int readonly iterations; private readonly double[] data; private readonly double[] outdata; - private int skip; + private readonly int skip; public TulipTests() { @@ -44,7 +45,7 @@ public class TulipTests for (int i = QL.Length - 1; i > skip; i--) { double QL_item = QL[i].Value; - double TU = i skip*2; i--) //Initial Tulip Ema value is (wrongly) set to the first input value - therefore large skip + for (int i = QL.Length - 1; i > skip * 2; i--) //Initial Tulip Ema value is (wrongly) set to the first input value - therefore large skip { double QL_item = QL[i].Value; double TU = arrout[0][i]; - Assert.True(Math.Abs(TU - QL_item) <= range, $"Assertion failed at index {i} for period {period}: TU = {TU}, QL_item = {QL_item}, delta = {TU-QL_item}"); + Assert.True(Math.Abs(TU - QL_item) <= range, $"Assertion failed at index {i} for period {period}: TU = {TU}, QL_item = {QL_item}, delta = {TU - QL_item}"); } } diff --git a/Tests/test_iTBar.cs b/Tests/test_iTBar.cs index 4f21c69a..db5d70ae 100644 --- a/Tests/test_iTBar.cs +++ b/Tests/test_iTBar.cs @@ -5,7 +5,7 @@ namespace QuanTAlib { public class BarIndicatorTests { - private Random rnd; + private readonly Random rnd; private const int SeriesLen = 1000; private const int Corrections = 100; diff --git a/Tests/test_iTValue.cs b/Tests/test_iTValue.cs index 6504695f..e1b33a98 100644 --- a/Tests/test_iTValue.cs +++ b/Tests/test_iTValue.cs @@ -5,7 +5,7 @@ namespace QuanTAlib { public class IndicatorTests { - private Random rnd; + private readonly Random rnd; private const int SeriesLen = 1000; private const int Corrections = 100; diff --git a/Tests/test_skender.stock.cs b/Tests/test_skender.stock.cs index e652c773..69e90ce5 100644 --- a/Tests/test_skender.stock.cs +++ b/Tests/test_skender.stock.cs @@ -6,7 +6,7 @@ public class SkenderTests { private readonly TBarSeries bars; private readonly GbmFeed feed; - private Random rnd; + private readonly Random rnd; private readonly double range; private int period, iterations; private readonly IEnumerable quotes; diff --git a/Tests/test_talib.cs b/Tests/test_talib.cs index 3d57d44a..d56e2ec1 100644 --- a/Tests/test_talib.cs +++ b/Tests/test_talib.cs @@ -6,9 +6,10 @@ public class TAlibTests { private readonly TBarSeries bars; private readonly GbmFeed feed; - private Random rnd; + private readonly Random rnd; private readonly double range; - private int period, iterations; + private int period; + private int readonly iterations; private readonly double[] data; private readonly double[] TALIB; @@ -78,7 +79,7 @@ public class TAlibTests { QL.Add(ma.Calc(new TValue(item.Time, item.Close))); } Core.Dema(data, 0, QL.Length - 1, TALIB, out int outBegIdx, out _, period); Assert.Equal(QL.Length, TALIB.Length); - for (int i = QL.Length - 1; i > period*20; i--) + for (int i = QL.Length - 1; i > period * 20; i--) { double TL = i < outBegIdx ? double.NaN : TALIB[i - outBegIdx]; Assert.InRange(TALIB[i - outBegIdx] - QL[i].Value, -range, range); @@ -98,7 +99,7 @@ public class TAlibTests { QL.Add(ma.Calc(new TValue(item.Time, item.Close))); } Core.Tema(data, 0, QL.Length - 1, TALIB, out int outBegIdx, out _, period); Assert.Equal(QL.Length, TALIB.Length); - for (int i = QL.Length - 1; i > period*20; i--) + for (int i = QL.Length - 1; i > period * 20; i--) { double TL = i < outBegIdx ? double.NaN : TALIB[i - outBegIdx]; Assert.InRange(TALIB[i - outBegIdx] - QL[i].Value, -range, range); @@ -116,9 +117,9 @@ public class TAlibTests TSeries QL = new(); foreach (TBar item in feed) { QL.Add(ma.Calc(new TValue(item.Time, item.Close))); } - Core.T3(data, 0, QL.Length - 1, TALIB, out int outBegIdx, out _, optInTimePeriod: period, optInVFactor: 0.7); + Core.T3(data, 0, QL.Length - 1, TALIB, out int outBegIdx, out _, optInTimePeriod: period, optInVFactor: 0.7); Assert.Equal(QL.Length, TALIB.Length); - for (int i = QL.Length - 1; i > period*20; i--) + for (int i = QL.Length - 1; i > period * 20; i--) { double TL = i < outBegIdx ? double.NaN : TALIB[i - outBegIdx]; Assert.InRange(TALIB[i - outBegIdx] - QL[i].Value, -range, range); diff --git a/lib/statistics/Entropy.cs b/lib/statistics/Entropy.cs index d1f2348b..63562191 100644 --- a/lib/statistics/Entropy.cs +++ b/lib/statistics/Entropy.cs @@ -6,7 +6,7 @@ using System.Linq; // Shannon's Entropy calculation public class Entropy : AbstractBase { - public readonly int Period; + private readonly int Period; private readonly CircularBuffer _buffer; public Entropy(int period) diff --git a/lib/statistics/Kurtosis.cs b/lib/statistics/Kurtosis.cs index 3b60f8ba..efb8afef 100644 --- a/lib/statistics/Kurtosis.cs +++ b/lib/statistics/Kurtosis.cs @@ -3,7 +3,7 @@ namespace QuanTAlib; // Excess kurtosis calculated with Sheskin Algorithm public class Kurtosis : AbstractBase { - public readonly int Period; + private readonly int Period; private readonly CircularBuffer _buffer; public Kurtosis(int period) diff --git a/lib/statistics/Max.cs b/lib/statistics/Max.cs index 1257f63d..a883f1d1 100644 --- a/lib/statistics/Max.cs +++ b/lib/statistics/Max.cs @@ -4,7 +4,7 @@ namespace QuanTAlib { public class Max : AbstractBase { - public readonly int Period; + private readonly int Period; private readonly CircularBuffer _buffer; private readonly double _halfLife; private double _currentMax, _p_currentMax; diff --git a/lib/statistics/Median.cs b/lib/statistics/Median.cs index 1adc8077..85174e3b 100644 --- a/lib/statistics/Median.cs +++ b/lib/statistics/Median.cs @@ -5,7 +5,7 @@ namespace QuanTAlib { public class Median : AbstractBase { - public readonly int Period; + private readonly int Period; private readonly CircularBuffer _buffer; public Median(int period) diff --git a/lib/statistics/Min.cs b/lib/statistics/Min.cs index 03e0e14f..f0b756b2 100644 --- a/lib/statistics/Min.cs +++ b/lib/statistics/Min.cs @@ -4,7 +4,7 @@ namespace QuanTAlib { public class Min : AbstractBase { - public readonly int Period; + private readonly int Period; private readonly CircularBuffer _buffer; private readonly double _halfLife; private double _currentMin, _p_currentMin; diff --git a/lib/statistics/Mode.cs b/lib/statistics/Mode.cs index 6acf96b3..0ef93927 100644 --- a/lib/statistics/Mode.cs +++ b/lib/statistics/Mode.cs @@ -2,7 +2,7 @@ namespace QuanTAlib; public class Mode : AbstractBase { - public readonly int Period; + private readonly int Period; private readonly CircularBuffer _buffer; public Mode(int period) diff --git a/lib/statistics/Percentile.cs b/lib/statistics/Percentile.cs index 244bbbc4..605ecb41 100644 --- a/lib/statistics/Percentile.cs +++ b/lib/statistics/Percentile.cs @@ -5,8 +5,8 @@ using System.Linq; public class Percentile : AbstractBase { - public readonly int Period; - public readonly double Percent; + private readonly int Period; + private readonly double Percent; private readonly CircularBuffer _buffer; public Percentile(int period, double percent) diff --git a/lib/statistics/Skew.cs b/lib/statistics/Skew.cs index 6101ae0d..546904be 100644 --- a/lib/statistics/Skew.cs +++ b/lib/statistics/Skew.cs @@ -5,7 +5,7 @@ using System.Linq; public class Skew : AbstractBase { - public readonly int Period; + private readonly int Period; private readonly CircularBuffer _buffer; public Skew(int period) diff --git a/lib/statistics/Stddev.cs b/lib/statistics/Stddev.cs index c0463368..9d41dd2c 100644 --- a/lib/statistics/Stddev.cs +++ b/lib/statistics/Stddev.cs @@ -5,8 +5,8 @@ namespace QuanTAlib { public class Stddev : AbstractBase { - public readonly int Period; - public readonly bool IsPopulation; + private readonly int Period; + private readonly bool IsPopulation; private readonly CircularBuffer _buffer; public Stddev(int period, bool isPopulation = false) diff --git a/lib/statistics/Variance.cs b/lib/statistics/Variance.cs index 18f71a9f..95ab8ae1 100644 --- a/lib/statistics/Variance.cs +++ b/lib/statistics/Variance.cs @@ -5,8 +5,8 @@ namespace QuanTAlib { public class Variance : AbstractBase { - public readonly int Period; - public readonly bool IsPopulation; + private readonly int Period; + private readonly bool IsPopulation; private readonly CircularBuffer _buffer; public Variance(int period, bool isPopulation = false) diff --git a/lib/statistics/Zscore.cs b/lib/statistics/Zscore.cs index 74d696f3..27734156 100644 --- a/lib/statistics/Zscore.cs +++ b/lib/statistics/Zscore.cs @@ -5,7 +5,7 @@ using System.Linq; public class Zscore : AbstractBase { - public readonly int Period; + private readonly int Period; private readonly CircularBuffer _buffer; public Zscore(int period)