normalization of methods

This commit is contained in:
Miha Kralj
2026-02-10 21:33:16 -08:00
parent 915d7a007b
commit 6d6259a47d
527 changed files with 10525 additions and 2123 deletions
+1 -1
View File
@@ -425,7 +425,7 @@ public class CgTests
var batchResult = batchIndicator.Update(tSeries);
// Mode 3: Static Calculate
var staticResult = Cg.Calculate(tSeries, period);
var staticResult = Cg.Batch(tSeries, period);
// Mode 4: Span-based Batch
double[] sourceArray = new double[dataLen];
+2 -2
View File
@@ -219,7 +219,7 @@ public class CgValidationTests
tSeries.Add(new TValue(bar.Time, bar.Close));
}
var batch = Cg.Calculate(tSeries, period);
var batch = Cg.Batch(tSeries, period);
// Compare last values
Assert.Equal(batch[^1].Value, streaming.Last.Value, Tolerance);
@@ -241,7 +241,7 @@ public class CgValidationTests
tSeries.Add(new TValue(bar.Time, bar.Close));
}
var tSeriesResult = Cg.Calculate(tSeries, period);
var tSeriesResult = Cg.Batch(tSeries, period);
// Span approach
double[] source = new double[dataLen];
+8 -1
View File
@@ -213,7 +213,7 @@ public sealed class Cg : AbstractBase
/// <summary>
/// Calculates CG for a time series.
/// </summary>
public static TSeries Calculate(TSeries source, int period = 10)
public static TSeries Batch(TSeries source, int period = 10)
{
var cg = new Cg(period);
return cg.Update(source);
@@ -244,6 +244,13 @@ public sealed class Cg : AbstractBase
CalculateScalarCore(source, output, period);
}
public static (TSeries Results, Cg Indicator) Calculate(TSeries source, int period = 10)
{
var indicator = new Cg(period);
TSeries results = indicator.Update(source);
return (results, indicator);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void CalculateScalarCore(ReadOnlySpan<double> source, Span<double> output, int period)
{
+1 -1
View File
@@ -298,7 +298,7 @@ public class DspTests
tSeries.Add(new TValue(bar.Time, bar.Close));
}
var batch = Dsp.Calculate(tSeries, period);
var batch = Dsp.Batch(tSeries, period);
// Compare last values
Assert.Equal(batch[^1].Value, streaming.Last.Value, Tolerance);
+2 -2
View File
@@ -205,7 +205,7 @@ public class DspValidationTests
tSeries.Add(new TValue(bar.Time, bar.Close));
}
var batch = Dsp.Calculate(tSeries, period);
var batch = Dsp.Batch(tSeries, period);
// Compare last values
Assert.Equal(batch[^1].Value, streaming.Last.Value, Tolerance);
@@ -227,7 +227,7 @@ public class DspValidationTests
tSeries.Add(new TValue(bar.Time, bar.Close));
}
var tSeriesResult = Dsp.Calculate(tSeries, period);
var tSeriesResult = Dsp.Batch(tSeries, period);
// Span approach
double[] source = new double[dataLen];
+8 -1
View File
@@ -210,7 +210,7 @@ public sealed class Dsp : AbstractBase
/// <summary>
/// Calculates DSP for a time series.
/// </summary>
public static TSeries Calculate(TSeries source, int period = 40)
public static TSeries Batch(TSeries source, int period = 40)
{
var dsp = new Dsp(period);
return dsp.Update(source);
@@ -290,4 +290,11 @@ public sealed class Dsp : AbstractBase
output[i] = emaFast - emaSlow;
}
}
public static (TSeries Results, Dsp Indicator) Calculate(TSeries source, int period = 40)
{
var indicator = new Dsp(period);
TSeries results = indicator.Update(source);
return (results, indicator);
}
}
+1 -1
View File
@@ -321,7 +321,7 @@ public class EacpTests
tSeries.Add(new TValue(bar.Time, bar.Close));
}
var batch = Eacp.Calculate(tSeries, minPeriod, maxPeriod);
var batch = Eacp.Batch(tSeries, minPeriod, maxPeriod);
// Compare last values
Assert.Equal(batch[^1].Value, streaming.Last.Value, Tolerance);
+2 -2
View File
@@ -196,7 +196,7 @@ public class EacpValidationTests
tSeries.Add(new TValue(bar.Time, bar.Close));
}
var batch = Eacp.Calculate(tSeries, minPeriod, maxPeriod);
var batch = Eacp.Batch(tSeries, minPeriod, maxPeriod);
// Compare last values
Assert.Equal(batch[^1].Value, streaming.Last.Value, Tolerance);
@@ -219,7 +219,7 @@ public class EacpValidationTests
tSeries.Add(new TValue(bar.Time, bar.Close));
}
var tSeriesResult = Eacp.Calculate(tSeries, minPeriod, maxPeriod);
var tSeriesResult = Eacp.Batch(tSeries, minPeriod, maxPeriod);
// Span approach
double[] source = new double[dataLen];
+8 -1
View File
@@ -405,7 +405,7 @@ public sealed class Eacp : AbstractBase
/// <summary>
/// Calculates EACP for a time series.
/// </summary>
public static TSeries Calculate(TSeries source, int minPeriod = 8, int maxPeriod = 48,
public static TSeries Batch(TSeries source, int minPeriod = 8, int maxPeriod = 48,
int avgLength = 3, bool enhance = true)
{
var eacp = new Eacp(minPeriod, maxPeriod, avgLength, enhance);
@@ -447,4 +447,11 @@ public sealed class Eacp : AbstractBase
output[i] = result.Value;
}
}
public static (TSeries Results, Eacp Indicator) Calculate(TSeries source, int minPeriod = 8, int maxPeriod = 48, int avgLength = 3, bool enhance = true)
{
var indicator = new Eacp(minPeriod, maxPeriod, avgLength, enhance);
TSeries results = indicator.Update(source);
return (results, indicator);
}
}
+1 -1
View File
@@ -320,7 +320,7 @@ public class EbswTests
tSeries.Add(new TValue(bar.Time, bar.Close));
}
var batch = Ebsw.Calculate(tSeries, hpLength, ssfLength);
var batch = Ebsw.Batch(tSeries, hpLength, ssfLength);
// Compare last values
Assert.Equal(batch[^1].Value, streaming.Last.Value, Tolerance);
+2 -2
View File
@@ -296,7 +296,7 @@ public class EbswValidationTests
tSeries.Add(new TValue(bar.Time, bar.Close));
}
var batch = Ebsw.Calculate(tSeries, hpLength, ssfLength);
var batch = Ebsw.Batch(tSeries, hpLength, ssfLength);
// Compare last values
Assert.Equal(batch[^1].Value, streaming.Last.Value, Tolerance);
@@ -319,7 +319,7 @@ public class EbswValidationTests
tSeries.Add(new TValue(bar.Time, bar.Close));
}
var tSeriesResult = Ebsw.Calculate(tSeries, hpLength, ssfLength);
var tSeriesResult = Ebsw.Batch(tSeries, hpLength, ssfLength);
// Span approach
double[] source = new double[dataLen];
+8 -1
View File
@@ -246,7 +246,7 @@ public sealed class Ebsw : AbstractBase
/// <summary>
/// Calculates EBSW for a time series.
/// </summary>
public static TSeries Calculate(TSeries source, int hpLength = 40, int ssfLength = 10)
public static TSeries Batch(TSeries source, int hpLength = 40, int ssfLength = 10)
{
var ebsw = new Ebsw(hpLength, ssfLength);
return ebsw.Update(source);
@@ -337,4 +337,11 @@ public sealed class Ebsw : AbstractBase
filt1 = filt0;
}
}
public static (TSeries Results, Ebsw Indicator) Calculate(TSeries source, int hpLength = 40, int ssfLength = 10)
{
var indicator = new Ebsw(hpLength, ssfLength);
TSeries results = indicator.Update(source);
return (results, indicator);
}
}
+1 -1
View File
@@ -297,7 +297,7 @@ public class HomodTests
tSeries.Add(new TValue(bar.Time, bar.Close));
}
var batch = Homod.Calculate(tSeries, minPeriod, maxPeriod);
var batch = Homod.Batch(tSeries, minPeriod, maxPeriod);
// Compare last values
Assert.Equal(batch[^1].Value, streaming.Last.Value, Tolerance);
+1 -1
View File
@@ -160,7 +160,7 @@ public class HomodValidationTests
{
tSeries.Add(new TValue(bar.Time, bar.Close));
}
var tSeriesResult = Homod.Calculate(tSeries, 6, 50);
var tSeriesResult = Homod.Batch(tSeries, 6, 50);
// Compare all values
for (int i = 0; i < bars.Count; i++)
+8 -1
View File
@@ -381,7 +381,7 @@ public sealed class Homod : AbstractBase
/// <summary>
/// Calculates Homodyne Discriminator for a time series.
/// </summary>
public static TSeries Calculate(TSeries source, double minPeriod = 6.0, double maxPeriod = 50.0)
public static TSeries Batch(TSeries source, double minPeriod = 6.0, double maxPeriod = 50.0)
{
var homod = new Homod(minPeriod, maxPeriod);
return homod.Update(source);
@@ -421,4 +421,11 @@ public sealed class Homod : AbstractBase
output[i] = result.Value;
}
}
public static (TSeries Results, Homod Indicator) Calculate(TSeries source, double minPeriod = 6.0, double maxPeriod = 50.0)
{
var indicator = new Homod(minPeriod, maxPeriod);
TSeries results = indicator.Update(source);
return (results, indicator);
}
}
+9 -2
View File
@@ -402,7 +402,7 @@ public sealed class HtDcperiod : AbstractBase
}
}
public static void Calculate(ReadOnlySpan<double> source, Span<double> output)
public static void Batch(ReadOnlySpan<double> source, Span<double> output)
{
if (output.Length < source.Length)
{
@@ -416,9 +416,16 @@ public sealed class HtDcperiod : AbstractBase
}
}
public static TSeries Calculate(TSeries source)
public static TSeries Batch(TSeries source)
{
var ht = new HtDcperiod();
return ht.Update(source);
}
public static (TSeries Results, HtDcperiod Indicator) Calculate(TSeries source)
{
var indicator = new HtDcperiod();
TSeries results = indicator.Update(source);
return (results, indicator);
}
}
+9 -2
View File
@@ -472,7 +472,7 @@ public sealed class HtDcphase : AbstractBase
}
}
public static void Calculate(ReadOnlySpan<double> source, Span<double> output)
public static void Batch(ReadOnlySpan<double> source, Span<double> output)
{
if (output.Length < source.Length)
{
@@ -486,9 +486,16 @@ public sealed class HtDcphase : AbstractBase
}
}
public static TSeries Calculate(TSeries source)
public static TSeries Batch(TSeries source)
{
var ht = new HtDcphase();
return ht.Update(source);
}
public static (TSeries Results, HtDcphase Indicator) Calculate(TSeries source)
{
var indicator = new HtDcphase();
TSeries results = indicator.Update(source);
return (results, indicator);
}
}
+9 -2
View File
@@ -415,7 +415,7 @@ public sealed class HtPhasor : AbstractBase
/// <summary>
/// Calculates HT_PHASOR for a time series.
/// </summary>
public static TSeries Calculate(TSeries source)
public static TSeries Batch(TSeries source)
{
var htPhasor = new HtPhasor();
return htPhasor.Update(source);
@@ -453,4 +453,11 @@ public sealed class HtPhasor : AbstractBase
quadrature[i] = htPhasor.Quadrature;
}
}
}
public static (TSeries Results, HtPhasor Indicator) Calculate(TSeries source)
{
var indicator = new HtPhasor();
TSeries results = indicator.Update(source);
return (results, indicator);
}
}
+1 -1
View File
@@ -300,7 +300,7 @@ public class HtSineTests
tSeries.Add(new TValue(bar.Time, bar.Close));
}
var batch = HtSine.Calculate(tSeries);
var batch = HtSine.Batch(tSeries);
// Compare last values
Assert.Equal(batch[^1].Value, streaming.Last.Value, Tolerance);
+8 -1
View File
@@ -496,7 +496,7 @@ public sealed class HtSine : AbstractBase
/// <summary>
/// Calculates HT_SINE for a time series.
/// </summary>
public static TSeries Calculate(TSeries source)
public static TSeries Batch(TSeries source)
{
var htSine = new HtSine();
return htSine.Update(source);
@@ -534,4 +534,11 @@ public sealed class HtSine : AbstractBase
leadSine[i] = htSine.LeadSine;
}
}
public static (TSeries Results, HtSine Indicator) Calculate(TSeries source)
{
var indicator = new HtSine();
TSeries results = indicator.Update(source);
return (results, indicator);
}
}
+1 -1
View File
@@ -171,7 +171,7 @@ public class LunarTests
series.Add(new TValue(startDate.AddDays(i), 100.0 + i));
}
var result = Lunar.Calculate(series);
var result = Lunar.Batch(series);
Assert.Equal(30, result.Count);
+8 -1
View File
@@ -91,7 +91,7 @@ public sealed class Lunar : AbstractBase
/// <summary>
/// Creates a new Lunar indicator and calculates phases for the source series.
/// </summary>
public static TSeries Calculate(TSeries source)
public static TSeries Batch(TSeries source)
{
var lunar = new Lunar();
return lunar.Update(source);
@@ -114,6 +114,13 @@ public sealed class Lunar : AbstractBase
}
}
public static (TSeries Results, Lunar Indicator) Calculate(TSeries source)
{
var indicator = new Lunar();
TSeries results = indicator.Update(source);
return (results, indicator);
}
/// <summary>
/// Calculates lunar phase for a specific DateTime.
/// </summary>
+3 -3
View File
@@ -185,7 +185,7 @@ public class SineTests
series.Add(new TValue(bar.Time, bar.Close));
}
var result = Sine.Calculate(series);
var result = Sine.Batch(series);
Assert.Equal(100, result.Count);
}
@@ -201,7 +201,7 @@ public class SineTests
series.Add(new TValue(bar.Time, bar.Close));
}
var result = Sine.Calculate(series, hpPeriod: 20, ssfPeriod: 5);
var result = Sine.Batch(series, hpPeriod: 20, ssfPeriod: 5);
Assert.Equal(100, result.Count);
}
@@ -252,7 +252,7 @@ public class SineTests
}
// Batch calculation
var batchResult = Sine.Calculate(series);
var batchResult = Sine.Batch(series);
// Compare last 100 values (after warmup)
for (int i = 100; i < 200; i++)
+9 -2
View File
@@ -215,12 +215,19 @@ public sealed class Sine : AbstractBase
/// <summary>
/// Creates a new Sine indicator and calculates for the source series.
/// </summary>
public static TSeries Calculate(TSeries source, int hpPeriod = 40, int ssfPeriod = 10)
public static TSeries Batch(TSeries source, int hpPeriod = 40, int ssfPeriod = 10)
{
var sine = new Sine(hpPeriod, ssfPeriod);
return sine.Update(source);
}
public static (TSeries Results, Sine Indicator) Calculate(TSeries source, int hpPeriod = 40, int ssfPeriod = 10)
{
var indicator = new Sine(hpPeriod, ssfPeriod);
TSeries results = indicator.Update(source);
return (results, indicator);
}
public override void Reset()
{
_srcBuffer.Clear();
@@ -240,4 +247,4 @@ public sealed class Sine : AbstractBase
Update(new TValue(baseTime + (interval * i), source[i]), true);
}
}
}
}
+1 -1
View File
@@ -160,7 +160,7 @@ public class SolarTests
series.Add(new TValue(startDate.AddDays(i), 100.0 + i));
}
var result = Solar.Calculate(series);
var result = Solar.Batch(series);
Assert.Equal(30, result.Count);
+8 -1
View File
@@ -91,7 +91,7 @@ public sealed class Solar : AbstractBase
/// <summary>
/// Creates a new Solar indicator and calculates cycles for the source series.
/// </summary>
public static TSeries Calculate(TSeries source)
public static TSeries Batch(TSeries source)
{
var solar = new Solar();
return solar.Update(source);
@@ -114,6 +114,13 @@ public sealed class Solar : AbstractBase
}
}
public static (TSeries Results, Solar Indicator) Calculate(TSeries source)
{
var indicator = new Solar();
TSeries results = indicator.Update(source);
return (results, indicator);
}
/// <summary>
/// Calculates solar cycle for a specific DateTime.
/// </summary>
+1 -1
View File
@@ -307,7 +307,7 @@ public class SsfdspTests
tSeries.Add(new TValue(bar.Time, bar.Close));
}
var batch = Ssfdsp.Calculate(tSeries, period);
var batch = Ssfdsp.Batch(tSeries, period);
// Compare last values
Assert.Equal(batch[^1].Value, streaming.Last.Value, Tolerance);
+1 -1
View File
@@ -292,7 +292,7 @@ public class SsfdspValidationTests
}
// TSeries Calculate
var tsResult = Ssfdsp.Calculate(tSeries, period);
var tsResult = Ssfdsp.Batch(tSeries, period);
// Streaming
var streaming = new Ssfdsp(period);
+8 -1
View File
@@ -229,7 +229,7 @@ public sealed class Ssfdsp : AbstractBase
/// <summary>
/// Calculates SSF-DSP for a time series.
/// </summary>
public static TSeries Calculate(TSeries source, int period = 40)
public static TSeries Batch(TSeries source, int period = 40)
{
var ssfdsp = new Ssfdsp(period);
return ssfdsp.Update(source);
@@ -328,4 +328,11 @@ public sealed class Ssfdsp : AbstractBase
output[i] = ssfFast - ssfSlow;
}
}
public static (TSeries Results, Ssfdsp Indicator) Calculate(TSeries source, int period = 40)
{
var indicator = new Ssfdsp(period);
TSeries results = indicator.Update(source);
return (results, indicator);
}
}
+1 -1
View File
@@ -93,7 +93,7 @@ public class StcTests
var batchStc = CreateDefaultStc();
var tseriesResult = batchStc.Update(series);
Stc.Calculate(input.AsSpan(), output.AsSpan(), kPeriod: CycleLength, dPeriod: CycleLength, fastLength: FastLength, slowLength: SlowLength, smoothing: StcSmoothing.Sigmoid);
Stc.Batch(input.AsSpan(), output.AsSpan(), kPeriod: CycleLength, dPeriod: CycleLength, fastLength: FastLength, slowLength: SlowLength, smoothing: StcSmoothing.Sigmoid);
// Compare last value
Assert.Equal(tseriesResult.Last.Value, output[^1], 1e-9);
+10 -3
View File
@@ -473,7 +473,7 @@ public sealed class Stc : AbstractBase
/// <summary>
/// Static convenience method that creates a new Stc instance and processes the entire series.
/// </summary>
public static TSeries Calculate(TSeries source, int kPeriod = 10, int dPeriod = 3, int fastLength = 23, int slowLength = 50, StcSmoothing smoothing = StcSmoothing.Ema)
public static TSeries Batch(TSeries source, int kPeriod = 10, int dPeriod = 3, int fastLength = 23, int slowLength = 50, StcSmoothing smoothing = StcSmoothing.Ema)
{
var indicator = new Stc(kPeriod, dPeriod, fastLength, slowLength, smoothing);
return indicator.Update(source);
@@ -483,7 +483,7 @@ public sealed class Stc : AbstractBase
// replicate the full STC state machine inline for zero-allocation performance.
// The sequential MACD→Stoch1→Stoch2→Smoothing pipeline cannot be decomposed
// without introducing heap allocations or sacrificing inlining opportunities.
public static void Calculate(ReadOnlySpan<double> source, Span<double> output,
public static void Batch(ReadOnlySpan<double> source, Span<double> output,
int kPeriod = 10, int dPeriod = 3, int fastLength = 23, int slowLength = 50, StcSmoothing smoothing = StcSmoothing.Ema)
{
if (source.Length != output.Length)
@@ -665,4 +665,11 @@ public sealed class Stc : AbstractBase
}
}
}
}
public static (TSeries Results, Stc Indicator) Calculate(TSeries source, int kPeriod = 10, int dPeriod = 3, int fastLength = 23, int slowLength = 50, StcSmoothing smoothing = StcSmoothing.Ema)
{
var indicator = new Stc(kPeriod, dPeriod, fastLength, slowLength, smoothing);
TSeries results = indicator.Update(source);
return (results, indicator);
}
}