Refactor and enhance various channel indicators for improved performance and stability

- Updated Codacy instructions to streamline usage guidelines.
- Refactored Bbands class to utilize ArrayPool for memory management, preventing stack overflow on large series.
- Changed Fcb class to use long for monotonic deques to avoid truncation issues.
- Enhanced Kchannel class to ensure safe defaults for non-finite values.
- Improved Maenv class to prevent double-priming during calculations.
- Modified Mmchannel class to ensure non-negative buffer indices and removed unnecessary state tracking.
- Updated Pchannel class to correctly reference IsHot state.
- Refined Regchannel class to avoid double-processing during calculations.
- Enhanced Starchannel class to sanitize non-finite values during calculations.
- Adjusted Stbands.Quantower.cs to allow finer control over multiplier precision.
- Updated Ubands class to only update last valid values on new bars.
- Modified Uchannel.Quantower.cs to allow for finer multiplier precision.
- Enhanced Vwapbands classes to include standard deviation calculations and ensure consistent array lengths.
- Refactored Vwapsd classes to include standard deviation outputs and ensure consistent array lengths.
- Updated MonotonicDeque to use long for indices to prevent overflow.
- Improved Mdape class to handle zero actual values with a substitute value for error calculation.
- Enhanced Rae class to ensure correct state management during updates.
- Refined Wmape class to simplify the logic for finding last valid actual and predicted values.
- Updated Cmf.Quantower classes to ensure MinHistoryDepths reflects the current period.
This commit is contained in:
Miha Kralj
2026-01-27 23:48:33 -08:00
parent 8ac15f1efa
commit a9e72dae0d
29 changed files with 464 additions and 114 deletions
+10 -1
View File
@@ -337,16 +337,24 @@ public sealed class Vwapsd : AbstractBase
/// <summary>
/// Calculates VWAP SD Bands using span arrays.
/// </summary>
/// <param name="price">Source price values (typically HLC3)</param>
/// <param name="volume">Volume values</param>
/// <param name="upper">Output span for upper band</param>
/// <param name="lower">Output span for lower band</param>
/// <param name="vwap">Output span for VWAP values</param>
/// <param name="stdDev">Output span for standard deviation values</param>
/// <param name="numDevs">Number of standard deviations for bands (default 2.0)</param>
public static void Calculate(
ReadOnlySpan<double> price,
ReadOnlySpan<double> volume,
Span<double> upper,
Span<double> lower,
Span<double> vwap,
Span<double> stdDev,
double numDevs = DefaultNumDevs)
{
int len = price.Length;
if (len != volume.Length || len != upper.Length || len != lower.Length || len != vwap.Length)
if (len != volume.Length || len != upper.Length || len != lower.Length || len != vwap.Length || len != stdDev.Length)
{
throw new ArgumentException("All spans must have the same length.", nameof(price));
}
@@ -396,6 +404,7 @@ public sealed class Vwapsd : AbstractBase
double stdev = Math.Sqrt(variance);
vwap[i] = vwapVal;
stdDev[i] = stdev;
upper[i] = vwapVal + numDevs * stdev;
lower[i] = vwapVal - numDevs * stdev;
}