mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-25 13:58:04 +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:
@@ -25,13 +25,11 @@ public sealed class Gauss : AbstractBase
|
||||
private State _p_state;
|
||||
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
#pragma warning disable CA1066 // Implement IEquatable<T> because it overrides Equals
|
||||
private struct State
|
||||
private record struct State
|
||||
{
|
||||
public double LastValue;
|
||||
public bool IsHot;
|
||||
}
|
||||
#pragma warning restore CA1066
|
||||
|
||||
/// <summary>
|
||||
/// Gets the kernel size used for the filter.
|
||||
|
||||
@@ -20,13 +20,11 @@ public sealed class Hann : AbstractBase
|
||||
private State _p_state;
|
||||
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
#pragma warning disable CA1066 // Implement IEquatable<T> because it overrides Equals
|
||||
private struct State
|
||||
private record struct State
|
||||
{
|
||||
public double LastValue;
|
||||
public bool IsHot;
|
||||
}
|
||||
#pragma warning restore CA1066
|
||||
|
||||
/// <summary>
|
||||
/// Gets the length of the window (period).
|
||||
|
||||
@@ -25,15 +25,13 @@ public sealed class Hp : AbstractBase
|
||||
private State _p_state;
|
||||
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
#pragma warning disable CA1066 // Implement IEquatable<T> because it overrides Equals
|
||||
private struct State
|
||||
private record struct State
|
||||
{
|
||||
public double Trend;
|
||||
public double PrevTrend;
|
||||
public double PrevPrice;
|
||||
public bool IsInitialized;
|
||||
}
|
||||
#pragma warning restore CA1066
|
||||
|
||||
/// <summary>
|
||||
/// Smoothing parameter (lambda). Common values: 1600 (Quarterly), 14400 (Monthly), 6.25 (Annual).
|
||||
|
||||
@@ -22,8 +22,7 @@ public sealed class Hpf : AbstractBase
|
||||
private State _pState;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
#pragma warning disable CA1066 // Implement IEquatable<T> because it overrides Equals
|
||||
private struct State
|
||||
private record struct State
|
||||
{
|
||||
public double Hp1;
|
||||
public double Hp2;
|
||||
@@ -32,7 +31,6 @@ public sealed class Hpf : AbstractBase
|
||||
public int Samples;
|
||||
public bool HasSrc;
|
||||
}
|
||||
#pragma warning restore CA1066
|
||||
|
||||
public int Length { get; }
|
||||
|
||||
|
||||
@@ -42,14 +42,12 @@ public sealed class Kalman : AbstractBase
|
||||
private State _pState;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
#pragma warning disable CA1066 // Implement IEquatable<T> because it overrides Equals
|
||||
private struct State
|
||||
private record struct State
|
||||
{
|
||||
public double X;
|
||||
public double P;
|
||||
public int Samples;
|
||||
}
|
||||
#pragma warning restore CA1066
|
||||
|
||||
/// <summary>
|
||||
/// Process noise covariance. Defaults to 0.01.
|
||||
|
||||
@@ -28,14 +28,12 @@ public sealed class Loess : AbstractBase
|
||||
private Snapshot _pSnap;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
#pragma warning disable CA1066 // Implement IEquatable<T> because it overrides Equals
|
||||
private struct Snapshot
|
||||
private record struct Snapshot
|
||||
{
|
||||
public double LastOutput;
|
||||
public double LastFiniteInput;
|
||||
public bool HasFiniteInput;
|
||||
}
|
||||
#pragma warning restore CA1066
|
||||
|
||||
/// <summary>
|
||||
/// Gets the period of the filter.
|
||||
|
||||
@@ -15,13 +15,11 @@ public sealed class Notch : AbstractBase
|
||||
private State _p_state;
|
||||
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
#pragma warning disable CA1066 // Implement IEquatable<T> because it overrides Equals
|
||||
private struct State
|
||||
private record struct State
|
||||
{
|
||||
public double X1, X2, Y1, Y2;
|
||||
public double LastValue;
|
||||
}
|
||||
#pragma warning restore CA1066
|
||||
|
||||
public int NotchFreq { get; }
|
||||
public double Bandwidth { get; }
|
||||
|
||||
@@ -123,7 +123,10 @@ public sealed class Usf : AbstractBase
|
||||
|
||||
double usf = (_state.Count < 4)
|
||||
? val
|
||||
: (1.0 - _c1) * val + (2.0 * _c1 - _c2) * _state.PrevInput1 - (_c1 + _c3) * _state.PrevInput2 + _c2 * _state.Usf1 + _c3 * _state.Usf2;
|
||||
: Math.FusedMultiplyAdd(_c3, _state.Usf2,
|
||||
Math.FusedMultiplyAdd(_c2, _state.Usf1,
|
||||
Math.FusedMultiplyAdd(_k2, _state.PrevInput2,
|
||||
Math.FusedMultiplyAdd(_k1, _state.PrevInput1, _k0 * val))));
|
||||
|
||||
_state.Usf2 = _state.Usf1;
|
||||
_state.Usf1 = usf;
|
||||
|
||||
Reference in New Issue
Block a user