feat(rsi, alma, bilateral, blma, butter, ema, htit, kama, lsma, pwma, rma, trima, vidya, wma): enhance calculations with NaN handling and edge case management; improve performance and stability across multiple classes

This commit is contained in:
Miha Kralj
2025-12-25 22:16:07 -08:00
parent 0d077c24d8
commit 86e2934f1b
17 changed files with 203 additions and 71 deletions
+15 -2
View File
@@ -25,11 +25,13 @@ namespace QuanTAlib;
/// Becomes true when both internal SMAs are hot.
/// </remarks>
[SkipLocalsInit]
public sealed class Trima : AbstractBase
public sealed class Trima : AbstractBase, IDisposable
{
private readonly int _period;
private readonly Sma _sma1;
private readonly Sma _sma2;
private readonly Action<TValue> _updateHandler;
private ITValuePublisher? _publisher;
public Trima(int period)
{
@@ -41,6 +43,7 @@ public sealed class Trima : AbstractBase
_sma1 = new Sma(p1);
_sma2 = new Sma(p2);
_updateHandler = (item) => Update(item);
Name = $"Trima({period})";
WarmupPeriod = p1 + p2 - 1;
@@ -48,7 +51,17 @@ public sealed class Trima : AbstractBase
public Trima(ITValuePublisher source, int period) : this(period)
{
source.Pub += (item) => Update(item);
_publisher = source;
_publisher.Pub += _updateHandler;
}
public void Dispose()
{
if (_publisher != null)
{
_publisher.Pub -= _updateHandler;
_publisher = null;
}
}
public override bool IsHot => _sma1.IsHot && _sma2.IsHot;