mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-23 04:58:08 +00:00
normalization of methods
This commit is contained in:
@@ -316,7 +316,7 @@ public class VwapTests
|
||||
[Fact]
|
||||
public void Calculate_Static_ShouldReturnTSeries()
|
||||
{
|
||||
var result = Vwap.Calculate(_bars);
|
||||
var result = Vwap.Batch(_bars);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(_bars.Count, result.Count);
|
||||
@@ -325,7 +325,7 @@ public class VwapTests
|
||||
[Fact]
|
||||
public void Calculate_Static_WithPeriod_ShouldWork()
|
||||
{
|
||||
var result = Vwap.Calculate(_bars, 100);
|
||||
var result = Vwap.Batch(_bars, 100);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(_bars.Count, result.Count);
|
||||
@@ -336,7 +336,7 @@ public class VwapTests
|
||||
[Fact]
|
||||
public void Calculate_Span_ShouldMatchBatch()
|
||||
{
|
||||
var batchResult = Vwap.Calculate(_bars);
|
||||
var batchResult = Vwap.Batch(_bars);
|
||||
|
||||
var high = _bars.High.Values.ToArray();
|
||||
var low = _bars.Low.Values.ToArray();
|
||||
@@ -344,7 +344,7 @@ public class VwapTests
|
||||
var volume = _bars.Volume.Values.ToArray();
|
||||
var spanOutput = new double[_bars.Count];
|
||||
|
||||
Vwap.Calculate(high, low, close, volume, spanOutput);
|
||||
Vwap.Batch(high, low, close, volume, spanOutput);
|
||||
|
||||
for (int i = 0; i < _bars.Count; i++)
|
||||
{
|
||||
@@ -361,7 +361,7 @@ public class VwapTests
|
||||
var volume = new double[100];
|
||||
var output = new double[100];
|
||||
|
||||
Assert.Throws<ArgumentException>(() => Vwap.Calculate(high, low, close, volume, output));
|
||||
Assert.Throws<ArgumentException>(() => Vwap.Batch(high, low, close, volume, output));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -373,7 +373,7 @@ public class VwapTests
|
||||
var volume = new double[100];
|
||||
var output = new double[50]; // Mismatched
|
||||
|
||||
Assert.Throws<ArgumentException>(() => Vwap.Calculate(high, low, close, volume, output));
|
||||
Assert.Throws<ArgumentException>(() => Vwap.Batch(high, low, close, volume, output));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -385,7 +385,7 @@ public class VwapTests
|
||||
var volume = new double[100];
|
||||
var output = new double[100];
|
||||
|
||||
Assert.Throws<ArgumentException>(() => Vwap.Calculate(high, low, close, volume, output, -1));
|
||||
Assert.Throws<ArgumentException>(() => Vwap.Batch(high, low, close, volume, output, -1));
|
||||
}
|
||||
|
||||
// ============ Event Tests ============
|
||||
@@ -418,7 +418,7 @@ public class VwapTests
|
||||
}
|
||||
|
||||
// Batch
|
||||
var batchResult = Vwap.Calculate(_bars);
|
||||
var batchResult = Vwap.Batch(_bars);
|
||||
|
||||
// Compare last 100 values
|
||||
for (int i = _bars.Count - 100; i < _bars.Count; i++)
|
||||
|
||||
@@ -50,7 +50,7 @@ public class VwapValidationTests
|
||||
}
|
||||
|
||||
// Batch
|
||||
var batchResult = Vwap.Calculate(_data.Bars);
|
||||
var batchResult = Vwap.Batch(_data.Bars);
|
||||
var batchValues = batchResult.Values.ToArray();
|
||||
|
||||
// Cumulative indicators accumulate floating-point errors over many bars
|
||||
@@ -75,7 +75,7 @@ public class VwapValidationTests
|
||||
var volume = _data.Bars.Volume.Values.ToArray();
|
||||
var spanValues = new double[high.Length];
|
||||
|
||||
Vwap.Calculate(high, low, close, volume, spanValues);
|
||||
Vwap.Batch(high, low, close, volume, spanValues);
|
||||
|
||||
// Cumulative indicators accumulate floating-point errors over many bars
|
||||
ValidationHelper.VerifyData(streamingValues.ToArray(), spanValues, 0, 100, 1e-10);
|
||||
@@ -85,7 +85,7 @@ public class VwapValidationTests
|
||||
public void Vwap_Batch_Matches_Span()
|
||||
{
|
||||
// Batch
|
||||
var batchResult = Vwap.Calculate(_data.Bars);
|
||||
var batchResult = Vwap.Batch(_data.Bars);
|
||||
var batchValues = batchResult.Values.ToArray();
|
||||
|
||||
// Span
|
||||
@@ -95,7 +95,7 @@ public class VwapValidationTests
|
||||
var volume = _data.Bars.Volume.Values.ToArray();
|
||||
var spanValues = new double[high.Length];
|
||||
|
||||
Vwap.Calculate(high, low, close, volume, spanValues);
|
||||
Vwap.Batch(high, low, close, volume, spanValues);
|
||||
|
||||
// Batch and Span use identical code path, should match exactly
|
||||
ValidationHelper.VerifyData(batchValues, spanValues, 0, 100, 1e-12);
|
||||
|
||||
+10
-3
@@ -220,7 +220,7 @@ public sealed class Vwap : ITValuePublisher
|
||||
/// <param name="source">Source bar series</param>
|
||||
/// <param name="period">Period for VWAP reset (0 = no reset)</param>
|
||||
/// <returns>TSeries containing VWAP values</returns>
|
||||
public static TSeries Calculate(TBarSeries source, int period = 0)
|
||||
public static TSeries Batch(TBarSeries source, int period = 0)
|
||||
{
|
||||
if (source.Count == 0)
|
||||
{
|
||||
@@ -230,7 +230,7 @@ public sealed class Vwap : ITValuePublisher
|
||||
var t = source.Open.Times.ToArray();
|
||||
var v = new double[source.Count];
|
||||
|
||||
Calculate(source.High.Values, source.Low.Values, source.Close.Values, source.Volume.Values, v, period);
|
||||
Batch(source.High.Values, source.Low.Values, source.Close.Values, source.Volume.Values, v, period);
|
||||
|
||||
return new TSeries(t, v);
|
||||
}
|
||||
@@ -245,7 +245,7 @@ public sealed class Vwap : ITValuePublisher
|
||||
/// <param name="output">Output span for VWAP values</param>
|
||||
/// <param name="period">Period for VWAP reset (0 = no reset)</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
|
||||
public static void Calculate(ReadOnlySpan<double> high, ReadOnlySpan<double> low, ReadOnlySpan<double> close, ReadOnlySpan<double> volume, Span<double> output, int period = 0)
|
||||
public static void Batch(ReadOnlySpan<double> high, ReadOnlySpan<double> low, ReadOnlySpan<double> close, ReadOnlySpan<double> volume, Span<double> output, int period = 0)
|
||||
{
|
||||
if (high.Length != low.Length)
|
||||
{
|
||||
@@ -368,4 +368,11 @@ public sealed class Vwap : ITValuePublisher
|
||||
barsSinceReset++;
|
||||
}
|
||||
}
|
||||
|
||||
public static (TSeries Results, Vwap Indicator) Calculate(TBarSeries source, int period = 0)
|
||||
{
|
||||
var indicator = new Vwap(period);
|
||||
TSeries results = indicator.Update(source);
|
||||
return (results, indicator);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user