feat(tests): enhance tests with GBM for noise generation and improve tolerance for MAMA validation

feat(trends): implement IDisposable in Bessel and Conv classes to manage event subscriptions
fix(trends): add validation for period and parameters in Kama and MGDI calculations
fix(trends): clamp logarithmic calculations in JMA to avoid -Infinity
This commit is contained in:
Miha Kralj
2025-12-25 20:18:14 -08:00
parent df598c810d
commit ac8b2dbb3f
20 changed files with 281 additions and 187 deletions
+18 -3
View File
@@ -21,7 +21,7 @@ namespace QuanTAlib;
/// F[n] = c1 * Src[n] + c2 * F[n-1] + c3 * F[n-2]
/// </remarks>
[SkipLocalsInit]
public sealed class Bessel : AbstractBase
public sealed class Bessel : AbstractBase, IDisposable
{
private record struct State(double F1, double F2, double LastValidValue, int Count, bool IsHot)
{
@@ -36,6 +36,8 @@ public sealed class Bessel : AbstractBase
}
private readonly double _c1, _c2, _c3;
private readonly ITValuePublisher? _publisher;
private readonly Action<TValue>? _handler;
private State _state = State.New();
private State _p_state = State.New();
@@ -65,7 +67,9 @@ public sealed class Bessel : AbstractBase
/// </summary>
public Bessel(ITValuePublisher source, int length) : this(length)
{
source.Pub += item => Update(item);
_publisher = source;
_handler = item => Update(item);
_publisher.Pub += _handler;
}
/// <summary>
@@ -79,7 +83,9 @@ public sealed class Bessel : AbstractBase
Last = new TValue(source.LastTime, Last.Value);
}
source.Pub += item => Update(item);
_publisher = source;
_handler = item => Update(item);
_publisher.Pub += _handler;
}
public override bool IsHot => _state.IsHot;
@@ -309,4 +315,13 @@ public sealed class Bessel : AbstractBase
_p_state = _state;
Last = default;
}
public void Dispose()
{
if (_publisher != null && _handler != null)
{
_publisher.Pub -= _handler;
}
GC.SuppressFinalize(this);
}
}