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:
@@ -361,7 +361,7 @@ public class VoTests
|
||||
}
|
||||
|
||||
// Batch
|
||||
var batchResult = Vo.Calculate(_bars, shortPeriod: 5, longPeriod: 10, signalPeriod: 10);
|
||||
var batchResult = Vo.Batch(_bars, shortPeriod: 5, longPeriod: 10, signalPeriod: 10);
|
||||
|
||||
Assert.Equal(streamingResults.Count, batchResult.Count);
|
||||
for (int i = 0; i < streamingResults.Count; i++)
|
||||
@@ -386,7 +386,7 @@ public class VoTests
|
||||
// Span - pass arrays directly (implicit span conversion)
|
||||
var volume = _bars.Volume.Values.ToArray();
|
||||
var output = new double[_bars.Count];
|
||||
Vo.Calculate(volume, output, shortPeriod: 5, longPeriod: 10);
|
||||
Vo.Batch(volume, output, shortPeriod: 5, longPeriod: 10);
|
||||
|
||||
for (int i = 0; i < streamingResults.Count; i++)
|
||||
{
|
||||
@@ -425,7 +425,7 @@ public class VoTests
|
||||
ArgumentException? caught = null;
|
||||
try
|
||||
{
|
||||
Vo.Calculate(volume, output, shortPeriod: 5, longPeriod: 10);
|
||||
Vo.Batch(volume, output, shortPeriod: 5, longPeriod: 10);
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
@@ -445,7 +445,7 @@ public class VoTests
|
||||
ArgumentException? caught = null;
|
||||
try
|
||||
{
|
||||
Vo.Calculate(volume, output, shortPeriod: 0, longPeriod: 10);
|
||||
Vo.Batch(volume, output, shortPeriod: 0, longPeriod: 10);
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
@@ -465,7 +465,7 @@ public class VoTests
|
||||
ArgumentException? caught = null;
|
||||
try
|
||||
{
|
||||
Vo.Calculate(volume, output, shortPeriod: 5, longPeriod: 0);
|
||||
Vo.Batch(volume, output, shortPeriod: 5, longPeriod: 0);
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
@@ -485,7 +485,7 @@ public class VoTests
|
||||
ArgumentException? caught = null;
|
||||
try
|
||||
{
|
||||
Vo.Calculate(volume, output, shortPeriod: 10, longPeriod: 5);
|
||||
Vo.Batch(volume, output, shortPeriod: 10, longPeriod: 5);
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
@@ -503,7 +503,7 @@ public class VoTests
|
||||
double[] outputArr = [];
|
||||
|
||||
// Should not throw
|
||||
Vo.Calculate(volumeArr, outputArr, shortPeriod: 5, longPeriod: 10);
|
||||
Vo.Batch(volumeArr, outputArr, shortPeriod: 5, longPeriod: 10);
|
||||
|
||||
Assert.Empty(outputArr);
|
||||
}
|
||||
@@ -519,7 +519,7 @@ public class VoTests
|
||||
volume[i] = i == 10 ? double.NaN : 500 + i;
|
||||
}
|
||||
|
||||
Vo.Calculate(volume, output, shortPeriod: 5, longPeriod: 10);
|
||||
Vo.Batch(volume, output, shortPeriod: 5, longPeriod: 10);
|
||||
|
||||
foreach (var val in output)
|
||||
{
|
||||
@@ -539,7 +539,7 @@ public class VoTests
|
||||
}
|
||||
|
||||
// Should not throw stack overflow
|
||||
Vo.Calculate(volume, output, shortPeriod: 50, longPeriod: 200);
|
||||
Vo.Batch(volume, output, shortPeriod: 50, longPeriod: 200);
|
||||
|
||||
Assert.True(double.IsFinite(output[^1]));
|
||||
}
|
||||
|
||||
+10
-3
@@ -279,7 +279,7 @@ public sealed class Vo : ITValuePublisher
|
||||
/// <param name="longPeriod">The long-term period (default: 10).</param>
|
||||
/// <param name="signalPeriod">The signal line period (default: 10).</param>
|
||||
/// <returns>The result series.</returns>
|
||||
public static TSeries Calculate(TBarSeries source, int shortPeriod = 5, int longPeriod = 10, int signalPeriod = 10)
|
||||
public static TSeries Batch(TBarSeries source, int shortPeriod = 5, int longPeriod = 10, int signalPeriod = 10)
|
||||
{
|
||||
if (source.Count == 0)
|
||||
{
|
||||
@@ -289,7 +289,7 @@ public sealed class Vo : ITValuePublisher
|
||||
var t = source.Open.Times.ToArray();
|
||||
var v = new double[source.Count];
|
||||
|
||||
Calculate(source.Volume.Values, v, shortPeriod, longPeriod);
|
||||
Batch(source.Volume.Values, v, shortPeriod, longPeriod);
|
||||
|
||||
return new TSeries(t, v);
|
||||
}
|
||||
@@ -305,7 +305,7 @@ public sealed class Vo : ITValuePublisher
|
||||
/// <param name="longPeriod">The long-term period (default: 10).</param>
|
||||
/// <exception cref="ArgumentException">Thrown when parameters are invalid.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Calculate(ReadOnlySpan<double> volume, Span<double> output, int shortPeriod = 5, int longPeriod = 10)
|
||||
public static void Batch(ReadOnlySpan<double> volume, Span<double> output, int shortPeriod = 5, int longPeriod = 10)
|
||||
{
|
||||
if (shortPeriod < 1)
|
||||
{
|
||||
@@ -421,4 +421,11 @@ public sealed class Vo : ITValuePublisher
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static (TSeries Results, Vo Indicator) Calculate(TBarSeries source, int shortPeriod = 5, int longPeriod = 10, int signalPeriod = 10)
|
||||
{
|
||||
var indicator = new Vo(shortPeriod, longPeriod, signalPeriod);
|
||||
TSeries results = indicator.Update(source);
|
||||
return (results, indicator);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user