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:
@@ -263,7 +263,7 @@ public class MfiTests
|
||||
}
|
||||
|
||||
// Batch
|
||||
var batchResult = Mfi.Calculate(bars);
|
||||
var batchResult = Mfi.Batch(bars);
|
||||
|
||||
Assert.Equal(bars.Count, batchResult.Count);
|
||||
for (int i = 0; i < bars.Count; i++)
|
||||
@@ -298,7 +298,7 @@ public class MfiTests
|
||||
var volume = bars.Volume.Values.ToArray();
|
||||
var output = new double[bars.Count];
|
||||
|
||||
Mfi.Calculate(high, low, close, volume, output);
|
||||
Mfi.Batch(high, low, close, volume, output);
|
||||
|
||||
for (int i = 0; i < bars.Count; i++)
|
||||
{
|
||||
@@ -315,7 +315,7 @@ public class MfiTests
|
||||
var volume = new double[100];
|
||||
var output = new double[100];
|
||||
|
||||
Assert.Throws<ArgumentException>(() => Mfi.Calculate(high, low, close, volume, output));
|
||||
Assert.Throws<ArgumentException>(() => Mfi.Batch(high, low, close, volume, output));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -327,7 +327,7 @@ public class MfiTests
|
||||
var volume = new double[100];
|
||||
var output = new double[100];
|
||||
|
||||
Assert.Throws<ArgumentException>(() => Mfi.Calculate(high, low, close, volume, output, period: 0));
|
||||
Assert.Throws<ArgumentException>(() => Mfi.Batch(high, low, close, volume, output, period: 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -339,7 +339,7 @@ public class MfiTests
|
||||
var volume = Array.Empty<double>();
|
||||
var output = Array.Empty<double>();
|
||||
|
||||
Mfi.Calculate(high, low, close, volume, output);
|
||||
Mfi.Batch(high, low, close, volume, output);
|
||||
|
||||
Assert.Empty(output);
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ public class MfiValidationTests
|
||||
}
|
||||
|
||||
// Batch
|
||||
var batchResult = Mfi.Calculate(_data.Bars, DefaultPeriod);
|
||||
var batchResult = Mfi.Batch(_data.Bars, DefaultPeriod);
|
||||
var batchValues = batchResult.Values.ToArray();
|
||||
|
||||
ValidationHelper.VerifyData(streamingValues.ToArray(), batchValues, 0, 100, 1e-9);
|
||||
@@ -120,7 +120,7 @@ public class MfiValidationTests
|
||||
var volume = _data.Bars.Volume.Values.ToArray();
|
||||
var spanOutput = new double[high.Length];
|
||||
|
||||
Mfi.Calculate(high, low, close, volume, spanOutput, DefaultPeriod);
|
||||
Mfi.Batch(high, low, close, volume, spanOutput, DefaultPeriod);
|
||||
|
||||
ValidationHelper.VerifyData(streamingValues.ToArray(), spanOutput, 0, 100, 1e-9);
|
||||
}
|
||||
|
||||
+10
-3
@@ -212,7 +212,7 @@ public sealed class Mfi : ITValuePublisher
|
||||
return new TSeries(t, v);
|
||||
}
|
||||
|
||||
public static TSeries Calculate(TBarSeries source, int period = 14)
|
||||
public static TSeries Batch(TBarSeries source, int period = 14)
|
||||
{
|
||||
if (source.Count == 0)
|
||||
{
|
||||
@@ -222,13 +222,13 @@ public sealed class Mfi : 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);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Calculate(ReadOnlySpan<double> high, ReadOnlySpan<double> low, ReadOnlySpan<double> close, ReadOnlySpan<double> volume, Span<double> output, int period = 14)
|
||||
public static void Batch(ReadOnlySpan<double> high, ReadOnlySpan<double> low, ReadOnlySpan<double> close, ReadOnlySpan<double> volume, Span<double> output, int period = 14)
|
||||
{
|
||||
if (high.Length != low.Length)
|
||||
{
|
||||
@@ -326,4 +326,11 @@ public sealed class Mfi : ITValuePublisher
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static (TSeries Results, Mfi Indicator) Calculate(TBarSeries source, int period = 14)
|
||||
{
|
||||
var indicator = new Mfi(period);
|
||||
TSeries results = indicator.Update(source);
|
||||
return (results, indicator);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user