Sonarcloud fixes

This commit is contained in:
Miha Kralj
2024-09-30 15:53:48 -07:00
parent ad3aa37978
commit 697fa19cfa
17 changed files with 36 additions and 34 deletions
+4 -4
View File
@@ -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<IOhlcv> Candles;
private readonly int period, iterations;
private readonly int skip;
private readonly IEnumerable<IOhlcv> Candles;
public TradyTests()
{
+8 -7
View File
@@ -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<period-1?double.NaN:arrout[0][i-period+1];
double TU = i < period - 1 ? double.NaN : arrout[0][i - period + 1];
Assert.InRange(TU - QL_item, -range, range);
}
}
@@ -60,18 +61,18 @@ public class TulipTests
Ema ma = new(period, useSma: false);
TSeries QL = new();
foreach (TBar item in feed)
{ QL.Add(ma.Calc(new TValue(item.Time, item.Close))); }
{ QL.Add(ma.Calc(new TValue(item.Time, item.Close))); }
double[][] arrin = [data];
double[][] arrout = [outdata];
Tulip.Indicators.ema.Run(inputs: arrin, options: [period], outputs: arrout);
Assert.Equal(QL.Length, arrout[0].Length);
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
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}");
}
}
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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<Quote> quotes;
+7 -6
View File
@@ -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);
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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)
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -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)
+2 -2
View File
@@ -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)
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -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)