[CodeFactor] Apply fixes to commit 0606491

This commit is contained in:
codefactor-io
2026-03-12 19:37:50 +00:00
parent 060649192f
commit 8f79257155
384 changed files with 1197 additions and 1215 deletions
+1 -1
View File
@@ -318,7 +318,7 @@ public class AcfTests
// Generate and store values
for (int i = 0; i < 20; i++)
{
inputs.Add(new TValue(DateTime.UtcNow.AddSeconds(i), 100 + i * 0.5));
inputs.Add(new TValue(DateTime.UtcNow.AddSeconds(i), 100 + (i * 0.5)));
}
// First pass
@@ -226,7 +226,7 @@ public class AcfValidationTests
for (int i = 1; i < n; i++)
{
double epsilon = Math.Log(bars[i].Close / bars[i - 1].Close) * 0.5; // incremental log-return scaled as noise
ar1Data[i] = phi * ar1Data[i - 1] + epsilon;
ar1Data[i] = (phi * ar1Data[i - 1]) + epsilon;
}
// Compute ACF at different lags
+1 -1
View File
@@ -153,7 +153,7 @@ public class BetaTests
var beta = new Beta(5);
for (int i = 0; i < 10; i++)
{
beta.Update(100 + i * 2, 100 + i); // Different ratios
beta.Update(100 + (i * 2), 100 + i); // Different ratios
}
Assert.True(beta.IsHot);
@@ -42,7 +42,7 @@ public sealed class BetaValidationTests : IDisposable
var noiseBar = noiseGbm.Next();
double noise = (noiseBar.Close - noiseBar.Open) / noiseBar.Open;
double assetReturn = targetBeta * marketReturn + noise;
double assetReturn = (targetBeta * marketReturn) + noise;
assetPrice *= (1 + assetReturn);
assetQuotes.Add(new TBar(marketQuotes[i].Time, assetPrice, assetPrice, assetPrice, assetPrice, 1000));
@@ -117,7 +117,7 @@ public sealed class BetaValidationTests : IDisposable
double mktReturn = (marketQuotes[i].Value - marketQuotes[i - 1].Value) / marketQuotes[i - 1].Value;
var noiseBar = noiseGbm.Next();
double noise = (noiseBar.Close - noiseBar.Open) / noiseBar.Open;
double astReturn = targetBeta * mktReturn + noise * 0.1;
double astReturn = (targetBeta * mktReturn) + (noise * 0.1);
assetPrice *= (1 + astReturn);
assetPrices[i] = assetPrice;
marketPrices[i] = marketQuotes[i].Value;
@@ -342,7 +342,7 @@ public class CointegrationTests
for (int i = 0; i < 10; i++)
{
indicator.Update(100.0 + i, 100.0 + i * 0.5);
indicator.Update(100.0 + i, 100.0 + (i * 0.5));
}
_ = indicator.Last.Value; // beforeNaN - verify state before NaN
@@ -362,7 +362,7 @@ public class CointegrationTests
for (int i = 0; i < 10; i++)
{
indicator.Update(100.0 + i, 100.0 + i * 0.5);
indicator.Update(100.0 + i, 100.0 + (i * 0.5));
}
// Update with infinity
@@ -380,7 +380,7 @@ public class CointegrationTests
for (int i = 0; i < 20; i++)
{
double a = i % 5 == 0 ? double.NaN : 100.0 + i;
double b = i % 7 == 0 ? double.NaN : 100.0 + i * 0.5;
double b = i % 7 == 0 ? double.NaN : 100.0 + (i * 0.5);
indicator.Update(a, b);
}
@@ -592,8 +592,8 @@ public class CointegrationTests
for (int i = 0; i < 100; i++)
{
double a = 100.0 + i * 0.1;
double b = a + Math.Log(random.Next().Close / 100.0) * 0.1; // Highly correlated
double a = 100.0 + (i * 0.1);
double b = a + (Math.Log(random.Next().Close / 100.0) * 0.1); // Highly correlated
indicator.Update(a, b);
}
@@ -616,9 +616,9 @@ public class CointegrationTests
for (int i = 0; i < 100; i++)
{
// Cointegrated pair
double a1 = 100.0 + i * 0.1;
double a1 = 100.0 + (i * 0.1);
double noise1 = Math.Log(random.Next().Close / 100.0);
double b1 = a1 + noise1 * 0.1;
double b1 = a1 + (noise1 * 0.1);
indicatorCointegrated.Update(a1, b1);
// Random walks
@@ -29,8 +29,8 @@ public class CointegrationValidationTests
{
// Incremental log-return: truly i.i.d. noise, variance ~(0.2²·dt)
double noise = Math.Log(bars[i].Close / bars[i - 1].Close);
double a = 100.0 + i * 0.5 + noise * 0.1;
double b = 2.0 * a + 10.0 + noise * 0.1;
double a = 100.0 + (i * 0.5) + (noise * 0.1);
double b = (2.0 * a) + 10.0 + (noise * 0.1);
indicator.Update(a, b);
}
@@ -49,7 +49,7 @@ public class CointegrationValidationTests
for (int i = 0; i < 100; i++)
{
double value = 100.0 + Math.Sin(i * 0.1) * 10.0;
double value = 100.0 + (Math.Sin(i * 0.1) * 10.0);
indicator.Update(value, value);
}
@@ -68,9 +68,9 @@ public class CointegrationValidationTests
for (int i = 0; i < 100; i++)
{
double a = 50.0 + i * 0.3 + Math.Sin(i * 0.2) * 5.0;
double a = 50.0 + (i * 0.3) + (Math.Sin(i * 0.2) * 5.0);
double noise = GbmNoise(random) * 0.5;
double b = 1.5 * a + noise;
double b = (1.5 * a) + noise;
indicator.Update(a, b);
}
@@ -87,9 +87,9 @@ public class CointegrationValidationTests
for (int i = 0; i < 100; i++)
{
double a = 100.0 + i * 0.2;
double a = 100.0 + (i * 0.2);
double noise = GbmNoise(random) * 0.5; // Small noise
double b = 25.0 + 0.8 * a + noise;
double b = 25.0 + (0.8 * a) + noise;
indicator.Update(a, b);
}
@@ -105,8 +105,8 @@ public class CointegrationValidationTests
for (int i = 0; i < 100; i++)
{
double a = 100.0 + i * 0.3;
double b = 50.0 + 0.5 * a + Math.Sin(i * 0.1);
double a = 100.0 + (i * 0.3);
double b = 50.0 + (0.5 * a) + Math.Sin(i * 0.1);
indicator10.Update(a, b);
indicator30.Update(a, b);
}
@@ -128,8 +128,8 @@ public class CointegrationValidationTests
for (int i = 0; i < 50; i++)
{
double a = 100.0 + i * 0.2 + Math.Sin(i * 0.1) * 3.0;
double b = 30.0 + 0.7 * a + Math.Cos(i * 0.15) * 2.0;
double a = 100.0 + (i * 0.2) + (Math.Sin(i * 0.1) * 3.0);
double b = 30.0 + (0.7 * a) + (Math.Cos(i * 0.15) * 2.0);
seriesA.Add(baseTime.AddMinutes(i), a);
seriesB.Add(baseTime.AddMinutes(i), b);
}
@@ -165,8 +165,8 @@ public class CointegrationValidationTests
for (int i = 0; i < length; i++)
{
seriesA[i] = 100.0 + i * 0.2 + Math.Sin(i * 0.1) * 3.0;
seriesB[i] = 30.0 + 0.7 * seriesA[i] + Math.Cos(i * 0.15) * 2.0;
seriesA[i] = 100.0 + (i * 0.2) + (Math.Sin(i * 0.1) * 3.0);
seriesB[i] = 30.0 + (0.7 * seriesA[i]) + (Math.Cos(i * 0.15) * 2.0);
}
// Span calculation
@@ -198,8 +198,8 @@ public class CointegrationValidationTests
// First run
for (int i = 0; i < 50; i++)
{
double a = 100.0 + i * 0.3;
double b = 50.0 + 0.5 * a;
double a = 100.0 + (i * 0.3);
double b = 50.0 + (0.5 * a);
indicator.Update(a, b);
}
var firstResult = indicator.Last.Value;
@@ -209,8 +209,8 @@ public class CointegrationValidationTests
// Second run with same data
for (int i = 0; i < 50; i++)
{
double a = 100.0 + i * 0.3;
double b = 50.0 + 0.5 * a;
double a = 100.0 + (i * 0.3);
double b = 50.0 + (0.5 * a);
indicator.Update(a, b);
}
var secondResult = indicator.Last.Value;
@@ -259,8 +259,8 @@ public class CointegrationValidationTests
for (int i = 0; i < 20; i++)
{
double a = 100.0 + i + GbmNoise(random) * 0.1;
double b = 50.0 + 0.5 * a + GbmNoise(random) * 0.1;
double a = 100.0 + i + (GbmNoise(random) * 0.1);
double b = 50.0 + (0.5 * a) + (GbmNoise(random) * 0.1);
indicator.Update(a, b);
}
@@ -277,8 +277,8 @@ public class CointegrationValidationTests
for (int i = 0; i < 150; i++)
{
double a = 100.0 + i * 0.1 + GbmNoise(random) * 0.1;
double b = 30.0 + 0.8 * a + GbmNoise(random) * 0.1;
double a = 100.0 + (i * 0.1) + (GbmNoise(random) * 0.1);
double b = 30.0 + (0.8 * a) + (GbmNoise(random) * 0.1);
indicator.Update(a, b);
}
@@ -298,8 +298,8 @@ public class CointegrationValidationTests
for (int i = 0; i < 50; i++)
{
double a = 1e8 + i * 1e5;
double b = 2e8 + 2.0 * a;
double a = 1e8 + (i * 1e5);
double b = 2e8 + (2.0 * a);
indicator.Update(a, b);
}
@@ -313,8 +313,8 @@ public class CointegrationValidationTests
for (int i = 0; i < 50; i++)
{
double a = 1e-6 + i * 1e-8;
double b = 2e-6 + 1.5 * a;
double a = 1e-6 + (i * 1e-8);
double b = 2e-6 + (1.5 * a);
indicator.Update(a, b);
}
@@ -329,7 +329,7 @@ public class CointegrationValidationTests
for (int i = 0; i < 50; i++)
{
double a = 1000.0 + i;
double b = 0.001 + 0.000001 * a; // Much smaller scale
double b = 0.001 + (0.000001 * a); // Much smaller scale
indicator.Update(a, b);
}
@@ -211,8 +211,8 @@ public sealed class CorrelationValidationTests : IDisposable
for (int i = 0; i < 50; i++)
{
double x = 10.0 + i * 2.5;
double y = 5.0 + 3.0 * x; // y = 5 + 3x
double x = 10.0 + (i * 2.5);
double y = 5.0 + (3.0 * x); // y = 5 + 3x
indicator.Update(x, y);
}
@@ -227,8 +227,8 @@ public sealed class CorrelationValidationTests : IDisposable
for (int i = 0; i < 50; i++)
{
double x = 10.0 + i * 2.5;
double y = 100.0 - 2.0 * x; // y = 100 - 2x
double x = 10.0 + (i * 2.5);
double y = 100.0 - (2.0 * x); // y = 100 - 2x
indicator.Update(x, y);
}
@@ -272,7 +272,7 @@ public sealed class CorrelationValidationTests : IDisposable
double x = gbmX.Next().Close;
double y = gbmY.Next().Close;
indicator1.Update(x, y);
indicator2.Update(a * x + b, c * y + d);
indicator2.Update((a * x) + b, (c * y) + d);
}
// Relax tolerance due to floating point precision with large transformations
@@ -526,8 +526,8 @@ public sealed class CorrelationValidationTests : IDisposable
for (int i = 0; i < 50; i++)
{
double x = 1e8 + i * 1e5;
double y = 2e8 + 2.0 * (i * 1e5); // Linear relationship
double x = 1e8 + (i * 1e5);
double y = 2e8 + (2.0 * (i * 1e5)); // Linear relationship
indicator.Update(x, y);
}
@@ -543,8 +543,8 @@ public sealed class CorrelationValidationTests : IDisposable
// Use values that are small but not so small they cause numerical issues
for (int i = 0; i < 50; i++)
{
double x = 0.001 + i * 0.0001;
double y = 0.002 + 1.5 * (i * 0.0001); // Linear relationship
double x = 0.001 + (i * 0.0001);
double y = 0.002 + (1.5 * (i * 0.0001)); // Linear relationship
indicator.Update(x, y);
}
@@ -581,8 +581,8 @@ public sealed class CorrelationValidationTests : IDisposable
// Use deterministic data that creates high correlation
for (int i = 0; i < 100; i++)
{
double x = 100.0 + i + (i % 3) * 0.1; // Small variation
double y = 0.9 * x + (i % 5) * 0.2; // High correlation with small noise
double x = 100.0 + i + ((i % 3) * 0.1); // Small variation
double y = (0.9 * x) + ((i % 5) * 0.2); // High correlation with small noise
indicator.Update(x, y);
}
@@ -598,8 +598,8 @@ public sealed class CorrelationValidationTests : IDisposable
for (int i = 0; i < 100; i++)
{
double x = 100.0 + i + Math.Log(random.Next().Close / 100.0) * 2;
double y = 200.0 - 0.8 * i + Math.Log(random.Next().Close / 100.0) * 2; // Negative relationship
double x = 100.0 + i + (Math.Log(random.Next().Close / 100.0) * 2);
double y = 200.0 - (0.8 * i) + (Math.Log(random.Next().Close / 100.0) * 2); // Negative relationship
indicator.Update(x, y);
}
@@ -294,7 +294,7 @@ public class CovarianceTests
{
var bar = gbm.Next();
x[i] = bar.Close;
y[i] = bar.Close * 1.5 + 10; // Correlated series
y[i] = (bar.Close * 1.5) + 10; // Correlated series
}
// Streaming
@@ -154,7 +154,7 @@ public sealed class EntropyValidationTests
for (int i = 0; i < 20; i++)
{
// All values within 1e-12 of each other
e.Update(new TValue(DateTime.UtcNow, 100.0 + i * 1e-12));
e.Update(new TValue(DateTime.UtcNow, 100.0 + (i * 1e-12)));
}
// Range ≈ 19e-12, which is > epsilon but all values collapse into same bin
@@ -106,7 +106,7 @@ public sealed class GeomeanValidationTests
var g = new Geomean(10);
for (int i = 0; i < 20; i++)
{
g.Update(new TValue(DateTime.UtcNow, 100.0 + i * 0.001));
g.Update(new TValue(DateTime.UtcNow, 100.0 + (i * 0.001)));
}
Assert.True(Math.Abs(g.Last.Value - 100.01) < 0.1,
$"Expected near 100.01, got {g.Last.Value}");
@@ -209,7 +209,7 @@ public class GrangerStateCorrectionTests
// Multiple corrections converge
for (int i = 0; i < 5; i++)
{
indicator.Update(y1 + i * 0.01, x1 + i * 0.01, isNew: false);
indicator.Update(y1 + (i * 0.01), x1 + (i * 0.01), isNew: false);
}
var final1 = indicator.Update(y1, x1, isNew: false);
@@ -26,8 +26,8 @@ public class GrangerValidationTests
for (int i = 0; i < 200; i++)
{
x = 100.0 + Math.Sin(i * 0.1) * 10.0 + GbmNoise(rng) * 2.0;
y = 50.0 + 0.5 * prevY + 0.3 * prevX + GbmNoise(rng) * 0.5;
x = 100.0 + (Math.Sin(i * 0.1) * 10.0) + (GbmNoise(rng) * 2.0);
y = 50.0 + (0.5 * prevY) + (0.3 * prevX) + (GbmNoise(rng) * 0.5);
indicator.Update(y, x, isNew: true);
@@ -80,12 +80,12 @@ public class GrangerValidationTests
for (int i = 0; i < 200; i++)
{
x = 100.0 + Math.Sin(i * 0.1) * 10.0 + GbmNoise(rng) * 2.0;
x = 100.0 + (Math.Sin(i * 0.1) * 10.0) + (GbmNoise(rng) * 2.0);
// Strong: Y depends heavily on X_lag
yStrong = 50.0 + 0.3 * prevYStrong + 0.6 * prevX + GbmNoise(rng) * 0.5;
yStrong = 50.0 + (0.3 * prevYStrong) + (0.6 * prevX) + (GbmNoise(rng) * 0.5);
// Weak: Y barely depends on X_lag
yWeak = 50.0 + 0.8 * prevYWeak + 0.05 * prevX + GbmNoise(rng) * 5.0;
yWeak = 50.0 + (0.8 * prevYWeak) + (0.05 * prevX) + (GbmNoise(rng) * 5.0);
strongIndicator.Update(yStrong, x, isNew: true);
weakIndicator.Update(yWeak, x, isNew: true);
@@ -211,9 +211,9 @@ public class GrangerValidationTests
for (int i = 0; i < 200; i++)
{
// X is exogenous (just random walk with drift)
x = prevX + GbmNoise(rng) * 2.0;
x = prevX + (GbmNoise(rng) * 2.0);
// Y depends on X_lag (X Granger-causes Y, but Y does NOT Granger-cause X)
y = 50.0 + 0.3 * prevY + 0.4 * prevX + GbmNoise(rng) * 0.5;
y = 50.0 + (0.3 * prevY) + (0.4 * prevX) + (GbmNoise(rng) * 0.5);
indicatorYX.Update(y, x, isNew: true); // Testing: does X cause Y?
indicatorXY.Update(x, y, isNew: true); // Testing: does Y cause X?
@@ -127,7 +127,7 @@ public sealed class HarmeanValidationTests
var h = new Harmean(10);
for (int i = 0; i < 20; i++)
{
h.Update(new TValue(DateTime.UtcNow, 100.0 + i * 0.001));
h.Update(new TValue(DateTime.UtcNow, 100.0 + (i * 0.001)));
}
Assert.True(Math.Abs(h.Last.Value - 100.01) < 0.1,
$"Expected near 100.01, got {h.Last.Value}");
@@ -219,5 +219,4 @@ public sealed class HurstValidationTests
$"Skender Hurst value {r.HurstExponent.Value} is not finite");
}
}
}
+1 -1
View File
@@ -120,7 +120,7 @@ public class JbBasicTests
for (int i = 0; i < 100; i++)
{
// Triangular wave approximating normal shape
double val = 50.0 + Math.Sin(i * 0.1) * 10.0;
double val = 50.0 + (Math.Sin(i * 0.1) * 10.0);
jb.Update(new TValue(DateTime.UtcNow, val));
}
Assert.True(double.IsFinite(jb.Last.Value));
+1 -1
View File
@@ -316,7 +316,7 @@ public class PacfTests
// Generate and store values
for (int i = 0; i < 20; i++)
{
inputs.Add(new TValue(DateTime.UtcNow.AddSeconds(i), 100 + i * 0.5));
inputs.Add(new TValue(DateTime.UtcNow.AddSeconds(i), 100 + (i * 0.5)));
}
// First pass
@@ -115,7 +115,7 @@ public class PacfValidationTests
for (int i = 1; i < 500; i++)
{
double noise = Math.Log(bars[i].Close / bars[i - 1].Close); // i.i.d. incremental return
double newValue = phi * arProcess[^1] + noise;
double newValue = (phi * arProcess[^1]) + noise;
arProcess.Add(newValue);
}
@@ -152,7 +152,7 @@ public class PacfValidationTests
for (int i = 0; i < 100; i++)
{
pacf.Update(new TValue(DateTime.UtcNow.AddSeconds(i), 100.0 + i * 0.5));
pacf.Update(new TValue(DateTime.UtcNow.AddSeconds(i), 100.0 + (i * 0.5)));
}
// Trending series should have high positive PACF at lag 1
@@ -238,7 +238,7 @@ public class PolyfitValidationTests
[InlineData(14, 2)]
public void GBMData_AllFinite(int period, int degree)
{
var gbm = new GBM(100, 0.05, 0.2, seed: period * 10 + degree);
var gbm = new GBM(100, 0.05, 0.2, seed: (period * 10) + degree);
var p = new Polyfit(period, degree);
for (int i = 0; i < 100; i++)
{
@@ -13,7 +13,7 @@ public sealed class SpearmanValidationTests
var s = new Spearman(10);
for (int i = 1; i <= 10; i++)
{
s.Update((double)i, 2.0 * i + 5.0, isNew: true);
s.Update((double)i, (2.0 * i) + 5.0, isNew: true);
}
Assert.Equal(1.0, s.Last.Value, 1e-10);
}
+3 -3
View File
@@ -78,7 +78,7 @@ public class StderrBasicTests
var se = new Stderr(10);
for (int i = 0; i < 10; i++)
{
se.Update(new TValue(DateTime.UtcNow, i * 2.0 + 5.0));
se.Update(new TValue(DateTime.UtcNow, (i * 2.0) + 5.0));
}
Assert.Equal(0.0, se.Last.Value, precision: 8);
}
@@ -138,7 +138,7 @@ public class StderrStateTests
var se = new Stderr(5);
for (int i = 0; i < 5; i++)
{
se.Update(new TValue(DateTime.UtcNow, i * 10.0 + 10.0));
se.Update(new TValue(DateTime.UtcNow, (i * 10.0) + 10.0));
}
double after5 = se.Last.Value;
@@ -152,7 +152,7 @@ public class StderrStateTests
var se = new Stderr(5);
for (int i = 0; i < 5; i++)
{
se.Update(new TValue(DateTime.UtcNow, i * 10.0 + 10.0));
se.Update(new TValue(DateTime.UtcNow, (i * 10.0) + 10.0));
}
se.Update(new TValue(DateTime.UtcNow, 50.0), isNew: true);
@@ -31,19 +31,19 @@ public class StderrValidationTests
sumX2 += (double)i * i;
}
double denom = n * sumX2 - sumX * sumX;
double denom = (n * sumX2) - (sumX * sumX);
if (denom == 0)
{
return 0;
}
double slope = (n * sumXY - sumX * sumY) / denom;
double intercept = (sumY - slope * sumX) / n;
double slope = ((n * sumXY) - (sumX * sumY)) / denom;
double intercept = (sumY - (slope * sumX)) / n;
double ssr = 0;
for (int i = 0; i < n; i++)
{
double predicted = slope * i + intercept;
double predicted = (slope * i) + intercept;
double res = window[i] - predicted;
ssr += res * res;
}
@@ -58,7 +58,7 @@ public class StderrValidationTests
var se = new Stderr(5);
for (int i = 0; i < 5; i++)
{
se.Update(new TValue(DateTime.UtcNow, i * 3.0 + 2.0));
se.Update(new TValue(DateTime.UtcNow, (i * 3.0) + 2.0));
}
Assert.Equal(0.0, se.Last.Value, precision: 8);
}
@@ -215,7 +215,7 @@ public sealed class SumValidationTests : IDisposable
// Expected: sum of 1e10, 1e10+1, ..., 1e10+999
// = 1000 * 1e10 + sum of 0,1,2,...,999
// = 1e13 + 999*1000/2 = 1e13 + 499500
double expectedSum = 1000 * baseValue + 499500.0;
double expectedSum = (1000 * baseValue) + 499500.0;
Assert.Equal(expectedSum, sum.Last.Value, 1e-4);
_output.WriteLine($"Sum Kahan-Babuška stability test passed: {sum.Last.Value:G17}");
@@ -364,7 +364,7 @@ public sealed class SumValidationTests : IDisposable
}
// Expected: 1e16 - 1000 * 1e13 = 1e16 - 1e16 = 0
double expected = 1e16 - 1000 * 1e13;
double expected = 1e16 - (1000 * 1e13);
// With Kahan-Babuška, this should be accurate
// Naive sum would have significant error
@@ -174,8 +174,6 @@ public class VarianceTests
}
}
[Fact]
public void Batch_SimdPath_Triggered()
{
@@ -577,8 +575,6 @@ public class VarianceTests
Assert.Equal(100, outputSamp[2], precision: 6); // 200/2
}
[Fact]
public void Resync_PreventsDrift_Extended()
{
@@ -65,7 +65,7 @@ public sealed class ZscoreValidationTests
{
double val = rng.Next().Close;
z1.Update(new TValue(DateTime.UtcNow, val));
z2.Update(new TValue(DateTime.UtcNow, val * 3.0 + 100.0)); // linear transform
z2.Update(new TValue(DateTime.UtcNow, (val * 3.0) + 100.0)); // linear transform
if (z1.IsHot && z2.IsHot)
{