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
+5 -5
View File
@@ -286,7 +286,7 @@ public class PviTests
}
// Batch
var batchResult = Pvi.Calculate(bars);
var batchResult = Pvi.Batch(bars);
Assert.Equal(bars.Count, batchResult.Count);
for (int i = 0; i < bars.Count; i++)
@@ -319,7 +319,7 @@ public class PviTests
var volume = bars.Volume.Values.ToArray();
var output = new double[bars.Count];
Pvi.Calculate(close, volume, output);
Pvi.Batch(close, volume, output);
for (int i = 0; i < bars.Count; i++)
{
@@ -334,7 +334,7 @@ public class PviTests
var volume = new double[99]; // Different length
var output = new double[100];
Assert.Throws<ArgumentException>(() => Pvi.Calculate(close, volume, output));
Assert.Throws<ArgumentException>(() => Pvi.Batch(close, volume, output));
}
[Fact]
@@ -344,7 +344,7 @@ public class PviTests
var volume = new double[100];
var output = new double[100];
Assert.Throws<ArgumentException>(() => Pvi.Calculate(close, volume, output, startValue: 0));
Assert.Throws<ArgumentException>(() => Pvi.Batch(close, volume, output, startValue: 0));
}
[Fact]
@@ -354,7 +354,7 @@ public class PviTests
var volume = Array.Empty<double>();
var output = Array.Empty<double>();
Pvi.Calculate(close, volume, output);
Pvi.Batch(close, volume, output);
Assert.Empty(output);
}
+2 -2
View File
@@ -62,7 +62,7 @@ public class PviValidationTests
}
// Batch
var batchResult = Pvi.Calculate(_data.Bars, DefaultStartValue);
var batchResult = Pvi.Batch(_data.Bars, DefaultStartValue);
var batchValues = batchResult.Values.ToArray();
ValidationHelper.VerifyData(streamingValues.ToArray(), batchValues, 0, 100, 1e-9);
@@ -84,7 +84,7 @@ public class PviValidationTests
var volume = _data.Bars.Volume.Values.ToArray();
var spanOutput = new double[close.Length];
Pvi.Calculate(close, volume, spanOutput, DefaultStartValue);
Pvi.Batch(close, volume, spanOutput, DefaultStartValue);
ValidationHelper.VerifyData(streamingValues.ToArray(), spanOutput, 0, 100, 1e-9);
}
+10 -3
View File
@@ -188,7 +188,7 @@ public sealed class Pvi : ITValuePublisher
return new TSeries(t, v);
}
public static TSeries Calculate(TBarSeries source, double startValue = 100.0)
public static TSeries Batch(TBarSeries source, double startValue = 100.0)
{
if (source.Count == 0)
{
@@ -198,13 +198,13 @@ public sealed class Pvi : ITValuePublisher
var t = source.Close.Times.ToArray();
var v = new double[source.Count];
Calculate(source.Close.Values, source.Volume.Values, v, startValue);
Batch(source.Close.Values, source.Volume.Values, v, startValue);
return new TSeries(t, v);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Calculate(ReadOnlySpan<double> close, ReadOnlySpan<double> volume, Span<double> output, double startValue = 100.0)
public static void Batch(ReadOnlySpan<double> close, ReadOnlySpan<double> volume, Span<double> output, double startValue = 100.0)
{
if (close.Length != volume.Length)
{
@@ -280,4 +280,11 @@ public sealed class Pvi : ITValuePublisher
prevVolume = currentVolume;
}
}
public static (TSeries Results, Pvi Indicator) Calculate(TBarSeries source, double startValue = 100.0)
{
var indicator = new Pvi(startValue);
TSeries results = indicator.Update(source);
return (results, indicator);
}
}