[CodeFactor] Apply fixes to commit d2fa0fc

This commit is contained in:
codefactor-io
2026-03-16 00:57:48 +00:00
parent d2fa0fc845
commit c0dad33d95
4 changed files with 47 additions and 47 deletions
+30 -30
View File
@@ -423,7 +423,7 @@ public sealed class Adf : AbstractBase
continue; continue;
} }
double aic = nObs * Math.Log(rss / nObs) + 2.0 * k; double aic = (nObs * Math.Log(rss / nObs)) + (2.0 * k);
if (aic < bestAic) if (aic < bestAic)
{ {
bestAic = aic; bestAic = aic;
@@ -501,7 +501,7 @@ public sealed class Adf : AbstractBase
{ {
for (int c = r; c < k; c++) for (int c = r; c < k; c++)
{ {
xtx[r * k + c] += xRow[r] * xRow[c]; xtx[(r * k) + c] += xRow[r] * xRow[c];
} }
xty[r] += xRow[r] * yVal; xty[r] += xRow[r] * yVal;
} }
@@ -512,7 +512,7 @@ public sealed class Adf : AbstractBase
{ {
for (int c = 0; c < r; c++) for (int c = 0; c < r; c++)
{ {
xtx[r * k + c] = xtx[c * k + r]; xtx[(r * k) + c] = xtx[(c * k) + r];
} }
} }
@@ -624,7 +624,7 @@ public sealed class Adf : AbstractBase
{ {
for (int c = r; c < k; c++) for (int c = r; c < k; c++)
{ {
xtx[r * k + c] += xRow[r] * xRow[c]; xtx[(r * k) + c] += xRow[r] * xRow[c];
} }
xty[r] += xRow[r] * yVal; xty[r] += xRow[r] * yVal;
} }
@@ -635,7 +635,7 @@ public sealed class Adf : AbstractBase
{ {
for (int c = 0; c < r; c++) for (int c = 0; c < r; c++)
{ {
xtx[r * k + c] = xtx[c * k + r]; xtx[(r * k) + c] = xtx[(c * k) + r];
} }
} }
@@ -672,7 +672,7 @@ public sealed class Adf : AbstractBase
{ {
for (int c = r; c < k; c++) for (int c = r; c < k; c++)
{ {
xtx[r * k + c] += xRow[r] * xRow[c]; xtx[(r * k) + c] += xRow[r] * xRow[c];
} }
} }
} }
@@ -680,7 +680,7 @@ public sealed class Adf : AbstractBase
{ {
for (int c = 0; c < r; c++) for (int c = 0; c < r; c++)
{ {
xtx[r * k + c] = xtx[c * k + r]; xtx[(r * k) + c] = xtx[(c * k) + r];
} }
} }
@@ -726,7 +726,7 @@ public sealed class Adf : AbstractBase
return (0, 1.0); return (0, 1.0);
} }
double seGamma = Math.Sqrt(s2 * xtxInv[gammaIdx * k + gammaIdx]); double seGamma = Math.Sqrt(s2 * xtxInv[(gammaIdx * k) + gammaIdx]);
if (seGamma <= 1e-15 || !double.IsFinite(seGamma)) if (seGamma <= 1e-15 || !double.IsFinite(seGamma))
{ {
return (0, 1.0); return (0, 1.0);
@@ -758,10 +758,10 @@ public sealed class Adf : AbstractBase
{ {
for (int j = 0; j <= i; j++) for (int j = 0; j <= i; j++)
{ {
double sum = A[i * k + j]; double sum = A[(i * k) + j];
for (int p = 0; p < j; p++) for (int p = 0; p < j; p++)
{ {
sum -= L[i * k + p] * L[j * k + p]; sum -= L[(i * k) + p] * L[(j * k) + p];
} }
if (i == j) if (i == j)
@@ -770,11 +770,11 @@ public sealed class Adf : AbstractBase
{ {
return false; // Not positive definite return false; // Not positive definite
} }
L[i * k + j] = Math.Sqrt(sum); L[(i * k) + j] = Math.Sqrt(sum);
} }
else else
{ {
L[i * k + j] = sum / L[j * k + j]; L[(i * k) + j] = sum / L[(j * k) + j];
} }
} }
} }
@@ -786,9 +786,9 @@ public sealed class Adf : AbstractBase
double sum = b[i]; double sum = b[i];
for (int j = 0; j < i; j++) for (int j = 0; j < i; j++)
{ {
sum -= L[i * k + j] * z[j]; sum -= L[(i * k) + j] * z[j];
} }
z[i] = sum / L[i * k + i]; z[i] = sum / L[(i * k) + i];
} }
// Back substitution: L'·x = z // Back substitution: L'·x = z
@@ -797,9 +797,9 @@ public sealed class Adf : AbstractBase
double sum = z[i]; double sum = z[i];
for (int j = i + 1; j < k; j++) for (int j = i + 1; j < k; j++)
{ {
sum -= L[j * k + i] * x[j]; sum -= L[(j * k) + i] * x[j];
} }
x[i] = sum / L[i * k + i]; x[i] = sum / L[(i * k) + i];
} }
return true; return true;
@@ -819,10 +819,10 @@ public sealed class Adf : AbstractBase
{ {
for (int j = 0; j <= i; j++) for (int j = 0; j <= i; j++)
{ {
double sum = A[i * k + j]; double sum = A[(i * k) + j];
for (int p = 0; p < j; p++) for (int p = 0; p < j; p++)
{ {
sum -= L[i * k + p] * L[j * k + p]; sum -= L[(i * k) + p] * L[(j * k) + p];
} }
if (i == j) if (i == j)
@@ -831,11 +831,11 @@ public sealed class Adf : AbstractBase
{ {
return false; return false;
} }
L[i * k + j] = Math.Sqrt(sum); L[(i * k) + j] = Math.Sqrt(sum);
} }
else else
{ {
L[i * k + j] = sum / L[j * k + j]; L[(i * k) + j] = sum / L[(j * k) + j];
} }
} }
} }
@@ -845,15 +845,15 @@ public sealed class Adf : AbstractBase
Linv.Clear(); Linv.Clear();
for (int i = 0; i < k; i++) for (int i = 0; i < k; i++)
{ {
Linv[i * k + i] = 1.0 / L[i * k + i]; Linv[(i * k) + i] = 1.0 / L[(i * k) + i];
for (int j = i + 1; j < k; j++) for (int j = i + 1; j < k; j++)
{ {
double sum = 0; double sum = 0;
for (int p = i; p < j; p++) for (int p = i; p < j; p++)
{ {
sum -= L[j * k + p] * Linv[p * k + i]; sum -= L[(j * k) + p] * Linv[(p * k) + i];
} }
Linv[j * k + i] = sum / L[j * k + j]; Linv[(j * k) + i] = sum / L[(j * k) + j];
} }
} }
@@ -866,10 +866,10 @@ public sealed class Adf : AbstractBase
double sum = 0; double sum = 0;
for (int p = j; p < k; p++) for (int p = j; p < k; p++)
{ {
sum += Linv[p * k + i] * Linv[p * k + j]; sum += Linv[(p * k) + i] * Linv[(p * k) + j];
} }
Ainv[i * k + j] = sum; Ainv[(i * k) + j] = sum;
Ainv[j * k + i] = sum; Ainv[(j * k) + i] = sum;
} }
} }
@@ -947,7 +947,7 @@ public sealed class Adf : AbstractBase
if (tStat <= tauStar) if (tStat <= tauStar)
{ {
// Small p-value region: p = NormCdf(poly3(tStat)) // Small p-value region: p = NormCdf(poly3(tStat))
double poly = smallP[0] + smallP[1] * tStat + smallP[2] * tStat * tStat; double poly = smallP[0] + (smallP[1] * tStat) + (smallP[2] * tStat * tStat);
return NormCdf(poly); return NormCdf(poly);
} }
else else
@@ -955,7 +955,7 @@ public sealed class Adf : AbstractBase
// Large p-value region: p = NormCdf(poly4(tStat)) // Large p-value region: p = NormCdf(poly4(tStat))
double t2 = tStat * tStat; double t2 = tStat * tStat;
double t3 = t2 * tStat; double t3 = t2 * tStat;
double poly = largeP[0] + largeP[1] * tStat + largeP[2] * t2 + largeP[3] * t3; double poly = largeP[0] + (largeP[1] * tStat) + (largeP[2] * t2) + (largeP[3] * t3);
return NormCdf(poly); return NormCdf(poly);
} }
} }
@@ -1002,11 +1002,11 @@ public sealed class Adf : AbstractBase
double t4 = t3 * t; double t4 = t3 * t;
double t5 = t4 * t; double t5 = t4 * t;
double poly = a1 * t + a2 * t2 + a3 * t3 + a4 * t4 + a5 * t5; double poly = (a1 * t) + (a2 * t2) + (a3 * t3) + (a4 * t4) + (a5 * t5);
double erfcZ = poly * Math.Exp(-z * z); double erfcZ = poly * Math.Exp(-z * z);
double erfZ = 1.0 - erfcZ; double erfZ = 1.0 - erfcZ;
// Φ(x) = 0.5 · (1 + sign · erf(|x|/√2)) // Φ(x) = 0.5 · (1 + sign · erf(|x|/√2))
return 0.5 * (1.0 + sign * erfZ); return 0.5 * (1.0 + (sign * erfZ));
} }
} }
@@ -184,7 +184,7 @@ public sealed class AdfIndicatorTests
for (int i = 0; i < 30; i++) for (int i = 0; i < 30; i++)
{ {
indicator.HistoricalData.AddBar( indicator.HistoricalData.AddBar(
now.AddMinutes(i), 100 + i * 0.5, 105 + i * 0.5, 95 + i * 0.5, 102 + i * 0.5); now.AddMinutes(i), 100 + (i * 0.5), 105 + (i * 0.5), 95 + (i * 0.5), 102 + (i * 0.5));
var reason = i == 0 ? UpdateReason.HistoricalBar : UpdateReason.NewBar; var reason = i == 0 ? UpdateReason.HistoricalBar : UpdateReason.NewBar;
indicator.ProcessUpdate(new UpdateArgs(reason)); indicator.ProcessUpdate(new UpdateArgs(reason));
+6 -6
View File
@@ -374,7 +374,7 @@ public class AdfConsistencyTests
double price = 100; double price = 100;
for (int i = 0; i < 30; i++) for (int i = 0; i < 30; i++)
{ {
price += rng.NextDouble() * 2 - 1; price += (rng.NextDouble() * 2) - 1;
data[i] = price; data[i] = price;
} }
@@ -400,7 +400,7 @@ public class AdfSpecificTests
for (int i = 0; i < 200; i++) for (int i = 0; i < 200; i++)
{ {
y = 100 + 0.5 * (y - 100) + rng.NextDouble() * 2 - 1; y = 100 + (0.5 * (y - 100)) + (rng.NextDouble() * 2) - 1;
a.Update(new TValue(now.AddMinutes(i), y)); a.Update(new TValue(now.AddMinutes(i), y));
} }
@@ -419,7 +419,7 @@ public class AdfSpecificTests
for (int i = 0; i < 200; i++) for (int i = 0; i < 200; i++)
{ {
y += rng.NextDouble() * 2 - 1; y += (rng.NextDouble() * 2) - 1;
a.Update(new TValue(now.AddMinutes(i), y)); a.Update(new TValue(now.AddMinutes(i), y));
} }
@@ -435,7 +435,7 @@ public class AdfSpecificTests
var source = new TSeries(); var source = new TSeries();
for (int i = 0; i < 80; i++) for (int i = 0; i < 80; i++)
{ {
y += rng.NextDouble() * 2 - 1; y += (rng.NextDouble() * 2) - 1;
source.Add(new TValue(DateTime.UtcNow.AddMinutes(i), y)); source.Add(new TValue(DateTime.UtcNow.AddMinutes(i), y));
} }
@@ -464,7 +464,7 @@ public class AdfSpecificTests
var source = new TSeries(); var source = new TSeries();
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
{ {
y += rng.NextDouble() * 2 - 1; y += (rng.NextDouble() * 2) - 1;
source.Add(new TValue(DateTime.UtcNow.AddMinutes(i), y)); source.Add(new TValue(DateTime.UtcNow.AddMinutes(i), y));
} }
@@ -485,7 +485,7 @@ public class AdfSpecificTests
var source = new TSeries(); var source = new TSeries();
for (int i = 0; i < 200; i++) for (int i = 0; i < 200; i++)
{ {
y += rng.NextDouble() * 2 - 1; y += (rng.NextDouble() * 2) - 1;
source.Add(new TValue(DateTime.UtcNow.AddMinutes(i), y)); source.Add(new TValue(DateTime.UtcNow.AddMinutes(i), y));
} }
@@ -44,7 +44,7 @@ public class AdfValidationTests
for (int i = 0; i < 500; i++) for (int i = 0; i < 500; i++)
{ {
y = 0.3 * y + rng.NextDouble() * 2 - 1; y = (0.3 * y) + (rng.NextDouble() * 2) - 1;
a.Update(new TValue(now.AddMinutes(i), 100 + y)); a.Update(new TValue(now.AddMinutes(i), 100 + y));
} }
@@ -63,7 +63,7 @@ public class AdfValidationTests
for (int i = 0; i < 500; i++) for (int i = 0; i < 500; i++)
{ {
double noise = rng.NextDouble() * 10 - 5; // zero-centered white noise double noise = (rng.NextDouble() * 10) - 5; // zero-centered white noise
a.Update(new TValue(now.AddMinutes(i), noise)); a.Update(new TValue(now.AddMinutes(i), noise));
} }
@@ -85,7 +85,7 @@ public class AdfValidationTests
for (int i = 0; i < 500; i++) for (int i = 0; i < 500; i++)
{ {
y += rng.NextDouble() * 2 - 1; y += (rng.NextDouble() * 2) - 1;
a.Update(new TValue(now.AddMinutes(i), y)); a.Update(new TValue(now.AddMinutes(i), y));
} }
@@ -101,7 +101,7 @@ public class AdfValidationTests
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
{ {
a.Update(new TValue(now.AddMinutes(i), 100.0 + i * 0.1)); a.Update(new TValue(now.AddMinutes(i), 100.0 + (i * 0.1)));
} }
// Linear trend without constant/trend in model should appear non-stationary // Linear trend without constant/trend in model should appear non-stationary
@@ -125,7 +125,7 @@ public class AdfValidationTests
double y = 0; double y = 0;
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
{ {
y = -0.9 * y + rng.NextDouble() * 0.1; y = (-0.9 * y) + (rng.NextDouble() * 0.1);
a.Update(new TValue(now.AddMinutes(i), 50 + y)); a.Update(new TValue(now.AddMinutes(i), 50 + y));
} }
@@ -145,7 +145,7 @@ public class AdfValidationTests
var source = new TSeries(); var source = new TSeries();
for (int i = 0; i < 80; i++) for (int i = 0; i < 80; i++)
{ {
y += rng.NextDouble() * 2 - 1; y += (rng.NextDouble() * 2) - 1;
source.Add(new TValue(DateTime.UtcNow.AddMinutes(i), y)); source.Add(new TValue(DateTime.UtcNow.AddMinutes(i), y));
} }
@@ -203,7 +203,7 @@ public class AdfValidationTests
var data = new List<TValue>(); var data = new List<TValue>();
for (int i = 0; i < 40; i++) for (int i = 0; i < 40; i++)
{ {
y += rng.NextDouble() * 2 - 1; y += (rng.NextDouble() * 2) - 1;
data.Add(new TValue(DateTime.UtcNow.AddMinutes(i), y)); data.Add(new TValue(DateTime.UtcNow.AddMinutes(i), y));
} }
@@ -240,7 +240,7 @@ public class AdfValidationTests
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
{ {
y += rng.NextDouble() * 2 - 1; y += (rng.NextDouble() * 2) - 1;
a.Update(new TValue(now.AddMinutes(i), y)); a.Update(new TValue(now.AddMinutes(i), y));
} }
@@ -263,7 +263,7 @@ public class AdfValidationTests
for (int i = 0; i < 25; i++) for (int i = 0; i < 25; i++)
{ {
y += rng.NextDouble() * 2 - 1; y += (rng.NextDouble() * 2) - 1;
a.Update(new TValue(now.AddMinutes(i), y)); a.Update(new TValue(now.AddMinutes(i), y));
} }
@@ -281,7 +281,7 @@ public class AdfValidationTests
for (int i = 0; i < 50; i++) for (int i = 0; i < 50; i++)
{ {
y += rng.NextDouble() * 2 - 1; y += (rng.NextDouble() * 2) - 1;
a.Update(new TValue(now.AddMinutes(i), y)); a.Update(new TValue(now.AddMinutes(i), y));
} }