Refactor validation tests for various indicators to utilize shared test data structure

This commit is contained in:
Miha Kralj
2025-12-12 13:47:57 -08:00
parent e6033638ad
commit cea3e0c46d
29 changed files with 1167 additions and 1804 deletions
+58
View File
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Skender.Stock.Indicators;
namespace QuanTAlib.Tests;
public class ValidationTestData : IDisposable
{
public TBarSeries Bars { get; }
public TSeries Data { get; }
public IReadOnlyList<Quote> SkenderQuotes { get; }
public ReadOnlyMemory<double> RawData { get; }
public ValidationTestData(int count = 5000, double startPrice = 1000000.0, double mu = 0.05, double sigma = 2.0, int seed = 123)
{
var gbm = new GBM(startPrice, mu, sigma, seed: seed);
Bars = gbm.Fetch(count, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
Data = Bars.Close;
RawData = Data.Select(x => x.Value).ToArray();
var quotes = new List<Quote>();
for (int i = 0; i < Bars.Count; i++)
{
quotes.Add(new Quote
{
Date = new DateTime(Bars.Open.Times[i], DateTimeKind.Utc),
Open = (decimal)Bars.Open[i].Value,
High = (decimal)Bars.High[i].Value,
Low = (decimal)Bars.Low[i].Value,
Close = (decimal)Bars.Close[i].Value,
Volume = (decimal)Bars.Volume[i].Value
});
}
SkenderQuotes = quotes;
}
private bool _disposed;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
// Dispose managed state (managed objects)
}
_disposed = true;
}
}
}