normalization of methods

This commit is contained in:
Miha Kralj
2026-02-10 21:33:16 -08:00
parent 915d7a007b
commit 6d6259a47d
527 changed files with 10525 additions and 2123 deletions
+6 -6
View File
@@ -234,7 +234,7 @@ public class EomTests
}
// Batch
var batchResult = Eom.Calculate(bars);
var batchResult = Eom.Batch(bars);
Assert.Equal(bars.Count, batchResult.Count);
for (int i = 0; i < bars.Count; i++)
@@ -268,7 +268,7 @@ public class EomTests
var volume = bars.Volume.Values.ToArray();
var spanValues = new double[bars.Count];
Eom.Calculate(high, low, volume, spanValues);
Eom.Batch(high, low, volume, spanValues);
for (int i = 0; i < bars.Count; i++)
{
@@ -284,7 +284,7 @@ public class EomTests
var volume = new double[100];
var output = new double[100];
Assert.Throws<ArgumentException>(() => Eom.Calculate(high, low, volume, output));
Assert.Throws<ArgumentException>(() => Eom.Batch(high, low, volume, output));
}
[Fact]
@@ -295,7 +295,7 @@ public class EomTests
var volume = new double[100];
var output = new double[100];
Assert.Throws<ArgumentException>(() => Eom.Calculate(high, low, volume, output, period: 0));
Assert.Throws<ArgumentException>(() => Eom.Batch(high, low, volume, output, period: 0));
}
[Fact]
@@ -306,7 +306,7 @@ public class EomTests
var volume = new double[100];
var output = new double[100];
Assert.Throws<ArgumentException>(() => Eom.Calculate(high, low, volume, output, volumeScale: 0));
Assert.Throws<ArgumentException>(() => Eom.Batch(high, low, volume, output, volumeScale: 0));
}
[Fact]
@@ -326,7 +326,7 @@ public class EomTests
}
// Should not throw
Eom.Calculate(high, low, volume, output);
Eom.Batch(high, low, volume, output);
Assert.True(double.IsFinite(output[size - 1]));
}
+2 -2
View File
@@ -51,7 +51,7 @@ public class EomValidationTests
}
// Batch
var batchResult = Eom.Calculate(_data.Bars, DefaultPeriod);
var batchResult = Eom.Batch(_data.Bars, DefaultPeriod);
var batchValues = batchResult.Values.ToArray();
ValidationHelper.VerifyData(streamingValues.ToArray(), batchValues, 0, 100, 1e-9);
@@ -74,7 +74,7 @@ public class EomValidationTests
var volume = _data.Bars.Volume.Values.ToArray();
var spanValues = new double[high.Length];
Eom.Calculate(high, low, volume, spanValues, DefaultPeriod);
Eom.Batch(high, low, volume, spanValues, DefaultPeriod);
ValidationHelper.VerifyData(streamingValues.ToArray(), spanValues, 0, 100, 1e-9);
}
+10 -3
View File
@@ -208,7 +208,7 @@ public sealed class Eom : ITValuePublisher
/// <param name="period">The smoothing period</param>
/// <param name="volumeScale">The volume scaling factor</param>
/// <returns>A TSeries containing the EOM values</returns>
public static TSeries Calculate(TBarSeries bars, int period = 14, double volumeScale = 10000)
public static TSeries Batch(TBarSeries bars, int period = 14, double volumeScale = 10000)
{
if (bars.Count == 0)
{
@@ -218,7 +218,7 @@ public sealed class Eom : ITValuePublisher
var t = bars.Open.Times.ToArray();
var v = new double[bars.Count];
Calculate(bars.High.Values, bars.Low.Values, bars.Volume.Values, v, period, volumeScale);
Batch(bars.High.Values, bars.Low.Values, bars.Volume.Values, v, period, volumeScale);
return new TSeries(t, v);
}
@@ -234,7 +234,7 @@ public sealed class Eom : ITValuePublisher
/// <param name="volumeScale">The volume scaling factor</param>
/// <exception cref="ArgumentException">Thrown when spans have different lengths</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> volume, Span<double> output, int period = 14, double volumeScale = 10000)
{
if (high.Length != low.Length)
@@ -332,4 +332,11 @@ public sealed class Eom : ITValuePublisher
}
}
}
public static (TSeries Results, Eom Indicator) Calculate(TBarSeries bars, int period = 14, double volumeScale = 10000)
{
var indicator = new Eom(period, volumeScale);
TSeries results = indicator.Update(bars);
return (results, indicator);
}
}