Apply fixes from CodeFactor (#46)

This commit is contained in:
Miha Kralj
2024-11-03 15:59:24 -08:00
committed by GitHub
10 changed files with 8 additions and 17 deletions
+2 -2
View File
@@ -22,7 +22,7 @@ public class StatisticsUpdateTests
double open = GetRandomDouble();
double high = open + Math.Abs(GetRandomDouble());
double low = open - Math.Abs(GetRandomDouble());
double close = low + (high - low) * GetRandomDouble();
double close = low + ((high - low) * GetRandomDouble());
return new TBar(DateTime.Now, open, high, low, close, 1000, IsNew);
}
@@ -31,7 +31,7 @@ public class StatisticsUpdateTests
double open = GetRandomDouble();
double high = open + Math.Abs(GetRandomDouble());
double low = open - Math.Abs(GetRandomDouble());
double close = low + (high - low) * GetRandomDouble();
double close = low + ((high - low) * GetRandomDouble());
return new TBar(DateTime.Now, open, high, low, close, 1000, IsNew);
}
+1 -2
View File
@@ -46,7 +46,6 @@ namespace QuanTAlib;
///
/// Note: Returns a value between 0 and 1
/// </remarks>
[SkipLocalsInit]
public sealed class Hurst : AbstractBase
{
@@ -184,7 +183,7 @@ public sealed class Hurst : AbstractBase
double hurst = 0.5; // Default to random walk
if (numPoints > 1)
{
double slope = (numPoints * sumXY - sumX * sumY) / (numPoints * sumX2 - sumX * sumX);
double slope = ((numPoints * sumXY) - (sumX * sumY)) / ((numPoints * sumX2) - (sumX * sumX));
hurst = Math.Max(0, Math.Min(1, slope)); // Clamp between 0 and 1
}
-1
View File
@@ -41,7 +41,6 @@ namespace QuanTAlib;
///
/// Note: Returns three values: upper, middle, and lower bands
/// </remarks>
[SkipLocalsInit]
public sealed class Bband : AbstractBase
{
-1
View File
@@ -36,7 +36,6 @@ namespace QuanTAlib;
///
/// Note: Returns annualized volatility as a percentage
/// </remarks>
[SkipLocalsInit]
public sealed class Ccv : AbstractBase
{
-1
View File
@@ -38,7 +38,6 @@ namespace QuanTAlib;
///
/// Note: Returns two values: long exit and short exit levels
/// </remarks>
[SkipLocalsInit]
public sealed class Ce : AbstractBase
{
+1 -2
View File
@@ -43,7 +43,6 @@ namespace QuanTAlib;
///
/// Note: Returns annualized volatility as a percentage
/// </remarks>
[SkipLocalsInit]
public sealed class Cv : AbstractBase
{
@@ -126,7 +125,7 @@ public sealed class Cv : AbstractBase
}
// Update variance estimate using GARCH(1,1)
double variance = _omega + _alpha * squaredReturn + _beta * _prevVariance;
double variance = _omega + (_alpha * squaredReturn) + (_beta * _prevVariance);
_prevVariance = variance;
// Calculate annualized volatility as percentage
+1 -2
View File
@@ -41,7 +41,6 @@ namespace QuanTAlib;
///
/// Note: Returns annualized volatility as a percentage
/// </remarks>
[SkipLocalsInit]
public sealed class Ewma : AbstractBase
{
@@ -121,7 +120,7 @@ public sealed class Ewma : AbstractBase
}
// Update EWMA
_ewma = _lambda * _ewma + (1 - _lambda) * squaredReturn;
_ewma = (_lambda * _ewma) + ((1 - _lambda) * squaredReturn);
// Calculate volatility
double volatility = Math.Sqrt(_ewma);
+2 -3
View File
@@ -38,7 +38,6 @@ namespace QuanTAlib;
///
/// Note: Returns three values: upper, middle, and lower bands
/// </remarks>
[SkipLocalsInit]
public sealed class Fcb : AbstractBase
{
@@ -134,8 +133,8 @@ public sealed class Fcb : AbstractBase
}
// Apply smoothing to bands
_upperBand = _smoothing * _upperEma + (1 - _smoothing) * BarInput.High;
_lowerBand = _smoothing * _lowerEma + (1 - _smoothing) * BarInput.Low;
_upperBand = (_smoothing * _upperEma) + ((1 - _smoothing) * BarInput.High);
_lowerBand = (_smoothing * _lowerEma) + ((1 - _smoothing) * BarInput.Low);
_middleBand = (_upperBand + _lowerBand) / 2;
IsHot = _index >= WarmupPeriod;
+1 -2
View File
@@ -38,7 +38,6 @@ namespace QuanTAlib;
///
/// Note: Returns annualized volatility as a percentage
/// </remarks>
[SkipLocalsInit]
public sealed class Gkv : AbstractBase
{
@@ -97,7 +96,7 @@ public sealed class Gkv : AbstractBase
c = c * c;
// Combine components with optimal weights
double component = 0.5 * u - (2 * _ln2 - 1) * c;
double component = (0.5 * u) - (((2 * _ln2) - 1) * c);
_components.Add(component);
// Need enough values for calculation
-1
View File
@@ -37,7 +37,6 @@ namespace QuanTAlib;
///
/// Note: Returns annualized volatility as a percentage
/// </remarks>
[SkipLocalsInit]
public sealed class Hlv : AbstractBase
{