mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-20 11:38:05 +00:00
normalization of methods
This commit is contained in:
@@ -225,7 +225,7 @@ public class CmfTests
|
||||
bars.Add(new TBar(time.AddMinutes(1), 10, 12, 8, 12, 200));
|
||||
bars.Add(new TBar(time.AddMinutes(2), 12, 12, 8, 8, 100));
|
||||
|
||||
var result = Cmf.Calculate(bars, 3);
|
||||
var result = Cmf.Batch(bars, 3);
|
||||
|
||||
Assert.Equal(3, result.Count);
|
||||
}
|
||||
@@ -239,7 +239,7 @@ public class CmfTests
|
||||
double[] volume = { 100, 200, 100 };
|
||||
double[] output = new double[3];
|
||||
|
||||
Cmf.Calculate(high, low, close, volume, output, 3);
|
||||
Cmf.Batch(high, low, close, volume, output, 3);
|
||||
|
||||
// Bar 0: MFV=0, Vol=100 -> CMF=0/100=0
|
||||
Assert.Equal(0, output[0]);
|
||||
@@ -259,7 +259,7 @@ public class CmfTests
|
||||
double[] output = new double[2];
|
||||
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
Cmf.Calculate(high, low, close, volume, output, 3));
|
||||
Cmf.Batch(high, low, close, volume, output, 3));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -272,14 +272,14 @@ public class CmfTests
|
||||
double[] output = new double[1];
|
||||
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
Cmf.Calculate(high, low, close, volume, output, 0));
|
||||
Cmf.Batch(high, low, close, volume, output, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Cmf_Calculate_EmptySeries_ReturnsEmpty()
|
||||
{
|
||||
var bars = new TBarSeries();
|
||||
var result = Cmf.Calculate(bars);
|
||||
var result = Cmf.Batch(bars);
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ public class CmfTests
|
||||
volume[i] = 10;
|
||||
}
|
||||
|
||||
Cmf.Calculate(high, low, close, volume, output, 20);
|
||||
Cmf.Batch(high, low, close, volume, output, 20);
|
||||
|
||||
// All bars have MFM=1, so CMF should be 1.0 once we have enough data
|
||||
for (int i = 19; i < count; i++)
|
||||
@@ -331,7 +331,7 @@ public class CmfTests
|
||||
}
|
||||
|
||||
// Batch
|
||||
var batchResult = Cmf.Calculate(bars, 20);
|
||||
var batchResult = Cmf.Batch(bars, 20);
|
||||
|
||||
// Compare last 80 values (after warmup)
|
||||
for (int i = 20; i < 100; i++)
|
||||
|
||||
@@ -91,7 +91,7 @@ public class CmfValidationTests
|
||||
}
|
||||
|
||||
// Batch
|
||||
var batchResult = Cmf.Calculate(_data.Bars, DefaultPeriod);
|
||||
var batchResult = Cmf.Batch(_data.Bars, DefaultPeriod);
|
||||
var batchValues = batchResult.Values.ToArray();
|
||||
|
||||
ValidationHelper.VerifyData(streamingValues.ToArray(), batchValues, 0, 100, 1e-12);
|
||||
@@ -115,7 +115,7 @@ public class CmfValidationTests
|
||||
var volume = _data.Bars.Volume.Values.ToArray();
|
||||
var spanValues = new double[high.Length];
|
||||
|
||||
Cmf.Calculate(high, low, close, volume, spanValues, DefaultPeriod);
|
||||
Cmf.Batch(high, low, close, volume, spanValues, DefaultPeriod);
|
||||
|
||||
ValidationHelper.VerifyData(streamingValues.ToArray(), spanValues, 0, 100, 1e-12);
|
||||
}
|
||||
|
||||
+11
-4
@@ -174,7 +174,7 @@ public sealed class Cmf : ITValuePublisher
|
||||
return new TSeries(t, v);
|
||||
}
|
||||
|
||||
public static TSeries Calculate(TBarSeries source, int period = 20)
|
||||
public static TSeries Batch(TBarSeries source, int period = 20)
|
||||
{
|
||||
if (source.Count == 0)
|
||||
{
|
||||
@@ -184,13 +184,13 @@ public sealed class Cmf : 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 = 20)
|
||||
public static void Batch(ReadOnlySpan<double> high, ReadOnlySpan<double> low, ReadOnlySpan<double> close, ReadOnlySpan<double> volume, Span<double> output, int period = 20)
|
||||
{
|
||||
if (high.Length != low.Length)
|
||||
{
|
||||
@@ -282,4 +282,11 @@ public sealed class Cmf : ITValuePublisher
|
||||
output[i] = sumVol > double.Epsilon ? sumMfv / sumVol : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static (TSeries Results, Cmf Indicator) Calculate(TBarSeries source, int period = 20)
|
||||
{
|
||||
var indicator = new Cmf(period);
|
||||
TSeries results = indicator.Update(source);
|
||||
return (results, indicator);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user