mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-25 13:58:04 +00:00
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:
+18
-7
@@ -5,12 +5,14 @@ using QuanTAlib;
|
||||
|
||||
namespace QuanTAlib;
|
||||
|
||||
public sealed class Blma : AbstractBase
|
||||
public sealed class Blma : AbstractBase, IDisposable
|
||||
{
|
||||
private readonly int _period;
|
||||
private readonly RingBuffer _buffer;
|
||||
private readonly double[] _weights;
|
||||
private readonly double _weightSum;
|
||||
private ITValuePublisher? _publisher;
|
||||
private bool _hasLast;
|
||||
|
||||
public override bool IsHot => _buffer.Count >= _period;
|
||||
|
||||
@@ -33,14 +35,12 @@ public sealed class Blma : AbstractBase
|
||||
|
||||
public Blma(object source, int period) : this(period)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(source);
|
||||
|
||||
if (source is ITValuePublisher pub)
|
||||
{
|
||||
pub.Pub += Handle;
|
||||
_publisher = pub;
|
||||
_publisher.Pub += Handle;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -48,6 +48,15 @@ public sealed class Blma : AbstractBase
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_publisher != null)
|
||||
{
|
||||
_publisher.Pub -= Handle;
|
||||
_publisher = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void Handle(TValue value)
|
||||
{
|
||||
Update(value);
|
||||
@@ -56,6 +65,7 @@ public sealed class Blma : AbstractBase
|
||||
public override void Reset()
|
||||
{
|
||||
_buffer.Clear();
|
||||
_hasLast = false;
|
||||
}
|
||||
|
||||
public override void Prime(ReadOnlySpan<double> source)
|
||||
@@ -80,7 +90,7 @@ public sealed class Blma : AbstractBase
|
||||
{
|
||||
if (double.IsNaN(input.Value) || double.IsInfinity(input.Value))
|
||||
{
|
||||
return Last;
|
||||
return _hasLast ? Last : default;
|
||||
}
|
||||
|
||||
_buffer.Add(input.Value, isNew);
|
||||
@@ -116,6 +126,7 @@ public sealed class Blma : AbstractBase
|
||||
|
||||
var tValue = new TValue(input.Time, result);
|
||||
Last = tValue;
|
||||
_hasLast = true;
|
||||
PubEvent(tValue);
|
||||
return tValue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user