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
+7 -7
View File
@@ -328,7 +328,7 @@ public class AmatTests
var tValues = _testData.Values.ToArray();
var spanInput = new ReadOnlySpan<double>(tValues);
var spanOutput = new double[tValues.Length];
Amat.Calculate(spanInput, spanOutput, fastPeriod, slowPeriod);
Amat.Batch(spanInput, spanOutput, fastPeriod, slowPeriod);
double spanResult = spanOutput[^1];
// 3. Streaming Mode (instance, one value at a time)
@@ -363,13 +363,13 @@ public class AmatTests
double[] wrongSize = new double[3];
Assert.Throws<ArgumentException>(() =>
Amat.Calculate(source.AsSpan(), wrongSize.AsSpan(), strength.AsSpan(), 5, 10));
Amat.Batch(source.AsSpan(), wrongSize.AsSpan(), strength.AsSpan(), 5, 10));
Assert.Throws<ArgumentException>(() =>
Amat.Calculate(source.AsSpan(), trend.AsSpan(), wrongSize.AsSpan(), 5, 10));
Amat.Batch(source.AsSpan(), trend.AsSpan(), wrongSize.AsSpan(), 5, 10));
Assert.Throws<ArgumentException>(() =>
Amat.Calculate(source.AsSpan(), trend.AsSpan(), strength.AsSpan(), 0, 10));
Amat.Batch(source.AsSpan(), trend.AsSpan(), strength.AsSpan(), 0, 10));
Assert.Throws<ArgumentException>(() =>
Amat.Calculate(source.AsSpan(), trend.AsSpan(), strength.AsSpan(), 10, 5)); // fast >= slow
Amat.Batch(source.AsSpan(), trend.AsSpan(), strength.AsSpan(), 10, 5)); // fast >= slow
}
[Fact]
@@ -379,7 +379,7 @@ public class AmatTests
double[] trend = new double[source.Length];
var tseriesResult = Amat.Batch(_testData, 10, 30);
Amat.Calculate(source.AsSpan(), trend.AsSpan(), 10, 30);
Amat.Batch(source.AsSpan(), trend.AsSpan(), 10, 30);
// Since trend values are discrete (-1, 0, 1), check after warmup where
// both methods should converge. Early values may differ due to EMA initialization.
@@ -404,7 +404,7 @@ public class AmatTests
double[] trend = new double[10];
double[] strength = new double[10];
Amat.Calculate(source.AsSpan(), trend.AsSpan(), strength.AsSpan(), 3, 5);
Amat.Batch(source.AsSpan(), trend.AsSpan(), strength.AsSpan(), 3, 5);
foreach (var val in trend)
{
+1 -1
View File
@@ -351,7 +351,7 @@ public sealed class AmatValidationTests : IDisposable
double[] sourceData = _testData.RawData.ToArray();
double[] spanTrend = new double[sourceData.Length];
double[] spanStrength = new double[sourceData.Length];
Amat.Calculate(sourceData, spanTrend, spanStrength, fastPeriod, slowPeriod);
Amat.Batch(sourceData, spanTrend, spanStrength, fastPeriod, slowPeriod);
// Compare trend values (after warmup period)
int warmup = slowPeriod * 2; // Allow extra warmup for convergence
+15 -14
View File
@@ -391,7 +391,7 @@ public sealed class Amat : ITValuePublisher, IDisposable
/// <param name="fastPeriod">Fast EMA period</param>
/// <param name="slowPeriod">Slow EMA period</param>
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
public static void Calculate(ReadOnlySpan<double> source, Span<double> trend, Span<double> strength,
public static void Batch(ReadOnlySpan<double> source, Span<double> trend, Span<double> strength,
int fastPeriod = 10, int slowPeriod = 50)
{
if (source.Length != trend.Length)
@@ -501,7 +501,7 @@ public sealed class Amat : ITValuePublisher, IDisposable
/// <param name="fastPeriod">Fast EMA period</param>
/// <param name="slowPeriod">Slow EMA period</param>
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
public static void Calculate(ReadOnlySpan<double> source, Span<double> trend,
public static void Batch(ReadOnlySpan<double> source, Span<double> trend,
int fastPeriod = 10, int slowPeriod = 50)
{
if (source.Length != trend.Length)
@@ -585,6 +585,19 @@ public sealed class Amat : ITValuePublisher, IDisposable
}
}
/// <summary>
/// Calculates AMAT for the entire series using a new instance.
/// </summary>
/// <param name="source">Input series</param>
/// <param name="fastPeriod">Fast EMA period</param>
/// <param name="slowPeriod">Slow EMA period</param>
/// <returns>AMAT trend series</returns>
public static TSeries Batch(TSeries source, int fastPeriod = 10, int slowPeriod = 50)
{
var amat = new Amat(fastPeriod, slowPeriod);
return amat.Update(source);
}
/// <summary>
/// Runs a high-performance batch calculation on history and returns
/// a "Hot" Amat instance ready to process the next tick immediately.
@@ -600,16 +613,4 @@ public sealed class Amat : ITValuePublisher, IDisposable
return (results, amat);
}
/// <summary>
/// Calculates AMAT for the entire series using a new instance.
/// </summary>
/// <param name="source">Input series</param>
/// <param name="fastPeriod">Fast EMA period</param>
/// <param name="slowPeriod">Slow EMA period</param>
/// <returns>AMAT trend series</returns>
public static TSeries Batch(TSeries source, int fastPeriod = 10, int slowPeriod = 50)
{
var amat = new Amat(fastPeriod, slowPeriod);
return amat.Update(source);
}
}