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
+8 -8
View File
@@ -318,7 +318,7 @@ public class PvoTests
}
// Batch
var batchResult = Pvo.Calculate(bars);
var batchResult = Pvo.Batch(bars);
Assert.Equal(bars.Count, batchResult.Count);
for (int i = 0; i < bars.Count; i++)
@@ -357,7 +357,7 @@ public class PvoTests
var spanSignal = new double[bars.Count];
var spanHistogram = new double[bars.Count];
Pvo.Calculate(volume, spanPvo, spanSignal, spanHistogram);
Pvo.Batch(volume, spanPvo, spanSignal, spanHistogram);
for (int i = 0; i < bars.Count; i++)
{
@@ -375,7 +375,7 @@ public class PvoTests
var signal = new double[100];
var histogram = new double[100];
Assert.Throws<ArgumentException>(() => Pvo.Calculate(volume, output, signal, histogram));
Assert.Throws<ArgumentException>(() => Pvo.Batch(volume, output, signal, histogram));
}
[Fact]
@@ -386,7 +386,7 @@ public class PvoTests
var signal = new double[100];
var histogram = new double[100];
Assert.Throws<ArgumentException>(() => Pvo.Calculate(volume, output, signal, histogram, fastPeriod: 0));
Assert.Throws<ArgumentException>(() => Pvo.Batch(volume, output, signal, histogram, fastPeriod: 0));
}
[Fact]
@@ -397,7 +397,7 @@ public class PvoTests
var signal = new double[100];
var histogram = new double[100];
Assert.Throws<ArgumentException>(() => Pvo.Calculate(volume, output, signal, histogram, slowPeriod: 0));
Assert.Throws<ArgumentException>(() => Pvo.Batch(volume, output, signal, histogram, slowPeriod: 0));
}
[Fact]
@@ -408,7 +408,7 @@ public class PvoTests
var signal = new double[100];
var histogram = new double[100];
Assert.Throws<ArgumentException>(() => Pvo.Calculate(volume, output, signal, histogram, signalPeriod: 0));
Assert.Throws<ArgumentException>(() => Pvo.Batch(volume, output, signal, histogram, signalPeriod: 0));
}
[Fact]
@@ -419,7 +419,7 @@ public class PvoTests
var signal = new double[100];
var histogram = new double[100];
Assert.Throws<ArgumentException>(() => Pvo.Calculate(volume, output, signal, histogram, fastPeriod: 26, slowPeriod: 26));
Assert.Throws<ArgumentException>(() => Pvo.Batch(volume, output, signal, histogram, fastPeriod: 26, slowPeriod: 26));
}
[Fact]
@@ -431,7 +431,7 @@ public class PvoTests
var histogram = Array.Empty<double>();
// Should not throw
Pvo.Calculate(volume, output, signal, histogram);
Pvo.Batch(volume, output, signal, histogram);
Assert.Empty(output);
}
+4 -4
View File
@@ -73,7 +73,7 @@ public class PvoValidationTests
}
// Batch
var batchResult = Pvo.Calculate(_data.Bars, DefaultFastPeriod, DefaultSlowPeriod, DefaultSignalPeriod);
var batchResult = Pvo.Batch(_data.Bars, DefaultFastPeriod, DefaultSlowPeriod, DefaultSignalPeriod);
var batchValues = batchResult.Values.ToArray();
ValidationHelper.VerifyData(streamingValues.ToArray(), batchValues, 0, 100, 1e-9);
@@ -101,7 +101,7 @@ public class PvoValidationTests
var spanSignal = new double[volume.Length];
var spanHistogram = new double[volume.Length];
Pvo.Calculate(volume, spanPvo, spanSignal, spanHistogram, DefaultFastPeriod, DefaultSlowPeriod, DefaultSignalPeriod);
Pvo.Batch(volume, spanPvo, spanSignal, spanHistogram, DefaultFastPeriod, DefaultSlowPeriod, DefaultSignalPeriod);
ValidationHelper.VerifyData(streamingPvo.ToArray(), spanPvo, 0, 100, 1e-9);
ValidationHelper.VerifyData(streamingSignal.ToArray(), spanSignal, 0, 100, 1e-9);
@@ -212,7 +212,7 @@ public class PvoValidationTests
}
// Mode 3: Batch
var mode3Result = Pvo.Calculate(_data.Bars, DefaultFastPeriod, DefaultSlowPeriod, DefaultSignalPeriod);
var mode3Result = Pvo.Batch(_data.Bars, DefaultFastPeriod, DefaultSlowPeriod, DefaultSignalPeriod);
var mode3Values = mode3Result.Values.ToArray();
// Mode 4: Span
@@ -220,7 +220,7 @@ public class PvoValidationTests
var mode4Values = new double[volume.Length];
var mode4Signal = new double[volume.Length];
var mode4Histogram = new double[volume.Length];
Pvo.Calculate(volume, mode4Values, mode4Signal, mode4Histogram, DefaultFastPeriod, DefaultSlowPeriod, DefaultSignalPeriod);
Pvo.Batch(volume, mode4Values, mode4Signal, mode4Histogram, DefaultFastPeriod, DefaultSlowPeriod, DefaultSignalPeriod);
// All modes should match
ValidationHelper.VerifyData(mode1Values.ToArray(), mode2Values.ToArray(), 0, 100, 1e-9);
+10 -3
View File
@@ -268,7 +268,7 @@ public sealed class Pvo : ITValuePublisher
/// <param name="slowPeriod">The slow EMA period</param>
/// <param name="signalPeriod">The signal line EMA period</param>
/// <returns>A TSeries containing the PVO values</returns>
public static TSeries Calculate(TBarSeries bars, int fastPeriod = 12, int slowPeriod = 26, int signalPeriod = 9)
public static TSeries Batch(TBarSeries bars, int fastPeriod = 12, int slowPeriod = 26, int signalPeriod = 9)
{
if (bars.Count == 0)
{
@@ -280,7 +280,7 @@ public sealed class Pvo : ITValuePublisher
var signal = new double[bars.Count];
var histogram = new double[bars.Count];
Calculate(bars.Volume.Values, v, signal, histogram, fastPeriod, slowPeriod, signalPeriod);
Batch(bars.Volume.Values, v, signal, histogram, fastPeriod, slowPeriod, signalPeriod);
return new TSeries(t, v);
}
@@ -297,7 +297,7 @@ public sealed class Pvo : 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> volume, Span<double> output, Span<double> signal,
public static void Batch(ReadOnlySpan<double> volume, Span<double> output, Span<double> signal,
Span<double> histogram, int fastPeriod = 12, int slowPeriod = 26, int signalPeriod = 9)
{
if (volume.Length != output.Length)
@@ -400,4 +400,11 @@ public sealed class Pvo : ITValuePublisher
histogram[i] = pvoValue - signalValue;
}
}
public static (TSeries Results, Pvo Indicator) Calculate(TBarSeries bars, int fastPeriod = 12, int slowPeriod = 26, int signalPeriod = 9)
{
var indicator = new Pvo(fastPeriod, slowPeriod, signalPeriod);
TSeries results = indicator.Update(bars);
return (results, indicator);
}
}