From 2b62aaad6c6efff5ebedd4bef52a64fc967c6c0b Mon Sep 17 00:00:00 2001 From: codefactor-io Date: Sun, 3 Nov 2024 23:59:03 +0000 Subject: [PATCH] [CodeFactor] Apply fixes --- Tests/test_updates_statistics.cs | 4 ++-- lib/statistics/Hurst.cs | 3 +-- lib/volatility/Bband.cs | 1 - lib/volatility/Ccv.cs | 1 - lib/volatility/Ce.cs | 1 - lib/volatility/Cv.cs | 3 +-- lib/volatility/Ewma.cs | 3 +-- lib/volatility/Fcb.cs | 5 ++--- lib/volatility/Gkv.cs | 3 +-- lib/volatility/Hlv.cs | 1 - 10 files changed, 8 insertions(+), 17 deletions(-) diff --git a/Tests/test_updates_statistics.cs b/Tests/test_updates_statistics.cs index a5d901fc..81394142 100644 --- a/Tests/test_updates_statistics.cs +++ b/Tests/test_updates_statistics.cs @@ -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); } diff --git a/lib/statistics/Hurst.cs b/lib/statistics/Hurst.cs index 4ec62254..4c2c9e2d 100644 --- a/lib/statistics/Hurst.cs +++ b/lib/statistics/Hurst.cs @@ -46,7 +46,6 @@ namespace QuanTAlib; /// /// Note: Returns a value between 0 and 1 /// - [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 } diff --git a/lib/volatility/Bband.cs b/lib/volatility/Bband.cs index a135b71b..19226928 100644 --- a/lib/volatility/Bband.cs +++ b/lib/volatility/Bband.cs @@ -41,7 +41,6 @@ namespace QuanTAlib; /// /// Note: Returns three values: upper, middle, and lower bands /// - [SkipLocalsInit] public sealed class Bband : AbstractBase { diff --git a/lib/volatility/Ccv.cs b/lib/volatility/Ccv.cs index cfe6e7ba..6514b7a4 100644 --- a/lib/volatility/Ccv.cs +++ b/lib/volatility/Ccv.cs @@ -36,7 +36,6 @@ namespace QuanTAlib; /// /// Note: Returns annualized volatility as a percentage /// - [SkipLocalsInit] public sealed class Ccv : AbstractBase { diff --git a/lib/volatility/Ce.cs b/lib/volatility/Ce.cs index 225c2c22..cdab9695 100644 --- a/lib/volatility/Ce.cs +++ b/lib/volatility/Ce.cs @@ -38,7 +38,6 @@ namespace QuanTAlib; /// /// Note: Returns two values: long exit and short exit levels /// - [SkipLocalsInit] public sealed class Ce : AbstractBase { diff --git a/lib/volatility/Cv.cs b/lib/volatility/Cv.cs index 77dd3fff..bc77b20b 100644 --- a/lib/volatility/Cv.cs +++ b/lib/volatility/Cv.cs @@ -43,7 +43,6 @@ namespace QuanTAlib; /// /// Note: Returns annualized volatility as a percentage /// - [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 diff --git a/lib/volatility/Ewma.cs b/lib/volatility/Ewma.cs index 52fb9443..672ebfb1 100644 --- a/lib/volatility/Ewma.cs +++ b/lib/volatility/Ewma.cs @@ -41,7 +41,6 @@ namespace QuanTAlib; /// /// Note: Returns annualized volatility as a percentage /// - [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); diff --git a/lib/volatility/Fcb.cs b/lib/volatility/Fcb.cs index 45c61aa9..60c926e1 100644 --- a/lib/volatility/Fcb.cs +++ b/lib/volatility/Fcb.cs @@ -38,7 +38,6 @@ namespace QuanTAlib; /// /// Note: Returns three values: upper, middle, and lower bands /// - [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; diff --git a/lib/volatility/Gkv.cs b/lib/volatility/Gkv.cs index 19baebdb..fd197d48 100644 --- a/lib/volatility/Gkv.cs +++ b/lib/volatility/Gkv.cs @@ -38,7 +38,6 @@ namespace QuanTAlib; /// /// Note: Returns annualized volatility as a percentage /// - [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 diff --git a/lib/volatility/Hlv.cs b/lib/volatility/Hlv.cs index 63a0b3ea..b1d60e36 100644 --- a/lib/volatility/Hlv.cs +++ b/lib/volatility/Hlv.cs @@ -37,7 +37,6 @@ namespace QuanTAlib; /// /// Note: Returns annualized volatility as a percentage /// - [SkipLocalsInit] public sealed class Hlv : AbstractBase {