mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-23 13:08:04 +00:00
Enhance code quality and stability across various modules
- Updated .coderabbit.yaml to exclude additional file types from reviews, improving the focus on relevant code changes. - Modified scanner.sh to handle test failures more gracefully, ensuring that analysis stops on test failures and improving logging. - Improved sonarscanner.sh to ensure build and test failures are properly reported, enhancing CI reliability. - Refined SimdExtensions.cs documentation for clarity on variance calculation methods. - Cleaned up TSeries.Tests.cs by simplifying the test structure and ensuring proper namespace usage. - Fixed potential issues in tseries.cs by ensuring correct handling of DateTime values. - Enhanced CsvFeed.cs to improve error handling during CSV parsing, ensuring robustness against malformed data. - Updated GBM.cs to correctly calculate volume in the current bar, ensuring accurate simulation. - Adjusted index.html to use globalThis for better compatibility across environments. - Refined quantalib.csproj to exclude unnecessary files from compilation, streamlining the build process. - Added comprehensive tests for the Mama class to ensure correct behavior during updates and state management. - Improved error handling in various trend classes (Kama, Dema, Ema, T3, Tema, Wma) to ensure NaN values are managed correctly. - Removed redundant Mama.Repro.Tests.cs file and consolidated tests into Mama.Tests.cs for better organization. - Enhanced T3 and Tema classes to maintain state integrity during updates, particularly with NaN values.
This commit is contained in:
+19
-6
@@ -75,6 +75,7 @@ public sealed class Kama : ITValuePublisher
|
||||
|
||||
Name = $"Kama({period}, {fastPeriod}, {slowPeriod})";
|
||||
_kama = double.NaN;
|
||||
_lastValidValue = double.NaN;
|
||||
}
|
||||
|
||||
public Kama(ITValuePublisher source, int period = 10, int fastPeriod = 2, int slowPeriod = 30)
|
||||
@@ -98,6 +99,12 @@ public sealed class Kama : ITValuePublisher
|
||||
public TValue Update(TValue input, bool isNew = true)
|
||||
{
|
||||
double val = GetValidValue(input.Value);
|
||||
if (double.IsNaN(val))
|
||||
{
|
||||
Last = new TValue(input.Time, double.NaN);
|
||||
Pub?.Invoke(Last);
|
||||
return Last;
|
||||
}
|
||||
|
||||
if (isNew)
|
||||
{
|
||||
@@ -190,11 +197,11 @@ public sealed class Kama : ITValuePublisher
|
||||
v.Add(outputSpan[i]);
|
||||
}
|
||||
|
||||
// Restore state by replaying last few bars
|
||||
// This is expensive but necessary to sync the object state
|
||||
// Restore state by replaying the entire series
|
||||
// This is expensive but necessary to sync the object state correctly
|
||||
// because KAMA is recursive (IIR) and depends on the full history.
|
||||
Reset();
|
||||
int startIndex = Math.Max(0, len - _period - 1);
|
||||
for (int i = startIndex; i < len; i++)
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
Update(source[i]);
|
||||
}
|
||||
@@ -220,7 +227,7 @@ public sealed class Kama : ITValuePublisher
|
||||
double volatilitySum = 0;
|
||||
double kama = 0;
|
||||
bool kamaInitialized = false;
|
||||
double lastValid = 0;
|
||||
double lastValid = double.NaN;
|
||||
|
||||
for (int i = 0; i < source.Length; i++)
|
||||
{
|
||||
@@ -230,6 +237,12 @@ public sealed class Kama : ITValuePublisher
|
||||
else
|
||||
val = lastValid;
|
||||
|
||||
if (double.IsNaN(val))
|
||||
{
|
||||
output[i] = double.NaN;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add to buffer
|
||||
double removed = buffer[bufferIdx];
|
||||
buffer[bufferIdx] = val;
|
||||
@@ -298,7 +311,7 @@ public sealed class Kama : ITValuePublisher
|
||||
_volatilitySum = 0;
|
||||
_p_volatilitySum = 0;
|
||||
_lastDiffOut = 0;
|
||||
_lastValidValue = 0;
|
||||
_lastValidValue = double.NaN;
|
||||
Last = default;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user