mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-22 20:48:04 +00:00
Refactor indicators to support optional time step in Prime method
- Updated the Prime method signature in multiple indicators (Jma, Kama, Lsma, Mama, Mgdi, Pwma, Rma, Sma, Ssf, Super, T3, Tema, Trima, Usf, Vidya, Wma, Atr) to accept an optional TimeSpan parameter for improved flexibility. - Added unit tests for Lsma to verify Dispose functionality, ensuring proper unsubscription from the source and thread safety. - Enhanced Mama and Wma classes to handle non-finite inputs gracefully and added checks for valid parameters in constructors. - Introduced additional tests for T3 to validate constructor behavior with invalid volume factors. - Ensured all indicators maintain consistent behavior when handling edge cases, such as empty buffers and non-finite values.
This commit is contained in:
+24
-2
@@ -70,7 +70,7 @@ public sealed class Ssf : AbstractBase
|
||||
public Ssf(TSeries source, int period) : this(period)
|
||||
{
|
||||
Prime(source.Values);
|
||||
if (source.Count > 0)
|
||||
if (source.Count > 0 && double.IsFinite(Last.Value))
|
||||
{
|
||||
Last = new TValue(source.LastTime, Last.Value);
|
||||
}
|
||||
@@ -81,7 +81,7 @@ public sealed class Ssf : AbstractBase
|
||||
|
||||
public override bool IsHot => _state.IsHot;
|
||||
|
||||
public override void Prime(ReadOnlySpan<double> source)
|
||||
public override void Prime(ReadOnlySpan<double> source, TimeSpan? step = null)
|
||||
{
|
||||
if (source.Length == 0) return;
|
||||
|
||||
@@ -105,6 +105,18 @@ public sealed class Ssf : AbstractBase
|
||||
}
|
||||
}
|
||||
|
||||
// Handle all-NaN case: if no finite value was found, set state to NaN and return
|
||||
if (i == 0)
|
||||
{
|
||||
_state.LastValidValue = double.NaN;
|
||||
_state.Ssf1 = double.NaN;
|
||||
_state.Ssf2 = double.NaN;
|
||||
_state.PrevInput = double.NaN;
|
||||
Last = new TValue(DateTime.MinValue, double.NaN);
|
||||
_p_state = _state;
|
||||
return;
|
||||
}
|
||||
|
||||
for (; i < len; i++)
|
||||
{
|
||||
double val = source[i];
|
||||
@@ -234,6 +246,16 @@ public sealed class Ssf : AbstractBase
|
||||
}
|
||||
output[i] = double.NaN;
|
||||
}
|
||||
|
||||
// Handle all-NaN case: if no finite value was found, set remaining outputs to NaN and return
|
||||
if (i == len && state.Count == 0)
|
||||
{
|
||||
state.LastValidValue = double.NaN;
|
||||
state.Ssf1 = double.NaN;
|
||||
state.Ssf2 = double.NaN;
|
||||
state.PrevInput = double.NaN;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (; i < len; i++)
|
||||
|
||||
Reference in New Issue
Block a user