mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-15 17:18:05 +00:00
Refactor event handling and improve argument validation across indicators
- Updated event handler signatures to use TValueEventArgs for consistency in Mama, Mgdi, Pwma, Rma, Sma, Ssf, Super, T3, Tema, Trima, Usf, Vidya, Wma, and Atr classes. - Enhanced argument validation by specifying parameter names in exceptions for clarity. - Adjusted tests to align with new event handler signatures. - Improved code readability and maintainability by using structured records and lambda expressions.
This commit is contained in:
@@ -33,11 +33,13 @@ public sealed class Jma : AbstractBase
|
||||
private readonly RingBuffer _devBuffer;
|
||||
private readonly RingBuffer _volBuffer;
|
||||
private readonly double[] _sorted;
|
||||
private readonly TValuePublishedHandler _handler;
|
||||
|
||||
// Streaming state (current + previous snapshot for isNew=false)
|
||||
private State _state;
|
||||
private State _p_state;
|
||||
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
private record struct State
|
||||
{
|
||||
// Jurik "envelope" anchors
|
||||
@@ -97,6 +99,7 @@ public sealed class Jma : AbstractBase
|
||||
// same warmup heuristic used in the AFL port (SetBarsRequired)
|
||||
WarmupPeriod = (int)Math.Ceiling(20.0 + 80.0 * Math.Pow(period, 0.36));
|
||||
|
||||
_handler = Handle;
|
||||
Name = $"Jma({period},{phase},{power})"; // power kept for signature compatibility
|
||||
|
||||
_devBuffer = new RingBuffer(DevWindowSize);
|
||||
@@ -109,7 +112,7 @@ public sealed class Jma : AbstractBase
|
||||
public Jma(ITValuePublisher source, int period, int phase = 0, double power = 0.45)
|
||||
: this(period, phase, power)
|
||||
{
|
||||
source.Pub += item => Update(item);
|
||||
source.Pub += _handler;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -238,7 +241,7 @@ public sealed class Jma : AbstractBase
|
||||
{
|
||||
double j = Step(input.Value, isNew);
|
||||
Last = new TValue(input.Time, j);
|
||||
PubEvent(Last);
|
||||
PubEvent(Last, isNew);
|
||||
return Last;
|
||||
}
|
||||
|
||||
@@ -289,6 +292,8 @@ public sealed class Jma : AbstractBase
|
||||
return new TSeries(t, v);
|
||||
}
|
||||
|
||||
private void Handle(object? sender, TValueEventArgs args) => Update(args.Value, args.IsNew);
|
||||
|
||||
public override void Prime(ReadOnlySpan<double> source)
|
||||
{
|
||||
foreach (var value in source)
|
||||
|
||||
Reference in New Issue
Block a user