mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-22 20:48:04 +00:00
normalization of methods
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
|
||||
@@ -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
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user