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
+7 -7
View File
@@ -306,7 +306,7 @@ public class KvoTests
}
// Batch
var batchResult = Kvo.Calculate(bars);
var batchResult = Kvo.Batch(bars);
Assert.Equal(bars.Count, batchResult.Count);
for (int i = 0; i < bars.Count; i++)
@@ -345,7 +345,7 @@ public class KvoTests
var spanKvo = new double[bars.Count];
var spanSignal = new double[bars.Count];
Kvo.Calculate(high, low, close, volume, spanKvo, spanSignal);
Kvo.Batch(high, low, close, volume, spanKvo, spanSignal);
for (int i = 0; i < bars.Count; i++)
{
@@ -364,7 +364,7 @@ public class KvoTests
var output = new double[100];
var signal = new double[100];
Assert.Throws<ArgumentException>(() => Kvo.Calculate(high, low, close, volume, output, signal));
Assert.Throws<ArgumentException>(() => Kvo.Batch(high, low, close, volume, output, signal));
}
[Fact]
@@ -377,7 +377,7 @@ public class KvoTests
var output = new double[100];
var signal = new double[100];
Assert.Throws<ArgumentException>(() => Kvo.Calculate(high, low, close, volume, output, signal, fastPeriod: 0));
Assert.Throws<ArgumentException>(() => Kvo.Batch(high, low, close, volume, output, signal, fastPeriod: 0));
}
[Fact]
@@ -390,7 +390,7 @@ public class KvoTests
var output = new double[100];
var signal = new double[100];
Assert.Throws<ArgumentException>(() => Kvo.Calculate(high, low, close, volume, output, signal, slowPeriod: 0));
Assert.Throws<ArgumentException>(() => Kvo.Batch(high, low, close, volume, output, signal, slowPeriod: 0));
}
[Fact]
@@ -403,7 +403,7 @@ public class KvoTests
var output = new double[100];
var signal = new double[100];
Assert.Throws<ArgumentException>(() => Kvo.Calculate(high, low, close, volume, output, signal, signalPeriod: 0));
Assert.Throws<ArgumentException>(() => Kvo.Batch(high, low, close, volume, output, signal, signalPeriod: 0));
}
[Fact]
@@ -417,7 +417,7 @@ public class KvoTests
var signal = Array.Empty<double>();
// Should not throw
Kvo.Calculate(high, low, close, volume, output, signal);
Kvo.Batch(high, low, close, volume, output, signal);
// Verify arrays remain empty (no out-of-bounds writes)
Assert.Empty(output);
+2 -2
View File
@@ -75,7 +75,7 @@ public class KvoValidationTests
}
// Batch
var batchResult = Kvo.Calculate(_data.Bars, DefaultFastPeriod, DefaultSlowPeriod, DefaultSignalPeriod);
var batchResult = Kvo.Batch(_data.Bars, DefaultFastPeriod, DefaultSlowPeriod, DefaultSignalPeriod);
var batchValues = batchResult.Values.ToArray();
ValidationHelper.VerifyData(streamingValues.ToArray(), batchValues, 0, 100, 1e-9);
@@ -103,7 +103,7 @@ public class KvoValidationTests
var spanKvo = new double[high.Length];
var spanSignal = new double[high.Length];
Kvo.Calculate(high, low, close, volume, spanKvo, spanSignal, DefaultFastPeriod, DefaultSlowPeriod, DefaultSignalPeriod);
Kvo.Batch(high, low, close, volume, spanKvo, spanSignal, DefaultFastPeriod, DefaultSlowPeriod, DefaultSignalPeriod);
ValidationHelper.VerifyData(streamingKvo.ToArray(), spanKvo, 0, 100, 1e-9);
ValidationHelper.VerifyData(streamingSignal.ToArray(), spanSignal, 0, 100, 1e-9);
+10 -3
View File
@@ -303,7 +303,7 @@ public sealed class Kvo : ITValuePublisher
/// <param name="slowPeriod">The slow EMA period</param>
/// <param name="signalPeriod">The signal line EMA period</param>
/// <returns>A TSeries containing the KVO values</returns>
public static TSeries Calculate(TBarSeries bars, int fastPeriod = 34, int slowPeriod = 55, int signalPeriod = 13)
public static TSeries Batch(TBarSeries bars, int fastPeriod = 34, int slowPeriod = 55, int signalPeriod = 13)
{
if (bars.Count == 0)
{
@@ -314,7 +314,7 @@ public sealed class Kvo : ITValuePublisher
var v = new double[bars.Count];
var signal = new double[bars.Count];
Calculate(bars.High.Values, bars.Low.Values, bars.Close.Values, bars.Volume.Values,
Batch(bars.High.Values, bars.Low.Values, bars.Close.Values, bars.Volume.Values,
v, signal, fastPeriod, slowPeriod, signalPeriod);
return new TSeries(t, v);
@@ -334,7 +334,7 @@ public sealed class Kvo : ITValuePublisher
/// <param name="signalPeriod">The signal line EMA period</param>
/// <exception cref="ArgumentException">Thrown when spans have different lengths or parameters are invalid</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Calculate(ReadOnlySpan<double> high, ReadOnlySpan<double> low,
public static void Batch(ReadOnlySpan<double> high, ReadOnlySpan<double> low,
ReadOnlySpan<double> close, ReadOnlySpan<double> volume,
Span<double> output, Span<double> signal,
int fastPeriod = 34, int slowPeriod = 55, int signalPeriod = 13)
@@ -478,4 +478,11 @@ public sealed class Kvo : ITValuePublisher
prevHlc3 = hlc3;
}
}
public static (TSeries Results, Kvo Indicator) Calculate(TBarSeries bars, int fastPeriod = 34, int slowPeriod = 55, int signalPeriod = 13)
{
var indicator = new Kvo(fastPeriod, slowPeriod, signalPeriod);
TSeries results = indicator.Update(bars);
return (results, indicator);
}
}