mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-17 01:58:06 +00:00
[CodeFactor] Apply fixes to commit 4a01f03
This commit is contained in:
@@ -112,7 +112,7 @@ public sealed class QqeValidationTests
|
||||
// Strongly trending up
|
||||
for (int i = 0; i < 200; i++)
|
||||
{
|
||||
ind.Update(new TValue(DateTime.UtcNow.AddMinutes(i), 50.0 + i * 0.5));
|
||||
ind.Update(new TValue(DateTime.UtcNow.AddMinutes(i), 50.0 + (i * 0.5)));
|
||||
}
|
||||
|
||||
Assert.True(ind.IsHot);
|
||||
@@ -130,7 +130,7 @@ public sealed class QqeValidationTests
|
||||
// Strongly trending down
|
||||
for (int i = 0; i < 200; i++)
|
||||
{
|
||||
ind.Update(new TValue(DateTime.UtcNow.AddMinutes(i), 200.0 - i * 0.5));
|
||||
ind.Update(new TValue(DateTime.UtcNow.AddMinutes(i), 200.0 - (i * 0.5)));
|
||||
}
|
||||
|
||||
Assert.True(ind.IsHot);
|
||||
@@ -251,7 +251,7 @@ public sealed class QqeValidationTests
|
||||
// Build state well past warmup (WarmupPeriod ≈ 37)
|
||||
for (int i = 0; i < 60; i++)
|
||||
{
|
||||
ind.Update(new TValue(t0.AddSeconds(i), 100.0 + i * 0.5));
|
||||
ind.Update(new TValue(t0.AddSeconds(i), 100.0 + (i * 0.5)));
|
||||
}
|
||||
|
||||
// Anchor bar
|
||||
|
||||
@@ -101,11 +101,11 @@ public sealed class Qqe : AbstractBase
|
||||
_sfAlpha = 2.0 / (smoothFactor + 1.0);
|
||||
_sfBeta = 1.0 - _sfAlpha;
|
||||
|
||||
int darPeriod = 2 * smoothFactor - 1;
|
||||
int darPeriod = (2 * smoothFactor) - 1;
|
||||
_darAlpha = 2.0 / (darPeriod + 1.0);
|
||||
_darBeta = 1.0 - _darAlpha;
|
||||
|
||||
WarmupPeriod = rsiPeriod + smoothFactor + darPeriod * 2;
|
||||
WarmupPeriod = rsiPeriod + smoothFactor + (darPeriod * 2);
|
||||
|
||||
_s = new State(
|
||||
Count: 0,
|
||||
@@ -168,7 +168,7 @@ public sealed class Qqe : AbstractBase
|
||||
double avgGain = s.RmaGain * cRma;
|
||||
double avgLoss = s.RmaLoss * cRma;
|
||||
double rs = avgLoss < Epsilon ? 100.0 : avgGain / avgLoss;
|
||||
double rsiVal = 100.0 - 100.0 / (1.0 + rs);
|
||||
double rsiVal = 100.0 - (100.0 / (1.0 + rs));
|
||||
|
||||
// ── Stage 2: EMA smooth of RSI (α = 2/(SF+1)) with §2 warmup → rsiMA ──
|
||||
s.RawRsiMa = Math.FusedMultiplyAdd(s.RawRsiMa, _sfBeta, rsiVal * _sfAlpha);
|
||||
|
||||
@@ -225,12 +225,12 @@ public sealed class SqueezeValidationTests
|
||||
// Build state well past warmup (WarmupPeriod = 20)
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
double p = 100.0 + i * 0.5;
|
||||
ind.Update(new TBar(t0 + i * TimeSpan.TicksPerSecond, p, p + 1, p - 1, p, 1000), isNew: true);
|
||||
double p = 100.0 + (i * 0.5);
|
||||
ind.Update(new TBar(t0 + (i * TimeSpan.TicksPerSecond), p, p + 1, p - 1, p, 1000), isNew: true);
|
||||
}
|
||||
|
||||
// Anchor bar
|
||||
long anchorTime = t0 + 50 * TimeSpan.TicksPerSecond;
|
||||
long anchorTime = t0 + (50 * TimeSpan.TicksPerSecond);
|
||||
var anchorBar = new TBar(anchorTime, 125.0, 126.0, 124.0, 125.0, 1000);
|
||||
ind.Update(anchorBar, isNew: true);
|
||||
double anchorMomentum = ind.Momentum;
|
||||
|
||||
@@ -213,7 +213,7 @@ public sealed class Squeeze : ITValuePublisher
|
||||
|
||||
int n = Math.Max(1, s.SmaCount);
|
||||
double smaVal = s.SmaSum / n;
|
||||
double variance = Math.Max(0.0, s.SmaSumSq / n - smaVal * smaVal);
|
||||
double variance = Math.Max(0.0, (s.SmaSumSq / n) - (smaVal * smaVal));
|
||||
double stddev = Math.Sqrt(variance);
|
||||
double bbUpper = Math.FusedMultiplyAdd(_bbMult, stddev, smaVal);
|
||||
double bbLower = Math.FusedMultiplyAdd(-_bbMult, stddev, smaVal);
|
||||
@@ -269,7 +269,7 @@ public sealed class Squeeze : ITValuePublisher
|
||||
if (!double.IsNaN(dl) && dl < lowest) { lowest = dl; }
|
||||
}
|
||||
double donMid = (highest + lowest) * 0.5;
|
||||
double delta = close - (donMid + smaVal) * 0.5;
|
||||
double delta = close - ((donMid + smaVal) * 0.5);
|
||||
|
||||
// ===== STAGE 5: Linear regression of delta over period (O(1) incremental) =====
|
||||
UpdateLrBuf(ref s, delta);
|
||||
@@ -277,16 +277,16 @@ public sealed class Squeeze : ITValuePublisher
|
||||
int pn = Math.Min(s.LrCount, _period);
|
||||
int startIdx = s.LrCount - pn;
|
||||
// Closed-form sums: ΣX and ΣX²
|
||||
double sumX = (double)pn * (2.0 * startIdx + pn - 1) * 0.5;
|
||||
double sumX = (double)pn * ((2.0 * startIdx) + pn - 1) * 0.5;
|
||||
double sumX2 = Math.FusedMultiplyAdd(
|
||||
pn, (double)startIdx * startIdx,
|
||||
Math.FusedMultiplyAdd(
|
||||
(double)startIdx * (pn - 1), pn,
|
||||
(double)(pn - 1) * pn * (2 * pn - 1) / 6.0));
|
||||
(double)(pn - 1) * pn * ((2 * pn) - 1) / 6.0));
|
||||
double denomX = Math.FusedMultiplyAdd(pn, sumX2, -(sumX * sumX));
|
||||
double slope = denomX == 0.0 ? 0.0
|
||||
: Math.FusedMultiplyAdd(pn, s.SumXY, -(sumX * s.SumY)) / denomX;
|
||||
double intercept = (s.SumY - slope * sumX) / pn;
|
||||
double intercept = (s.SumY - (slope * sumX)) / pn;
|
||||
double momentum = Math.FusedMultiplyAdd(slope, s.LrCount - 1, intercept);
|
||||
|
||||
_s = s;
|
||||
@@ -554,7 +554,7 @@ public sealed class Squeeze : ITValuePublisher
|
||||
|
||||
int n = Math.Max(1, smaCount);
|
||||
double smaVal = smaSum / n;
|
||||
double vari = Math.Max(0.0, smaSumSq / n - smaVal * smaVal);
|
||||
double vari = Math.Max(0.0, (smaSumSq / n) - (smaVal * smaVal));
|
||||
double sd = Math.Sqrt(vari);
|
||||
double bbUpper = Math.FusedMultiplyAdd(bbMult, sd, smaVal);
|
||||
double bbLower = Math.FusedMultiplyAdd(-bbMult, sd, smaVal);
|
||||
@@ -602,7 +602,7 @@ public sealed class Squeeze : ITValuePublisher
|
||||
if (!double.IsNaN(dl) && dl < lowest) { lowest = dl; }
|
||||
}
|
||||
double donMid = (highest + lowest) * 0.5;
|
||||
double delta = c - (donMid + smaVal) * 0.5;
|
||||
double delta = c - ((donMid + smaVal) * 0.5);
|
||||
|
||||
// Stage 5: LinReg incremental
|
||||
double oldLr = lrBuf[lrHead];
|
||||
@@ -620,16 +620,16 @@ public sealed class Squeeze : ITValuePublisher
|
||||
|
||||
int pn = Math.Min(lrCount, period);
|
||||
int startI = lrCount - pn;
|
||||
double sx = (double)pn * (2.0 * startI + pn - 1) * 0.5;
|
||||
double sx = (double)pn * ((2.0 * startI) + pn - 1) * 0.5;
|
||||
double sx2 = Math.FusedMultiplyAdd(
|
||||
pn, (double)startI * startI,
|
||||
Math.FusedMultiplyAdd(
|
||||
(double)startI * (pn - 1), pn,
|
||||
(double)(pn - 1) * pn * (2 * pn - 1) / 6.0));
|
||||
(double)(pn - 1) * pn * ((2 * pn) - 1) / 6.0));
|
||||
double denomX = Math.FusedMultiplyAdd(pn, sx2, -(sx * sx));
|
||||
double slope = denomX == 0.0 ? 0.0
|
||||
: Math.FusedMultiplyAdd(pn, sumXY, -(sx * sumY)) / denomX;
|
||||
double intc = (sumY - slope * sx) / pn;
|
||||
double intc = (sumY - (slope * sx)) / pn;
|
||||
double momentum = Math.FusedMultiplyAdd(slope, lrCount - 1, intc);
|
||||
|
||||
momOut[i] = momentum;
|
||||
|
||||
@@ -415,7 +415,7 @@ public sealed class StochrsiValidationTests : IDisposable
|
||||
// Build state well past warmup (WarmupPeriod ≈ 31)
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
ind.Update(new TValue(t0.AddSeconds(i), 100.0 + i * 0.5));
|
||||
ind.Update(new TValue(t0.AddSeconds(i), 100.0 + (i * 0.5)));
|
||||
}
|
||||
|
||||
// Anchor bar
|
||||
|
||||
Reference in New Issue
Block a user