mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-23 13:08:04 +00:00
normalization of methods
This commit is contained in:
@@ -306,7 +306,7 @@ public class KvoTests
|
||||
}
|
||||
|
||||
// Batch
|
||||
var batchResult = Kvo.Calculate(bars);
|
||||
var batchResult = Kvo.Batch(bars);
|
||||
|
||||
Assert.Equal(bars.Count, batchResult.Count);
|
||||
for (int i = 0; i < bars.Count; i++)
|
||||
@@ -345,7 +345,7 @@ public class KvoTests
|
||||
var spanKvo = new double[bars.Count];
|
||||
var spanSignal = new double[bars.Count];
|
||||
|
||||
Kvo.Calculate(high, low, close, volume, spanKvo, spanSignal);
|
||||
Kvo.Batch(high, low, close, volume, spanKvo, spanSignal);
|
||||
|
||||
for (int i = 0; i < bars.Count; i++)
|
||||
{
|
||||
@@ -364,7 +364,7 @@ public class KvoTests
|
||||
var output = new double[100];
|
||||
var signal = new double[100];
|
||||
|
||||
Assert.Throws<ArgumentException>(() => Kvo.Calculate(high, low, close, volume, output, signal));
|
||||
Assert.Throws<ArgumentException>(() => Kvo.Batch(high, low, close, volume, output, signal));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -377,7 +377,7 @@ public class KvoTests
|
||||
var output = new double[100];
|
||||
var signal = new double[100];
|
||||
|
||||
Assert.Throws<ArgumentException>(() => Kvo.Calculate(high, low, close, volume, output, signal, fastPeriod: 0));
|
||||
Assert.Throws<ArgumentException>(() => Kvo.Batch(high, low, close, volume, output, signal, fastPeriod: 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -390,7 +390,7 @@ public class KvoTests
|
||||
var output = new double[100];
|
||||
var signal = new double[100];
|
||||
|
||||
Assert.Throws<ArgumentException>(() => Kvo.Calculate(high, low, close, volume, output, signal, slowPeriod: 0));
|
||||
Assert.Throws<ArgumentException>(() => Kvo.Batch(high, low, close, volume, output, signal, slowPeriod: 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -403,7 +403,7 @@ public class KvoTests
|
||||
var output = new double[100];
|
||||
var signal = new double[100];
|
||||
|
||||
Assert.Throws<ArgumentException>(() => Kvo.Calculate(high, low, close, volume, output, signal, signalPeriod: 0));
|
||||
Assert.Throws<ArgumentException>(() => Kvo.Batch(high, low, close, volume, output, signal, signalPeriod: 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -417,7 +417,7 @@ public class KvoTests
|
||||
var signal = Array.Empty<double>();
|
||||
|
||||
// Should not throw
|
||||
Kvo.Calculate(high, low, close, volume, output, signal);
|
||||
Kvo.Batch(high, low, close, volume, output, signal);
|
||||
|
||||
// Verify arrays remain empty (no out-of-bounds writes)
|
||||
Assert.Empty(output);
|
||||
|
||||
@@ -75,7 +75,7 @@ public class KvoValidationTests
|
||||
}
|
||||
|
||||
// Batch
|
||||
var batchResult = Kvo.Calculate(_data.Bars, DefaultFastPeriod, DefaultSlowPeriod, DefaultSignalPeriod);
|
||||
var batchResult = Kvo.Batch(_data.Bars, DefaultFastPeriod, DefaultSlowPeriod, DefaultSignalPeriod);
|
||||
var batchValues = batchResult.Values.ToArray();
|
||||
|
||||
ValidationHelper.VerifyData(streamingValues.ToArray(), batchValues, 0, 100, 1e-9);
|
||||
@@ -103,7 +103,7 @@ public class KvoValidationTests
|
||||
var spanKvo = new double[high.Length];
|
||||
var spanSignal = new double[high.Length];
|
||||
|
||||
Kvo.Calculate(high, low, close, volume, spanKvo, spanSignal, DefaultFastPeriod, DefaultSlowPeriod, DefaultSignalPeriod);
|
||||
Kvo.Batch(high, low, close, volume, spanKvo, spanSignal, DefaultFastPeriod, DefaultSlowPeriod, DefaultSignalPeriod);
|
||||
|
||||
ValidationHelper.VerifyData(streamingKvo.ToArray(), spanKvo, 0, 100, 1e-9);
|
||||
ValidationHelper.VerifyData(streamingSignal.ToArray(), spanSignal, 0, 100, 1e-9);
|
||||
|
||||
+10
-3
@@ -303,7 +303,7 @@ public sealed class Kvo : ITValuePublisher
|
||||
/// <param name="slowPeriod">The slow EMA period</param>
|
||||
/// <param name="signalPeriod">The signal line EMA period</param>
|
||||
/// <returns>A TSeries containing the KVO values</returns>
|
||||
public static TSeries Calculate(TBarSeries bars, int fastPeriod = 34, int slowPeriod = 55, int signalPeriod = 13)
|
||||
public static TSeries Batch(TBarSeries bars, int fastPeriod = 34, int slowPeriod = 55, int signalPeriod = 13)
|
||||
{
|
||||
if (bars.Count == 0)
|
||||
{
|
||||
@@ -314,7 +314,7 @@ public sealed class Kvo : ITValuePublisher
|
||||
var v = new double[bars.Count];
|
||||
var signal = new double[bars.Count];
|
||||
|
||||
Calculate(bars.High.Values, bars.Low.Values, bars.Close.Values, bars.Volume.Values,
|
||||
Batch(bars.High.Values, bars.Low.Values, bars.Close.Values, bars.Volume.Values,
|
||||
v, signal, fastPeriod, slowPeriod, signalPeriod);
|
||||
|
||||
return new TSeries(t, v);
|
||||
@@ -334,7 +334,7 @@ public sealed class Kvo : ITValuePublisher
|
||||
/// <param name="signalPeriod">The signal line EMA period</param>
|
||||
/// <exception cref="ArgumentException">Thrown when spans have different lengths or parameters are invalid</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Calculate(ReadOnlySpan<double> high, ReadOnlySpan<double> low,
|
||||
public static void Batch(ReadOnlySpan<double> high, ReadOnlySpan<double> low,
|
||||
ReadOnlySpan<double> close, ReadOnlySpan<double> volume,
|
||||
Span<double> output, Span<double> signal,
|
||||
int fastPeriod = 34, int slowPeriod = 55, int signalPeriod = 13)
|
||||
@@ -478,4 +478,11 @@ public sealed class Kvo : ITValuePublisher
|
||||
prevHlc3 = hlc3;
|
||||
}
|
||||
}
|
||||
|
||||
public static (TSeries Results, Kvo Indicator) Calculate(TBarSeries bars, int fastPeriod = 34, int slowPeriod = 55, int signalPeriod = 13)
|
||||
{
|
||||
var indicator = new Kvo(fastPeriod, slowPeriod, signalPeriod);
|
||||
TSeries results = indicator.Update(bars);
|
||||
return (results, indicator);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user