mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-23 04:58:08 +00:00
Refactor error handling and calculations in TheilU, Wmape, and TukeyBiweight classes; update buffer handling for consistency
- Updated buffer handling in TheilU and Wmape classes to ensure consistency after adding new values. - Changed the resync interval constant in TukeyBiweight for better clarity. - Refactored state structures to record structs in Gauss, Hann, Hp, Hpf, Kalman, Loess, Notch, and other filter classes for improved performance and readability. - Enhanced numerical stability in Mama class calculations using Fused Multiply-Add (FMA) for precision. - Added comprehensive tests for Atan2 validation to compare .NET's Math.Atan2 with PineScript's implementation, ensuring accuracy across various edge cases. - Updated NDepend badges to reflect changes in classes, methods, and lines of code.
This commit is contained in:
@@ -29,7 +29,7 @@ public sealed class Frama : ITValuePublisher
|
||||
private readonly TValuePublishedHandler _handler;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct State
|
||||
private record struct State
|
||||
{
|
||||
public double Frama;
|
||||
public double LastHigh;
|
||||
|
||||
@@ -30,7 +30,7 @@ public sealed class Hema : AbstractBase
|
||||
private const double Ln2 = 0.693147180559945309417232121458176568;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct State
|
||||
private record struct State
|
||||
{
|
||||
public double EmaSlowRaw;
|
||||
public double EmaFastRaw;
|
||||
|
||||
@@ -210,9 +210,12 @@ public sealed class Mama : AbstractBase
|
||||
double alpha = _scaledFastLimit / delta;
|
||||
alpha = Math.Clamp(alpha, _slowLimit, _fastLimit);
|
||||
|
||||
// Final indicators
|
||||
_state.Mama = alpha * _priceBuffer[^1] + (1.0 - alpha) * _p_state.Mama;
|
||||
_state.Fama = FamaAlphaFactor * alpha * _state.Mama + (1.0 - FamaAlphaFactor * alpha) * _p_state.Fama;
|
||||
// Final indicators (using FMA for precision)
|
||||
double decay = 1.0 - alpha;
|
||||
_state.Mama = Math.FusedMultiplyAdd(_p_state.Mama, decay, alpha * _priceBuffer[^1]);
|
||||
double famaAlpha = FamaAlphaFactor * alpha;
|
||||
double famaDecay = 1.0 - famaAlpha;
|
||||
_state.Fama = Math.FusedMultiplyAdd(_p_state.Fama, famaDecay, famaAlpha * _state.Mama);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -442,9 +445,12 @@ public sealed class Mama : AbstractBase
|
||||
double alpha = scaledFastLimit / delta;
|
||||
alpha = Math.Clamp(alpha, slowLimit, fastLimit);
|
||||
|
||||
// Final indicators
|
||||
mama = alpha * priceBuffer[bufferIdx] + (1.0 - alpha) * p_mama;
|
||||
fama = FamaAlphaFactor * alpha * mama + (1.0 - FamaAlphaFactor * alpha) * p_fama;
|
||||
// Final indicators (using FMA for precision)
|
||||
double decay = 1.0 - alpha;
|
||||
mama = Math.FusedMultiplyAdd(p_mama, decay, alpha * priceBuffer[bufferIdx]);
|
||||
double famaAlpha = FamaAlphaFactor * alpha;
|
||||
double famaDecay = 1.0 - famaAlpha;
|
||||
fama = Math.FusedMultiplyAdd(p_fama, famaDecay, famaAlpha * mama);
|
||||
|
||||
// Update previous state
|
||||
p_i2 = i2;
|
||||
|
||||
Reference in New Issue
Block a user