mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-08 05:57:43 +00:00
060649192f
- Remove 'C# Implementation Considerations' sections from 34 indicator .md files - Delete 29 temp PowerShell scripts (_fix_mojibake.ps1, _hex_scan.ps1, etc.) - Move test files into tests/ subdirectories for consistent project structure - Add trader-focused bullet points to indicator documentation
101 lines
3.4 KiB
C#
101 lines
3.4 KiB
C#
using Skender.Stock.Indicators;
|
|
using Xunit.Abstractions;
|
|
|
|
using OoplesFinance.StockIndicators;
|
|
using OoplesFinance.StockIndicators.Models;
|
|
|
|
namespace QuanTAlib.Tests;
|
|
|
|
public class LsmaValidationTests
|
|
{
|
|
private readonly ValidationTestData _testData;
|
|
private readonly ITestOutputHelper _output;
|
|
|
|
public LsmaValidationTests(ITestOutputHelper output)
|
|
{
|
|
_output = output;
|
|
_testData = new ValidationTestData();
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_Skender_Batch()
|
|
{
|
|
int[] periods = { 5, 10, 20, 50, 100 };
|
|
|
|
foreach (var period in periods)
|
|
{
|
|
// Calculate QuanTAlib LSMA (batch TSeries)
|
|
var lsma = new global::QuanTAlib.Lsma(period);
|
|
var qResult = lsma.Update(_testData.Data);
|
|
|
|
// Calculate Skender EPMA (Endpoint Moving Average = LSMA)
|
|
var sResult = _testData.SkenderQuotes.GetEpma(period).ToList();
|
|
|
|
// Compare last 100 records
|
|
ValidationHelper.VerifyData(qResult, sResult, x => x.Epma, tolerance: ValidationHelper.OoplesTolerance);
|
|
}
|
|
_output.WriteLine("LSMA Batch(TSeries) validated successfully against Skender");
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_Skender_Streaming()
|
|
{
|
|
int[] periods = { 5, 10, 20, 50, 100 };
|
|
|
|
foreach (var period in periods)
|
|
{
|
|
// Calculate QuanTAlib LSMA (streaming)
|
|
var lsma = new global::QuanTAlib.Lsma(period);
|
|
var qResults = new List<double>();
|
|
foreach (var item in _testData.Data)
|
|
{
|
|
qResults.Add(lsma.Update(item).Value);
|
|
}
|
|
|
|
// Calculate Skender EPMA
|
|
var sResult = _testData.SkenderQuotes.GetEpma(period).ToList();
|
|
|
|
// Compare last 100 records
|
|
ValidationHelper.VerifyData(qResults, sResult, x => x.Epma, tolerance: ValidationHelper.OoplesTolerance);
|
|
}
|
|
_output.WriteLine("LSMA Streaming validated successfully against Skender");
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_Skender_Span()
|
|
{
|
|
int[] periods = { 5, 10, 20, 50, 100 };
|
|
|
|
foreach (var period in periods)
|
|
{
|
|
// Calculate QuanTAlib LSMA (Span API)
|
|
double[] qOutput = new double[_testData.RawData.Length];
|
|
global::QuanTAlib.Lsma.Batch(_testData.RawData.Span, qOutput.AsSpan(), period);
|
|
|
|
// Calculate Skender EPMA
|
|
var sResult = _testData.SkenderQuotes.GetEpma(period).ToList();
|
|
|
|
// Compare last 100 records
|
|
ValidationHelper.VerifyData(qOutput, sResult, x => x.Epma, tolerance: ValidationHelper.OoplesTolerance);
|
|
}
|
|
_output.WriteLine("LSMA Span validated successfully against Skender");
|
|
}
|
|
|
|
[Fact]
|
|
public void Lsma_MatchesOoples_Structural()
|
|
{
|
|
var gbm = new GBM(startPrice: 100.0, mu: 0.02, sigma: 0.15, seed: 42);
|
|
var bars = gbm.Fetch(500, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
|
|
var ooplesData = bars.Select(b => new TickerData
|
|
{
|
|
Date = new DateTime(b.Time, DateTimeKind.Utc),
|
|
Open = b.Open, High = b.High, Low = b.Low,
|
|
Close = b.Close, Volume = b.Volume
|
|
}).ToList();
|
|
var result = new StockData(ooplesData).CalculateAdaptiveLeastSquares();
|
|
var values = result.CustomValuesList;
|
|
int finiteCount = values.Count(v => double.IsFinite(v));
|
|
Assert.True(finiteCount > 100, $"Expected >100 finite values, got {finiteCount}");
|
|
}
|
|
}
|