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
+4 -4
View File
@@ -215,7 +215,7 @@ public class PvrTests
}
// Batch
var batchResult = Pvr.Calculate(bars);
var batchResult = Pvr.Batch(bars);
Assert.Equal(bars.Count, batchResult.Count);
for (int i = 0; i < bars.Count; i++)
@@ -248,7 +248,7 @@ public class PvrTests
var volume = bars.Volume.Values.ToArray();
var spanOutput = new double[bars.Count];
Pvr.Calculate(price, volume, spanOutput);
Pvr.Batch(price, volume, spanOutput);
for (int i = 0; i < bars.Count; i++)
{
@@ -263,7 +263,7 @@ public class PvrTests
var volume = new double[100];
var output = new double[99]; // Different length
Assert.Throws<ArgumentException>(() => Pvr.Calculate(price, volume, output));
Assert.Throws<ArgumentException>(() => Pvr.Batch(price, volume, output));
}
[Fact]
@@ -274,7 +274,7 @@ public class PvrTests
var output = Array.Empty<double>();
// Should not throw
Pvr.Calculate(price, volume, output);
Pvr.Batch(price, volume, output);
Assert.Empty(output);
}
+4 -4
View File
@@ -49,7 +49,7 @@ public class PvrValidationTests
}
// Batch
var batchResult = Pvr.Calculate(_data.Bars);
var batchResult = Pvr.Batch(_data.Bars);
var batchValues = batchResult.Values.ToArray();
ValidationHelper.VerifyData(streamingValues.ToArray(), batchValues, 0, 100, 1e-9);
@@ -71,7 +71,7 @@ public class PvrValidationTests
var volume = _data.Bars.Volume.Values.ToArray();
var spanOutput = new double[price.Length];
Pvr.Calculate(price, volume, spanOutput);
Pvr.Batch(price, volume, spanOutput);
ValidationHelper.VerifyData(streamingValues.ToArray(), spanOutput, 0, 100, 1e-9);
}
@@ -122,14 +122,14 @@ public class PvrValidationTests
}
// Mode 3: Batch
var mode3Result = Pvr.Calculate(_data.Bars);
var mode3Result = Pvr.Batch(_data.Bars);
var mode3Values = mode3Result.Values.ToArray();
// Mode 4: Span
var price = _data.Bars.Close.Values.ToArray();
var volume = _data.Bars.Volume.Values.ToArray();
var mode4Values = new double[price.Length];
Pvr.Calculate(price, volume, mode4Values);
Pvr.Batch(price, volume, mode4Values);
// All modes should match
ValidationHelper.VerifyData(mode1Values.ToArray(), mode2Values.ToArray(), 0, 100, 1e-9);
+10 -3
View File
@@ -172,7 +172,7 @@ public sealed class Pvr : ITValuePublisher
/// <summary>
/// Calculates PVR for a series of bars.
/// </summary>
public static TSeries Calculate(TBarSeries bars)
public static TSeries Batch(TBarSeries bars)
{
if (bars.Count == 0)
{
@@ -182,7 +182,7 @@ public sealed class Pvr : ITValuePublisher
var t = bars.Open.Times.ToArray();
var v = new double[bars.Count];
Calculate(bars.Close.Values, bars.Volume.Values, v);
Batch(bars.Close.Values, bars.Volume.Values, v);
return new TSeries(t, v);
}
@@ -191,7 +191,7 @@ public sealed class Pvr : ITValuePublisher
/// Calculates PVR values using span-based processing.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Calculate(ReadOnlySpan<double> price, ReadOnlySpan<double> volume, Span<double> output)
public static void Batch(ReadOnlySpan<double> price, ReadOnlySpan<double> volume, Span<double> output)
{
if (price.Length != output.Length)
{
@@ -247,4 +247,11 @@ public sealed class Pvr : ITValuePublisher
prevVolume = currentVolume;
}
}
public static (TSeries Results, Pvr Indicator) Calculate(TBarSeries bars)
{
var indicator = new Pvr();
TSeries results = indicator.Update(bars);
return (results, indicator);
}
}