mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-16 09:38: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:
@@ -66,7 +66,7 @@ public class VidyaValidationTests
|
||||
_output.WriteLine("VIDYA Batch validated successfully against reference implementation");
|
||||
}
|
||||
|
||||
private static List<double> CalculateVidyaReference(TSeries data, int period)
|
||||
private static IReadOnlyList<double> CalculateVidyaReference(TSeries data, int period)
|
||||
{
|
||||
var results = new List<double>();
|
||||
var prices = data.Select(x => x.Value).ToList();
|
||||
|
||||
@@ -33,8 +33,9 @@ public sealed class Vidya : AbstractBase, IDisposable
|
||||
private readonly RingBuffer _ups;
|
||||
private readonly RingBuffer _downs;
|
||||
private readonly ITValuePublisher? _source;
|
||||
private readonly Action<TValue>? _pubHandler;
|
||||
private readonly TValuePublishedHandler? _pubHandler;
|
||||
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
private record struct State(
|
||||
double PrevClose, double LastVidya,
|
||||
double CurrentClose, double CurrentVidya,
|
||||
@@ -59,7 +60,7 @@ public sealed class Vidya : AbstractBase, IDisposable
|
||||
public Vidya(ITValuePublisher source, int period) : this(period)
|
||||
{
|
||||
_source = source;
|
||||
_pubHandler = (item) => Update(item);
|
||||
_pubHandler = Handle;
|
||||
source.Pub += _pubHandler;
|
||||
}
|
||||
|
||||
@@ -71,6 +72,8 @@ public sealed class Vidya : AbstractBase, IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
private void Handle(object? sender, TValueEventArgs e) => Update(e.Value, e.IsNew);
|
||||
|
||||
public override bool IsHot => _state.BarCount >= _period;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -277,7 +280,7 @@ public sealed class Vidya : AbstractBase, IDisposable
|
||||
if (period <= 0)
|
||||
throw new ArgumentException("Period must be greater than 0", nameof(period));
|
||||
if (source.Length != output.Length)
|
||||
throw new ArgumentException("Source and output must have the same length");
|
||||
throw new ArgumentException("Source and output must have the same length", nameof(output));
|
||||
|
||||
if (source.Length == 0) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user