mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-16 09:38:05 +00:00
[CodeFactor] Apply fixes to commit 9697fac
This commit is contained in:
@@ -161,7 +161,6 @@ public sealed class Apo : ITValuePublisher, IDisposable
|
||||
Update(args.Value, args.IsNew);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the indicator state using the provided series history.
|
||||
/// </summary>
|
||||
|
||||
@@ -339,8 +339,8 @@ public sealed class Bbi : AbstractBase
|
||||
double old4 = b4[h4]; sum4 = c4 < p4 ? sum4 + val - old4 : sum4 - old4 + val; if (c4 < p4) { c4++; }
|
||||
b4[h4] = val; h4 = (h4 + 1) % p4;
|
||||
|
||||
output[i] = (sum1 / Math.Max(1, c1) + sum2 / Math.Max(1, c2)
|
||||
+ sum3 / Math.Max(1, c3) + sum4 / Math.Max(1, c4)) * 0.25;
|
||||
output[i] = ((sum1 / Math.Max(1, c1)) + (sum2 / Math.Max(1, c2))
|
||||
+ (sum3 / Math.Max(1, c3)) + (sum4 / Math.Max(1, c4))) * 0.25;
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -360,7 +360,6 @@ public sealed class Bbs : ITValuePublisher
|
||||
// === Bandwidth ===
|
||||
double bandwidth = bbMean != 0.0 ? ((bbUpper - bbLower) / bbMean) * 100.0 : 0.0; // skipcq: CS-R1077 - Exact-zero div guard: price avg
|
||||
|
||||
|
||||
// === IsHot ===
|
||||
if (!_state.IsHot && _state.Bars >= WarmupPeriod)
|
||||
{
|
||||
|
||||
@@ -56,8 +56,8 @@ public sealed class Cfo : AbstractBase
|
||||
WarmupPeriod = period;
|
||||
|
||||
_sumX = period * (period - 1) / 2.0;
|
||||
double sumX2 = period * (period - 1.0) * (2.0 * period - 1.0) / 6.0;
|
||||
_denomX = period * sumX2 - _sumX * _sumX;
|
||||
double sumX2 = period * (period - 1.0) * ((2.0 * period) - 1.0) / 6.0;
|
||||
_denomX = (period * sumX2) - (_sumX * _sumX);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -160,8 +160,8 @@ public sealed class Cfo : AbstractBase
|
||||
}
|
||||
|
||||
// Linear regression: slope, intercept, TSF
|
||||
double slope = (_period * _state.SumXY - _sumX * _state.SumY) / _denomX;
|
||||
double intercept = (_state.SumY - slope * _sumX) / _period;
|
||||
double slope = ((_period * _state.SumXY) - (_sumX * _state.SumY)) / _denomX;
|
||||
double intercept = (_state.SumY - (slope * _sumX)) / _period;
|
||||
double tsf = Math.FusedMultiplyAdd(slope, _period - 1, intercept);
|
||||
|
||||
// CFO = 100 * (source - tsf) / source
|
||||
@@ -265,8 +265,8 @@ public sealed class Cfo : AbstractBase
|
||||
}
|
||||
|
||||
double sumX = period * (period - 1) / 2.0;
|
||||
double sumX2 = period * (period - 1.0) * (2.0 * period - 1.0) / 6.0;
|
||||
double denomX = period * sumX2 - sumX * sumX;
|
||||
double sumX2 = period * (period - 1.0) * ((2.0 * period) - 1.0) / 6.0;
|
||||
double denomX = (period * sumX2) - (sumX * sumX);
|
||||
|
||||
double sumY = 0.0;
|
||||
double sumXY = 0.0;
|
||||
@@ -311,8 +311,8 @@ public sealed class Cfo : AbstractBase
|
||||
continue;
|
||||
}
|
||||
|
||||
double slope = (period * sumXY - sumX * sumY) / denomX;
|
||||
double intercept = (sumY - slope * sumX) / period;
|
||||
double slope = ((period * sumXY) - (sumX * sumY)) / denomX;
|
||||
double intercept = (sumY - (slope * sumX)) / period;
|
||||
double tsf = Math.FusedMultiplyAdd(slope, period - 1, intercept);
|
||||
|
||||
output[i] = val == 0.0 ? double.NaN : 100.0 * (val - tsf) / val; // skipcq: CS-R1077 - Exact-zero guard: val is a price; zero means no data, division by zero produces Infinity
|
||||
|
||||
@@ -203,7 +203,7 @@ public sealed class Coppock : ITValuePublisher
|
||||
{
|
||||
double oldPlain = plainSum;
|
||||
plainSum = plainSum - prevWma + combined;
|
||||
weightedSum = weightedSum - oldPlain + _wmaPeriod * combined;
|
||||
weightedSum = weightedSum - oldPlain + (_wmaPeriod * combined);
|
||||
coppockVal = weightedSum / _wmaNorm;
|
||||
}
|
||||
|
||||
@@ -357,7 +357,7 @@ public sealed class Coppock : ITValuePublisher
|
||||
{
|
||||
double oldPlain = plainSum;
|
||||
plainSum = plainSum - oldest + combined;
|
||||
weightedSum = weightedSum - oldPlain + wmaPeriod * combined;
|
||||
weightedSum = weightedSum - oldPlain + (wmaPeriod * combined);
|
||||
coppockVal = weightedSum / wmaNorm;
|
||||
}
|
||||
wmaBuf[wmaH] = combined;
|
||||
|
||||
@@ -63,7 +63,7 @@ public sealed class Cti : AbstractBase
|
||||
WarmupPeriod = period;
|
||||
|
||||
_sx = period * (period - 1) / 2.0;
|
||||
_sxx = period * (period - 1.0) * (2 * period - 1) / 6.0;
|
||||
_sxx = period * (period - 1.0) * ((2 * period) - 1) / 6.0;
|
||||
_denomX = Math.FusedMultiplyAdd(period, _sxx, -_sx * _sx);
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ public sealed class Cti : AbstractBase
|
||||
}
|
||||
|
||||
double sx = period * (period - 1) / 2.0;
|
||||
double sxx = period * (period - 1.0) * (2 * period - 1) / 6.0;
|
||||
double sxx = period * (period - 1.0) * ((2 * period) - 1) / 6.0;
|
||||
double denomX = Math.FusedMultiplyAdd(period, sxx, -sx * sx);
|
||||
|
||||
double sumY = 0.0;
|
||||
|
||||
@@ -87,7 +87,7 @@ public sealed class Deco : AbstractBase
|
||||
|
||||
double argShort = rad / shortPeriod;
|
||||
double alphaShort = (Math.Cos(argShort) + Math.Sin(argShort) - 1.0) / Math.Cos(argShort);
|
||||
double oneMinusAlphaHalfShort = 1.0 - alphaShort * 0.5;
|
||||
double oneMinusAlphaHalfShort = 1.0 - (alphaShort * 0.5);
|
||||
double oneMinusAlphaShort = 1.0 - alphaShort;
|
||||
_a1Short = oneMinusAlphaHalfShort * oneMinusAlphaHalfShort;
|
||||
_b1Short = 2.0 * oneMinusAlphaShort;
|
||||
@@ -95,7 +95,7 @@ public sealed class Deco : AbstractBase
|
||||
|
||||
double argLong = rad / longPeriod;
|
||||
double alphaLong = (Math.Cos(argLong) + Math.Sin(argLong) - 1.0) / Math.Cos(argLong);
|
||||
double oneMinusAlphaHalfLong = 1.0 - alphaLong * 0.5;
|
||||
double oneMinusAlphaHalfLong = 1.0 - (alphaLong * 0.5);
|
||||
double oneMinusAlphaLong = 1.0 - alphaLong;
|
||||
_a1Long = oneMinusAlphaHalfLong * oneMinusAlphaHalfLong;
|
||||
_b1Long = 2.0 * oneMinusAlphaLong;
|
||||
@@ -153,7 +153,7 @@ public sealed class Deco : AbstractBase
|
||||
else
|
||||
{
|
||||
// HP[n] = a1*(x[n] - 2*x[n-1] + x[n-2]) + b1*HP[n-1] + c1*HP[n-2]
|
||||
double diff = value - 2.0 * s.Price1 + s.Price2;
|
||||
double diff = value - (2.0 * s.Price1) + s.Price2;
|
||||
hpShort = Math.FusedMultiplyAdd(_a1Short, diff, Math.FusedMultiplyAdd(_b1Short, s.HpShort1, _c1Short * s.HpShort2));
|
||||
hpLong = Math.FusedMultiplyAdd(_a1Long, diff, Math.FusedMultiplyAdd(_b1Long, s.HpLong1, _c1Long * s.HpLong2));
|
||||
|
||||
@@ -262,7 +262,7 @@ public sealed class Deco : AbstractBase
|
||||
|
||||
double argShort = rad / shortPeriod;
|
||||
double alphaShort = (Math.Cos(argShort) + Math.Sin(argShort) - 1.0) / Math.Cos(argShort);
|
||||
double omahShort = 1.0 - alphaShort * 0.5;
|
||||
double omahShort = 1.0 - (alphaShort * 0.5);
|
||||
double omaShort = 1.0 - alphaShort;
|
||||
double a1S = omahShort * omahShort;
|
||||
double b1S = 2.0 * omaShort;
|
||||
@@ -270,7 +270,7 @@ public sealed class Deco : AbstractBase
|
||||
|
||||
double argLong = rad / longPeriod;
|
||||
double alphaLong = (Math.Cos(argLong) + Math.Sin(argLong) - 1.0) / Math.Cos(argLong);
|
||||
double omahLong = 1.0 - alphaLong * 0.5;
|
||||
double omahLong = 1.0 - (alphaLong * 0.5);
|
||||
double omaLong = 1.0 - alphaLong;
|
||||
double a1L = omahLong * omahLong;
|
||||
double b1L = 2.0 * omaLong;
|
||||
@@ -291,7 +291,7 @@ public sealed class Deco : AbstractBase
|
||||
}
|
||||
else
|
||||
{
|
||||
double diff = val - 2.0 * price1 + price2;
|
||||
double diff = val - (2.0 * price1) + price2;
|
||||
double hpS = Math.FusedMultiplyAdd(a1S, diff, Math.FusedMultiplyAdd(b1S, hpS1, c1S * hpS2));
|
||||
double hpL = Math.FusedMultiplyAdd(a1L, diff, Math.FusedMultiplyAdd(b1L, hpL1, c1L * hpL2));
|
||||
output[i] = hpL - hpS;
|
||||
@@ -314,5 +314,4 @@ public sealed class Deco : AbstractBase
|
||||
var results = ind.Update(source);
|
||||
return (results, ind);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ public sealed class Dosc : AbstractBase
|
||||
s.AvgLoss = Math.FusedMultiplyAdd(rsiAlpha, changeDn, rsiDecay * s.AvgLoss);
|
||||
}
|
||||
|
||||
double rsiVal = s.AvgLoss == 0.0 ? 100.0 : 100.0 - 100.0 / (1.0 + s.AvgGain / s.AvgLoss);
|
||||
double rsiVal = s.AvgLoss == 0.0 ? 100.0 : 100.0 - (100.0 / (1.0 + (s.AvgGain / s.AvgLoss)));
|
||||
|
||||
// --- Stage 2: EMA1 of RSI ---
|
||||
double ema1;
|
||||
|
||||
@@ -194,7 +194,7 @@ public sealed class Dymoi : AbstractBase
|
||||
|
||||
int nShort = s.CountShort;
|
||||
double meanShort = s.SumShort / nShort;
|
||||
double varShort = s.SumSqShort / nShort - meanShort * meanShort;
|
||||
double varShort = (s.SumSqShort / nShort) - (meanShort * meanShort);
|
||||
double sdShort = varShort > 0.0 ? Math.Sqrt(varShort) : 0.0;
|
||||
|
||||
// ── Stage 1: StdDev long window (O(1) update) ──
|
||||
@@ -216,7 +216,7 @@ public sealed class Dymoi : AbstractBase
|
||||
|
||||
int nLong = s.CountLong;
|
||||
double meanLong = s.SumLong / nLong;
|
||||
double varLong = s.SumSqLong / nLong - meanLong * meanLong;
|
||||
double varLong = (s.SumSqLong / nLong) - (meanLong * meanLong);
|
||||
double sdLong = varLong > 0.0 ? Math.Sqrt(varLong) : 0.0;
|
||||
|
||||
// ── Stage 2: dynamic period ──
|
||||
@@ -442,7 +442,7 @@ public sealed class Dymoi : AbstractBase
|
||||
}
|
||||
|
||||
double meanS = sumShort / countShort;
|
||||
double varS = sumSqShort / countShort - meanS * meanS;
|
||||
double varS = (sumSqShort / countShort) - (meanS * meanS);
|
||||
double sdShort = varS > 0.0 ? Math.Sqrt(varS) : 0.0;
|
||||
|
||||
// Long StdDev update
|
||||
@@ -463,7 +463,7 @@ public sealed class Dymoi : AbstractBase
|
||||
}
|
||||
|
||||
double meanL = sumLong / countLong;
|
||||
double varL = sumSqLong / countLong - meanL * meanL;
|
||||
double varL = (sumSqLong / countLong) - (meanL * meanL);
|
||||
double sdLong = varL > 0.0 ? Math.Sqrt(varL) : 0.0;
|
||||
|
||||
// Dynamic period
|
||||
|
||||
@@ -58,8 +58,8 @@ public sealed class Inertia : AbstractBase
|
||||
WarmupPeriod = period;
|
||||
|
||||
_sumX = period * (period - 1) / 2.0;
|
||||
double sumX2 = period * (period - 1.0) * (2.0 * period - 1.0) / 6.0;
|
||||
_denomX = period * sumX2 - _sumX * _sumX;
|
||||
double sumX2 = period * (period - 1.0) * ((2.0 * period) - 1.0) / 6.0;
|
||||
_denomX = (period * sumX2) - (_sumX * _sumX);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -160,8 +160,8 @@ public sealed class Inertia : AbstractBase
|
||||
}
|
||||
|
||||
// Linear regression: slope, intercept, TSF
|
||||
double slope = (_period * _state.SumXY - _sumX * _state.SumY) / _denomX;
|
||||
double intercept = (_state.SumY - slope * _sumX) / _period;
|
||||
double slope = ((_period * _state.SumXY) - (_sumX * _state.SumY)) / _denomX;
|
||||
double intercept = (_state.SumY - (slope * _sumX)) / _period;
|
||||
double tsf = Math.FusedMultiplyAdd(slope, _period - 1, intercept);
|
||||
|
||||
// Inertia = source - TSF (raw residual, no normalization)
|
||||
@@ -265,8 +265,8 @@ public sealed class Inertia : AbstractBase
|
||||
}
|
||||
|
||||
double sumX = period * (period - 1) / 2.0;
|
||||
double sumX2 = period * (period - 1.0) * (2.0 * period - 1.0) / 6.0;
|
||||
double denomX = period * sumX2 - sumX * sumX;
|
||||
double sumX2 = period * (period - 1.0) * ((2.0 * period) - 1.0) / 6.0;
|
||||
double denomX = (period * sumX2) - (sumX * sumX);
|
||||
|
||||
double sumY = 0.0;
|
||||
double sumXY = 0.0;
|
||||
@@ -311,8 +311,8 @@ public sealed class Inertia : AbstractBase
|
||||
continue;
|
||||
}
|
||||
|
||||
double slope = (period * sumXY - sumX * sumY) / denomX;
|
||||
double intercept = (sumY - slope * sumX) / period;
|
||||
double slope = ((period * sumXY) - (sumX * sumY)) / denomX;
|
||||
double intercept = (sumY - (slope * sumX)) / period;
|
||||
double tsf = Math.FusedMultiplyAdd(slope, period - 1, intercept);
|
||||
|
||||
output[i] = val - tsf;
|
||||
|
||||
@@ -255,7 +255,7 @@ public sealed class Kst : ITValuePublisher
|
||||
|
||||
// ── KST composite (weighted sum, FMA for w1..w3) ─────────────────────
|
||||
double kstVal = Math.FusedMultiplyAdd(3.0, sm3, Math.FusedMultiplyAdd(2.0, sm2, sm1))
|
||||
+ 4.0 * sm4;
|
||||
+ (4.0 * sm4);
|
||||
|
||||
// ── Signal line (SMA of KST) ──────────────────────────────────────────
|
||||
double sigVal = StepSma(_sigBuf, ref sigSum, ref sigH, ref sigC, kstVal, _sigPeriod, isNew, out double prevSig);
|
||||
@@ -458,7 +458,7 @@ public sealed class Kst : ITValuePublisher
|
||||
double sm4 = BatchStepSma(sm4b, s4, ref sum4, ref sh4, ref sc4, roc4);
|
||||
|
||||
double kstVal = Math.FusedMultiplyAdd(3.0, sm3, Math.FusedMultiplyAdd(2.0, sm2, sm1))
|
||||
+ 4.0 * sm4;
|
||||
+ (4.0 * sm4);
|
||||
|
||||
sigOut[i] = BatchStepSma(sigb, sigPeriod, ref sumSig, ref shSig, ref scSig, kstVal);
|
||||
kstOut[i] = kstVal;
|
||||
|
||||
@@ -135,7 +135,7 @@ public sealed class Mstoch : ITValuePublisher
|
||||
// === Stage 1: Highpass (2-pole Butterworth, removes trend) ===
|
||||
// HP = c1*(src - 2*src1 + src2) + c2*hp1 + c3*hp2
|
||||
double hp = Math.FusedMultiplyAdd(
|
||||
_hpC1, src - 2.0 * s.Src1 + s.Src2,
|
||||
_hpC1, src - (2.0 * s.Src1) + s.Src2,
|
||||
Math.FusedMultiplyAdd(_hpC2, s.Hp1, _hpC3 * s.Hp2));
|
||||
|
||||
// === Stage 1: Super Smoother of HP => Filt ===
|
||||
@@ -332,7 +332,7 @@ public sealed class Mstoch : ITValuePublisher
|
||||
}
|
||||
|
||||
double hp = Math.FusedMultiplyAdd(
|
||||
hpC1, s - 2.0 * prevSrc1 + prevSrc2,
|
||||
hpC1, s - (2.0 * prevSrc1) + prevSrc2,
|
||||
Math.FusedMultiplyAdd(hpC2, prevHp1, hpC3 * prevHp2));
|
||||
|
||||
double filtIn = (hp + prevHp1) * 0.5;
|
||||
|
||||
@@ -222,7 +222,7 @@ public sealed class Trendflex : AbstractBase
|
||||
// Always use Add (not UpdateNewest) because Snapshot/Restore already handles rollback
|
||||
buf.Add(filt);
|
||||
int n = Math.Min(s.Count, period);
|
||||
double slopeSum = n > 0 ? (n * filt - buf.Sum) / period : 0.0;
|
||||
double slopeSum = n > 0 ? ((n * filt) - buf.Sum) / period : 0.0;
|
||||
|
||||
// --- RMS normalization ---
|
||||
s.Ms = Math.FusedMultiplyAdd(RMS_ALPHA, slopeSum * slopeSum, RMS_DECAY * s.Ms);
|
||||
@@ -272,7 +272,7 @@ public sealed class Trendflex : AbstractBase
|
||||
// Slope
|
||||
buf.Add(filt);
|
||||
int n = Math.Min(s.Count, period);
|
||||
double slopeSum = n > 0 ? (n * filt - buf.Sum) / period : 0.0;
|
||||
double slopeSum = n > 0 ? ((n * filt) - buf.Sum) / period : 0.0;
|
||||
|
||||
// RMS
|
||||
s.Ms = Math.FusedMultiplyAdd(RMS_ALPHA, slopeSum * slopeSum, RMS_DECAY * s.Ms);
|
||||
|
||||
@@ -424,7 +424,6 @@ public sealed class Ultosc : AbstractBase
|
||||
return (results, indicator);
|
||||
}
|
||||
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
_bp1.Clear();
|
||||
|
||||
Reference in New Issue
Block a user