mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-26 06:18:05 +00:00
normalization of methods
This commit is contained in:
@@ -86,7 +86,7 @@ public class KamaTests
|
||||
|
||||
var instanceResults = new Kama(10).Update(series);
|
||||
var staticResults = new double[series.Count];
|
||||
Kama.Calculate(series.Values.ToArray().AsSpan(), staticResults.AsSpan(), 10);
|
||||
Kama.Batch(series.Values.ToArray().AsSpan(), staticResults.AsSpan(), 10);
|
||||
|
||||
for (int i = 0; i < instanceResults.Count; i++)
|
||||
{
|
||||
@@ -214,8 +214,8 @@ public class KamaTests
|
||||
double[] output = new double[5];
|
||||
double[] wrongSizeOutput = new double[3];
|
||||
|
||||
Assert.Throws<ArgumentException>(() => Kama.Calculate(source.AsSpan(), output.AsSpan(), 0));
|
||||
Assert.Throws<ArgumentException>(() => Kama.Calculate(source.AsSpan(), wrongSizeOutput.AsSpan(), 3));
|
||||
Assert.Throws<ArgumentException>(() => Kama.Batch(source.AsSpan(), output.AsSpan(), 0));
|
||||
Assert.Throws<ArgumentException>(() => Kama.Batch(source.AsSpan(), wrongSizeOutput.AsSpan(), 3));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -224,7 +224,7 @@ public class KamaTests
|
||||
double[] source = [100, 110, double.NaN, 120, 130];
|
||||
double[] output = new double[5];
|
||||
|
||||
Kama.Calculate(source.AsSpan(), output.AsSpan(), 3);
|
||||
Kama.Batch(source.AsSpan(), output.AsSpan(), 3);
|
||||
|
||||
foreach (var val in output)
|
||||
{
|
||||
@@ -249,7 +249,7 @@ public class KamaTests
|
||||
var tValues = series.Values.ToArray();
|
||||
var spanInput = new ReadOnlySpan<double>(tValues);
|
||||
var spanOutput = new double[tValues.Length];
|
||||
Kama.Calculate(spanInput, spanOutput, period);
|
||||
Kama.Batch(spanInput, spanOutput, period);
|
||||
double spanResult = spanOutput[^1];
|
||||
|
||||
// 3. Streaming Mode
|
||||
|
||||
@@ -97,7 +97,7 @@ public sealed class KamaValidationTests : IDisposable
|
||||
{
|
||||
// Calculate QuanTAlib KAMA (Span API)
|
||||
double[] qOutput = new double[_testData.RawData.Length];
|
||||
global::QuanTAlib.Kama.Calculate(_testData.RawData.Span, qOutput.AsSpan(), period, fastPeriod, slowPeriod);
|
||||
global::QuanTAlib.Kama.Batch(_testData.RawData.Span, qOutput.AsSpan(), period, fastPeriod, slowPeriod);
|
||||
|
||||
// Calculate Skender KAMA
|
||||
var sResult = _testData.SkenderQuotes.GetKama(period, fastPeriod, slowPeriod).ToList();
|
||||
|
||||
@@ -239,7 +239,7 @@ public sealed class Kama : AbstractBase
|
||||
return kama.Update(source);
|
||||
}
|
||||
|
||||
public static void Calculate(ReadOnlySpan<double> source, Span<double> output, int period, int fastPeriod = 2, int slowPeriod = 30)
|
||||
public static void Batch(ReadOnlySpan<double> source, Span<double> output, int period, int fastPeriod = 2, int slowPeriod = 30)
|
||||
{
|
||||
if (period <= 0)
|
||||
{
|
||||
@@ -363,6 +363,13 @@ public sealed class Kama : AbstractBase
|
||||
}
|
||||
}
|
||||
|
||||
public static (TSeries Results, Kama Indicator) Calculate(TSeries source, int period, int fastPeriod = 2, int slowPeriod = 30)
|
||||
{
|
||||
var indicator = new Kama(period, fastPeriod, slowPeriod);
|
||||
TSeries results = indicator.Update(source);
|
||||
return (results, indicator);
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
_buffer.Clear();
|
||||
@@ -372,4 +379,4 @@ public sealed class Kama : AbstractBase
|
||||
_p_state = _state;
|
||||
Last = default;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user