feat(tests): enhance tests with GBM for noise generation and improve tolerance for MAMA validation

feat(trends): implement IDisposable in Bessel and Conv classes to manage event subscriptions
fix(trends): add validation for period and parameters in Kama and MGDI calculations
fix(trends): clamp logarithmic calculations in JMA to avoid -Infinity
This commit is contained in:
Miha Kralj
2025-12-25 20:18:14 -08:00
parent df598c810d
commit ac8b2dbb3f
20 changed files with 281 additions and 187 deletions
@@ -12,13 +12,14 @@ public class CovarianceSimdTests
// Arrange
int count = 1000; // > 256 to trigger SIMD
int period = 20;
var r = new Random(42);
var gbmX = new GBM(startPrice: 100, mu: 0.05, sigma: 0.2, seed: 42);
var gbmY = new GBM(startPrice: 100, mu: 0.05, sigma: 0.2, seed: 123);
var dataX = new double[count];
var dataY = new double[count];
for (int i = 0; i < count; i++)
{
dataX[i] = r.NextDouble() * 100;
dataY[i] = r.NextDouble() * 100;
dataX[i] = gbmX.Next().Close;
dataY[i] = gbmY.Next().Close;
}
var sourceX = new TSeries();
@@ -11,14 +11,15 @@ public class CovarianceValidationTests
// Arrange
int period = 10;
var cov = new Covariance(period, isPopulation: false);
var r = new Random(123);
var gbmX = new GBM(startPrice: 100, mu: 0.05, sigma: 0.2, seed: 123);
var gbmY = new GBM(startPrice: 100, mu: 0.05, sigma: 0.2, seed: 456);
double[] x = new double[100];
double[] y = new double[100];
for (int i = 0; i < 100; i++)
{
x[i] = r.NextDouble() * 100;
y[i] = r.NextDouble() * 100;
x[i] = gbmX.Next().Close;
y[i] = gbmY.Next().Close;
cov.Update(x[i], y[i]);
if (i >= period - 1)
@@ -52,14 +53,15 @@ public class CovarianceValidationTests
// Arrange
int period = 10;
var cov = new Covariance(period, isPopulation: true);
var r = new Random(456);
var gbmX = new GBM(startPrice: 100, mu: 0.05, sigma: 0.2, seed: 456);
var gbmY = new GBM(startPrice: 100, mu: 0.05, sigma: 0.2, seed: 789);
double[] x = new double[100];
double[] y = new double[100];
for (int i = 0; i < 100; i++)
{
x[i] = r.NextDouble() * 100;
y[i] = r.NextDouble() * 100;
x[i] = gbmX.Next().Close;
y[i] = gbmY.Next().Close;
cov.Update(x[i], y[i]);
if (i >= period - 1)