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
+6 -6
View File
@@ -265,7 +265,7 @@ public class PvtTests
streamingResults[i] = pvtStreaming.Update(bars[i]).Value;
}
var batchResult = Pvt.Calculate(bars);
var batchResult = Pvt.Batch(bars);
// Compare last 45 values (after warmup)
for (int i = 5; i < bars.Count; i++)
@@ -299,7 +299,7 @@ public class PvtTests
}
var spanResult = new double[bars.Count];
Pvt.Calculate(close, volume, spanResult);
Pvt.Batch(close, volume, spanResult);
// Compare values after first bar
for (int i = 1; i < bars.Count; i++)
@@ -343,7 +343,7 @@ public class PvtTests
var volume = new double[8]; // Different length
var output = new double[10];
Assert.Throws<ArgumentException>(() => Pvt.Calculate(close, volume, output));
Assert.Throws<ArgumentException>(() => Pvt.Batch(close, volume, output));
}
[Fact]
@@ -353,7 +353,7 @@ public class PvtTests
var volume = new double[10];
var output = new double[8]; // Wrong length
Assert.Throws<ArgumentException>(() => Pvt.Calculate(close, volume, output));
Assert.Throws<ArgumentException>(() => Pvt.Batch(close, volume, output));
}
[Fact]
@@ -363,7 +363,7 @@ public class PvtTests
var volume = Array.Empty<double>();
var output = Array.Empty<double>();
Pvt.Calculate(close, volume, output); // Should not throw
Pvt.Batch(close, volume, output); // Should not throw
Assert.Empty(output);
}
@@ -374,7 +374,7 @@ public class PvtTests
var volume = new double[] { 1000.0 };
var output = new double[1];
Pvt.Calculate(close, volume, output);
Pvt.Batch(close, volume, output);
Assert.Equal(0.0, output[0]);
}
+2 -2
View File
@@ -59,7 +59,7 @@ public class PvtValidationTests
}
// Batch
var batchResult = Pvt.Calculate(_data.Bars);
var batchResult = Pvt.Batch(_data.Bars);
var batchValues = batchResult.Values.ToArray();
ValidationHelper.VerifyData(streamingValues.ToArray(), batchValues, 0, 100, 1e-9);
@@ -81,7 +81,7 @@ public class PvtValidationTests
var volume = _data.Bars.Volume.Values.ToArray();
var spanOutput = new double[close.Length];
Pvt.Calculate(close, volume, spanOutput);
Pvt.Batch(close, volume, spanOutput);
ValidationHelper.VerifyData(streamingValues.ToArray(), spanOutput, 0, 100, 1e-9);
}
+10 -3
View File
@@ -230,7 +230,7 @@ public sealed class Pvt : ITValuePublisher
return new TSeries(t, v);
}
public static TSeries Calculate(TBarSeries source)
public static TSeries Batch(TBarSeries source)
{
if (source.Count == 0)
{
@@ -240,13 +240,13 @@ public sealed class Pvt : ITValuePublisher
var t = source.Open.Times.ToArray();
var v = new double[source.Count];
Calculate(source.Close.Values, source.Volume.Values, v);
Batch(source.Close.Values, source.Volume.Values, v);
return new TSeries(t, v);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Calculate(ReadOnlySpan<double> close, ReadOnlySpan<double> volume, Span<double> output)
public static void Batch(ReadOnlySpan<double> close, ReadOnlySpan<double> volume, Span<double> output)
{
if (close.Length != volume.Length)
{
@@ -293,4 +293,11 @@ public sealed class Pvt : ITValuePublisher
}
}
}
public static (TSeries Results, Pvt Indicator) Calculate(TBarSeries source)
{
var indicator = new Pvt();
TSeries results = indicator.Update(source);
return (results, indicator);
}
}