sonar fixes

This commit is contained in:
Miha Kralj
2024-11-03 15:52:25 -08:00
parent f76b6dda2a
commit 94928714bf
19 changed files with 132 additions and 37 deletions
+3 -2
View File
@@ -61,6 +61,7 @@ jobs:
/d:sonar.exclusions="**/TestResults/**/*,**/bin/**/*,**/obj/**/*,**/*.html,**/coverage/**/*,**/CoverageReport/**/*,**/*.md,**/*.css,**/docs/**/*,**/archive/**/*,**/notebooks/**/*" `
/d:sonar.test.exclusions="**Tests.cs,**/obj/**/*,**/bin/**/*" `
/d:sonar.cpd.exclusions="**Tests.cs" `
/d:sonar.scanner.scanAll="false" `
/d:sonar.cs.roslyn.ignoreIssues="false" `
/d:sonar.issue.ignore.multicriteria="e1" `
/d:sonar.issue.ignore.multicriteria.e1.ruleKey="csharpsquid:S1944,csharpsquid:S2053,csharpsquid:S2222,csharpsquid:S2259,csharpsquid:S2583,csharpsquid:S2589,csharpsquid:S3329,csharpsquid:S3655,csharpsquid:S3900,csharpsquid:S3949,csharpsquid:S3966,csharpsquid:S4158,csharpsquid:S4347,csharpsquid:S5773,csharpsquid:S6781" `
@@ -102,7 +103,7 @@ jobs:
coverage-reports: '*cover*.xml'
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
files: 'cover*'
verbose: true
@@ -158,7 +159,7 @@ jobs:
fetch-depth: 0
- name: Setup NuGet
uses: nuget/setup-nuget@v1
uses: nuget/setup-nuget@v2
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v1
+48
View File
@@ -26,6 +26,22 @@ public class VolatilityUpdateTests
return new TBar(DateTime.Now, open, high, low, close, 1000, IsNew);
}
[Fact]
public void Adr_Update()
{
var indicator = new Adr(period: 14);
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);
for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));
Assert.Equal(initialValue, finalValue, precision);
}
[Fact]
public void Atr_Update()
{
@@ -42,6 +58,38 @@ public class VolatilityUpdateTests
Assert.Equal(initialValue, finalValue, precision);
}
[Fact]
public void Ap_Update()
{
var indicator = new Ap(period: 20);
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);
for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));
Assert.Equal(initialValue, finalValue, precision);
}
[Fact]
public void Atrp_Update()
{
var indicator = new Atrp(period: 14);
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);
for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));
Assert.Equal(initialValue, finalValue, precision);
}
[Fact]
public void Historical_Update()
{
+64
View File
@@ -319,4 +319,68 @@ public class VolumeUpdateTests
Assert.Equal(initialValue, finalValue, precision);
}
[Fact]
public void Vf_Update()
{
var indicator = new Vf(period: 13);
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);
for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));
Assert.Equal(initialValue, finalValue, precision);
}
[Fact]
public void Vp_Update()
{
var indicator = new Vp(period: 14);
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);
for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));
Assert.Equal(initialValue, finalValue, precision);
}
[Fact]
public void Vwap_Update()
{
var indicator = new Vwap();
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);
for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));
Assert.Equal(initialValue, finalValue, precision);
}
[Fact]
public void Vwma_Update()
{
var indicator = new Vwma(period: 20);
TBar r = GetRandomBar(true);
double initialValue = indicator.Calc(r);
for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(IsNew: false));
}
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false));
Assert.Equal(initialValue, finalValue, precision);
}
}
+1 -3
View File
@@ -18,7 +18,6 @@ namespace QuanTAlib;
/// </remarks>
public class Dema : AbstractBase
{
private readonly int _period;
private readonly double _k;
private readonly double _epsilon = 1e-10;
private double _lastEma1, _p_lastEma1;
@@ -31,8 +30,7 @@ public class Dema : AbstractBase
{
throw new ArgumentOutOfRangeException(nameof(period), "Period must be greater than or equal to 1.");
}
_period = period;
_k = 2.0 / (_period + 1);
_k = 2.0 / (period + 1);
Name = "Dema";
double percentile = 0.85; //targeting 85th percentile of correctness of converging EMA
WarmupPeriod = (int)System.Math.Ceiling(-period * System.Math.Log(1 - percentile));
-2
View File
@@ -21,7 +21,6 @@ namespace QuanTAlib;
/// </remarks>
public class Dsma : AbstractBase
{
private readonly int _period;
private readonly CircularBuffer _buffer;
private readonly double _c1, _c2, _c3;
private readonly double _scaleFactor;
@@ -49,7 +48,6 @@ public class Dsma : AbstractBase
{
throw new ArgumentOutOfRangeException(nameof(scaleFactor), "Scale factor must be between 0 and 1 (exclusive).");
}
_period = period;
_periodRecip = 1.0 / period;
_scaleFactor = scaleFactor;
_buffer = new CircularBuffer(period);
+1 -2
View File
@@ -26,7 +26,6 @@ public class Epma : AbstractBase
{
private readonly int _period;
private readonly Convolution _convolution;
private readonly double[] _baseKernel;
/// <param name="period">The number of data points used in the EPMA calculation.</param>
/// <exception cref="ArgumentException">Thrown when period is less than 1.</exception>
@@ -37,7 +36,7 @@ public class Epma : AbstractBase
throw new System.ArgumentException("Period must be greater than or equal to 1.", nameof(period));
}
_period = period;
_baseKernel = GenerateKernel(_period);
double[] _baseKernel = GenerateKernel(_period);
_convolution = new Convolution(_baseKernel);
Name = "Epma";
WarmupPeriod = period;
+1 -2
View File
@@ -26,7 +26,6 @@ namespace QuanTAlib;
public class Fwma : AbstractBase
{
private readonly Convolution _convolution;
private readonly double[] _kernel;
/// <param name="period">The number of data points used in the FWMA calculation.</param>
/// <exception cref="ArgumentException">Thrown when period is less than 1.</exception>
@@ -36,7 +35,7 @@ public class Fwma : AbstractBase
{
throw new System.ArgumentException("Period must be greater than or equal to 1.", nameof(period));
}
_kernel = GenerateKernel(period);
double[] _kernel = GenerateKernel(period);
_convolution = new Convolution(_kernel);
Name = "Fwma";
WarmupPeriod = period;
+1 -2
View File
@@ -26,7 +26,6 @@ namespace QuanTAlib;
public class Gma : AbstractBase
{
private readonly Convolution _convolution;
private readonly double[] _kernel;
/// <param name="period">The number of data points used in the GMA calculation.</param>
/// <exception cref="ArgumentException">Thrown when period is less than 1.</exception>
@@ -36,7 +35,7 @@ public class Gma : AbstractBase
{
throw new System.ArgumentException("Period must be greater than or equal to 1.", nameof(period));
}
_kernel = GenerateKernel(period);
double[] _kernel = GenerateKernel(period);
_convolution = new Convolution(_kernel);
Name = "Gma";
WarmupPeriod = period;
+4 -10
View File
@@ -28,11 +28,6 @@ namespace QuanTAlib;
public class Hma : AbstractBase
{
private readonly Convolution _wmaHalf, _wmaFull, _wmaFinal;
private readonly int _period;
private readonly int _sqrtPeriod;
private readonly double[] _kernelHalf;
private readonly double[] _kernelFull;
private readonly double[] _kernelFinal;
/// <param name="period">The number of data points used in the HMA calculation. Must be at least 2.</param>
/// <exception cref="ArgumentException">Thrown when period is less than 2.</exception>
@@ -42,13 +37,12 @@ public class Hma : AbstractBase
{
throw new System.ArgumentException("Period must be greater than or equal to 2.", nameof(period));
}
_period = period;
_sqrtPeriod = (int)System.Math.Sqrt(period);
int _sqrtPeriod = (int)System.Math.Sqrt(period);
// Generate all kernels once
_kernelHalf = GenerateWmaKernel(period / 2);
_kernelFull = GenerateWmaKernel(period);
_kernelFinal = GenerateWmaKernel(_sqrtPeriod);
double[] _kernelHalf = GenerateWmaKernel(period / 2);
double[] _kernelFull = GenerateWmaKernel(period);
double[] _kernelFinal = GenerateWmaKernel(_sqrtPeriod);
// Initialize convolutions with pre-generated kernels
_wmaHalf = new Convolution(_kernelHalf);
+1 -2
View File
@@ -28,7 +28,6 @@ namespace QuanTAlib;
public class Sinema : AbstractBase
{
private readonly Convolution _convolution;
private readonly double[] _kernel;
/// <param name="period">The number of data points used in the SINEMA calculation.</param>
/// <exception cref="ArgumentException">Thrown when period is less than 1.</exception>
@@ -38,7 +37,7 @@ public class Sinema : AbstractBase
{
throw new System.ArgumentException("Period must be greater than or equal to 1.", nameof(period));
}
_kernel = GenerateKernel(period);
double[] _kernel = GenerateKernel(period);
_convolution = new Convolution(_kernel);
Name = "Sinema";
WarmupPeriod = period;
-2
View File
@@ -27,7 +27,6 @@ namespace QuanTAlib;
public class Sma : AbstractBase
{
private readonly CircularBuffer _buffer;
private readonly int _period;
/// <param name="period">The number of data points used in the SMA calculation.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown when period is less than 1.</exception>
@@ -37,7 +36,6 @@ public class Sma : AbstractBase
{
throw new System.ArgumentOutOfRangeException(nameof(period), "Period must be greater than or equal to 1.");
}
_period = period;
_buffer = new CircularBuffer(period);
Name = "Sma";
WarmupPeriod = period;
+1 -3
View File
@@ -28,7 +28,6 @@ namespace QuanTAlib;
public class T3 : AbstractBase
{
private readonly int _period;
private readonly double _vfactor;
private readonly bool _useSma;
private readonly double _k;
private readonly double _c1, _c2, _c3, _c4;
@@ -48,7 +47,6 @@ public class T3 : AbstractBase
throw new System.ArgumentException("Period must be greater than or equal to 1.", nameof(period));
}
_period = period;
_vfactor = vfactor;
_useSma = useSma;
WarmupPeriod = period;
@@ -69,7 +67,7 @@ public class T3 : AbstractBase
_buffer5 = new(period);
_buffer6 = new(period);
Name = $"T3({_period}, {_vfactor})";
Name = $"T3({_period}, {vfactor})";
Init();
}
+1 -1
View File
@@ -12,7 +12,7 @@
<PackageReadmeFile>readme.md</PackageReadmeFile>
<RootNamespace>QuanTAlib</RootNamespace>
<AssemblyName>QuanTAlib</AssemblyName>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
<AssemblyVersion>0.0.0.1</AssemblyVersion>
<IsPublishable>True</IsPublishable>
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>full</DebugType>
+1 -1
View File
@@ -2,7 +2,7 @@
<PropertyGroup>
<AssemblyName>Averages</AssemblyName>
<AlgoType>Indicator</AlgoType>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
<AssemblyVersion>0.0.0.1</AssemblyVersion>
<OutputPath>bin\$(Configuration)\</OutputPath>
<IsLocalBuild Condition="'$(GITHUB_ACTIONS)' == ''">true</IsLocalBuild>
<UpdateAssemblyInfo>true</UpdateAssemblyInfo>
+1 -1
View File
@@ -2,7 +2,7 @@
<PropertyGroup>
<AssemblyName>Momentum</AssemblyName>
<AlgoType>Indicator</AlgoType>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
<AssemblyVersion>0.0.0.1</AssemblyVersion>
<OutputPath>bin\$(Configuration)\</OutputPath>
<IsLocalBuild Condition="'$(GITHUB_ACTIONS)' == ''">true</IsLocalBuild>
<UpdateAssemblyInfo>true</UpdateAssemblyInfo>
+1 -1
View File
@@ -2,7 +2,7 @@
<PropertyGroup>
<AssemblyName>Oscillators</AssemblyName>
<AlgoType>Indicator</AlgoType>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
<AssemblyVersion>0.0.0.1</AssemblyVersion>
<OutputPath>bin\$(Configuration)\</OutputPath>
<IsLocalBuild Condition="'$(GITHUB_ACTIONS)' == ''">true</IsLocalBuild>
<UpdateAssemblyInfo>true</UpdateAssemblyInfo>
+1 -1
View File
@@ -2,7 +2,7 @@
<PropertyGroup>
<AssemblyName>Statistics</AssemblyName>
<AlgoType>Indicator</AlgoType>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
<AssemblyVersion>0.0.0.1</AssemblyVersion>
<OutputPath>bin\$(Configuration)\</OutputPath>
<IsLocalBuild Condition="'$(GITHUB_ACTIONS)' == ''">true</IsLocalBuild>
<UpdateAssemblyInfo>true</UpdateAssemblyInfo>
+1 -1
View File
@@ -2,7 +2,7 @@
<PropertyGroup>
<AssemblyName>Volatility</AssemblyName>
<AlgoType>Indicator</AlgoType>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
<AssemblyVersion>0.0.0.1</AssemblyVersion>
<OutputPath>bin\$(Configuration)\</OutputPath>
<IsLocalBuild Condition="'$(GITHUB_ACTIONS)' == ''">true</IsLocalBuild>
<UpdateAssemblyInfo>true</UpdateAssemblyInfo>
+1 -1
View File
@@ -2,7 +2,7 @@
<PropertyGroup>
<AssemblyName>Volume</AssemblyName>
<AlgoType>Indicator</AlgoType>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
<AssemblyVersion>0.0.0.1</AssemblyVersion>
<OutputPath>bin\$(Configuration)\</OutputPath>
<IsLocalBuild Condition="'$(GITHUB_ACTIONS)' == ''">true</IsLocalBuild>
<UpdateAssemblyInfo>true</UpdateAssemblyInfo>