mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-26 06:18:05 +00:00
docs: remove C# Implementation Considerations sections, clean up temp scripts, reorganize test files
- 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
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
using TradingPlatform.BusinessLayer;
|
||||
|
||||
namespace QuanTAlib.Tests;
|
||||
|
||||
public class AlmaIndicatorTests
|
||||
{
|
||||
[Fact]
|
||||
public void AlmaIndicator_Constructor_SetsDefaults()
|
||||
{
|
||||
var indicator = new AlmaIndicator();
|
||||
|
||||
Assert.Equal(9, indicator.Period);
|
||||
Assert.Equal(0.85, indicator.Offset);
|
||||
Assert.Equal(6.0, indicator.Sigma);
|
||||
Assert.Equal(SourceType.Close, indicator.Source);
|
||||
Assert.True(indicator.ShowColdValues);
|
||||
Assert.Equal("ALMA - Arnaud Legoux Moving Average", indicator.Name);
|
||||
Assert.False(indicator.SeparateWindow);
|
||||
Assert.True(indicator.OnBackGround);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AlmaIndicator_MinHistoryDepths_EqualsPeriod()
|
||||
{
|
||||
var indicator = new AlmaIndicator { Period = 20 };
|
||||
|
||||
Assert.Equal(0, AlmaIndicator.MinHistoryDepths);
|
||||
Assert.Equal(0, ((IWatchlistIndicator)indicator).MinHistoryDepths);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AlmaIndicator_ShortName_IncludesPeriodAndSource()
|
||||
{
|
||||
var indicator = new AlmaIndicator { Period = 15 };
|
||||
|
||||
Assert.Contains("ALMA", indicator.ShortName, StringComparison.Ordinal);
|
||||
Assert.Contains("15", indicator.ShortName, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AlmaIndicator_Initialize_CreatesInternalAlma()
|
||||
{
|
||||
var indicator = new AlmaIndicator { Period = 10 };
|
||||
|
||||
// Initialize should not throw
|
||||
indicator.Initialize();
|
||||
|
||||
// After init, line series should exist
|
||||
Assert.Single(indicator.LinesSeries);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AlmaIndicator_ProcessUpdate_HistoricalBar_ComputesValue()
|
||||
{
|
||||
var indicator = new AlmaIndicator { Period = 3 };
|
||||
indicator.Initialize();
|
||||
|
||||
// Add historical data
|
||||
var now = DateTime.UtcNow;
|
||||
indicator.HistoricalData.AddBar(now, 100, 105, 95, 102);
|
||||
|
||||
// Process update
|
||||
var args = new UpdateArgs(UpdateReason.HistoricalBar);
|
||||
indicator.ProcessUpdate(args);
|
||||
|
||||
// Line series should have a value
|
||||
Assert.Equal(1, indicator.LinesSeries[0].Count);
|
||||
Assert.True(double.IsFinite(indicator.LinesSeries[0].GetValue(0)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AlmaIndicator_ProcessUpdate_NewBar_ComputesValue()
|
||||
{
|
||||
var indicator = new AlmaIndicator { Period = 3 };
|
||||
indicator.Initialize();
|
||||
|
||||
// Add historical data
|
||||
var now = DateTime.UtcNow;
|
||||
indicator.HistoricalData.AddBar(now, 100, 105, 95, 102);
|
||||
indicator.HistoricalData.AddBar(now.AddMinutes(1), 102, 108, 100, 106);
|
||||
|
||||
// Process first update
|
||||
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
|
||||
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.NewBar));
|
||||
|
||||
// Line series should have values
|
||||
Assert.Equal(2, indicator.LinesSeries[0].Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AlmaIndicator_ProcessUpdate_NewTick_ProcessesWithoutError()
|
||||
{
|
||||
var indicator = new AlmaIndicator { Period = 3 };
|
||||
indicator.Initialize();
|
||||
|
||||
// Add historical data
|
||||
var now = DateTime.UtcNow;
|
||||
indicator.HistoricalData.AddBar(now, 100, 105, 95, 102);
|
||||
|
||||
// Process historical bar first
|
||||
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
|
||||
double firstValue = indicator.LinesSeries[0].GetValue(0);
|
||||
|
||||
// Update with new tick (same bar data - simulates intrabar update)
|
||||
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.NewTick));
|
||||
double secondValue = indicator.LinesSeries[0].GetValue(0);
|
||||
|
||||
// Both values should be finite
|
||||
Assert.True(double.IsFinite(firstValue));
|
||||
Assert.True(double.IsFinite(secondValue));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AlmaIndicator_MultipleUpdates_ProducesCorrectAlmaSequence()
|
||||
{
|
||||
var indicator = new AlmaIndicator { Period = 3 };
|
||||
indicator.Initialize();
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
double[] closes = { 100, 102, 104, 103, 105, 107, 106 };
|
||||
|
||||
foreach (var close in closes)
|
||||
{
|
||||
indicator.HistoricalData.AddBar(now, close, close + 2, close - 2, close);
|
||||
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
|
||||
now = now.AddMinutes(1);
|
||||
}
|
||||
|
||||
// All values should be finite
|
||||
for (int i = 0; i < closes.Length; i++)
|
||||
{
|
||||
Assert.True(double.IsFinite(indicator.LinesSeries[0].GetValue(closes.Length - 1 - i)));
|
||||
}
|
||||
|
||||
// ALMA should be smoothing the values
|
||||
double lastAlma = indicator.LinesSeries[0].GetValue(0);
|
||||
Assert.True(lastAlma >= 100 && lastAlma <= 110);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AlmaIndicator_DifferentSourceTypes_Work()
|
||||
{
|
||||
var sources = new[] { SourceType.Open, SourceType.High, SourceType.Low, SourceType.Close, SourceType.HL2, SourceType.HLC3 };
|
||||
|
||||
foreach (var source in sources)
|
||||
{
|
||||
var indicator = new AlmaIndicator { Period = 3, Source = source };
|
||||
indicator.Initialize();
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
indicator.HistoricalData.AddBar(now, 100, 110, 90, 105);
|
||||
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
|
||||
|
||||
Assert.True(double.IsFinite(indicator.LinesSeries[0].GetValue(0)),
|
||||
$"Source {source} should produce finite value");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AlmaIndicator_Period_CanBeChanged()
|
||||
{
|
||||
var indicator = new AlmaIndicator { Period = 5 };
|
||||
Assert.Equal(5, indicator.Period);
|
||||
|
||||
indicator.Period = 20;
|
||||
Assert.Equal(20, indicator.Period);
|
||||
Assert.Equal(0, AlmaIndicator.MinHistoryDepths);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,341 @@
|
||||
|
||||
namespace QuanTAlib.Tests;
|
||||
|
||||
public class AlmaTests
|
||||
{
|
||||
[Fact]
|
||||
public void Alma_Constructor_ValidatesInput()
|
||||
{
|
||||
var ex1 = Assert.Throws<ArgumentException>(() => new Alma(0));
|
||||
Assert.Equal("period", ex1.ParamName);
|
||||
|
||||
var ex2 = Assert.Throws<ArgumentException>(() => new Alma(10, sigma: 0));
|
||||
Assert.Equal("sigma", ex2.ParamName);
|
||||
|
||||
var ex3 = Assert.Throws<ArgumentOutOfRangeException>(() => new Alma(10, offset: -0.1));
|
||||
Assert.Equal("offset", ex3.ParamName);
|
||||
|
||||
var ex4 = Assert.Throws<ArgumentOutOfRangeException>(() => new Alma(10, offset: 1.1));
|
||||
Assert.Equal("offset", ex4.ParamName);
|
||||
|
||||
var alma = new Alma(10);
|
||||
Assert.NotNull(alma);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Alma_Calc_ReturnsValue()
|
||||
{
|
||||
var alma = new Alma(10);
|
||||
TValue result = alma.Update(new TValue(DateTime.UtcNow, 100));
|
||||
Assert.True(result.Value > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Alma_IsHot_BecomesTrueWhenBufferFull()
|
||||
{
|
||||
var alma = new Alma(5);
|
||||
|
||||
Assert.False(alma.IsHot);
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
alma.Update(new TValue(DateTime.UtcNow, 100));
|
||||
Assert.False(alma.IsHot);
|
||||
}
|
||||
|
||||
alma.Update(new TValue(DateTime.UtcNow, 100));
|
||||
Assert.True(alma.IsHot);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Alma_StreamingMatchesBatch()
|
||||
{
|
||||
var almaStreaming = new Alma(10);
|
||||
var almaBatch = new Alma(10);
|
||||
var gbm = new GBM(startPrice: 100.0, mu: 0.05, sigma: 0.2, seed: 42);
|
||||
var series = new TSeries();
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
var bar = gbm.Next(isNew: true);
|
||||
series.Add(new TValue(bar.Time, bar.Close));
|
||||
}
|
||||
|
||||
// Streaming
|
||||
var streamingResults = new TSeries();
|
||||
Assert.True(series.Count > 0);
|
||||
foreach (var item in series)
|
||||
{
|
||||
streamingResults.Add(almaStreaming.Update(item));
|
||||
}
|
||||
|
||||
// Batch
|
||||
var batchResults = almaBatch.Update(series);
|
||||
|
||||
Assert.Equal(streamingResults.Count, batchResults.Count);
|
||||
for (int i = 0; i < batchResults.Count; i++)
|
||||
{
|
||||
Assert.Equal(streamingResults[i].Value, batchResults[i].Value, 1e-9);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Alma_StaticCalculate_MatchesInstance()
|
||||
{
|
||||
var series = new TSeries();
|
||||
var gbm = new GBM(startPrice: 100.0, mu: 0.05, sigma: 0.2, seed: 42);
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
var bar = gbm.Next(isNew: true);
|
||||
series.Add(bar.Time, bar.Close);
|
||||
}
|
||||
|
||||
var instanceResults = new Alma(10).Update(series);
|
||||
var staticResults = Alma.Batch(series, 10);
|
||||
|
||||
for (int i = 0; i < instanceResults.Count; i++)
|
||||
{
|
||||
Assert.Equal(instanceResults[i].Value, staticResults[i].Value, 1e-9);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Alma_SpanCalculate_MatchesSeries()
|
||||
{
|
||||
var series = new TSeries();
|
||||
var gbm = new GBM(startPrice: 100.0, mu: 0.05, sigma: 0.2, seed: 42);
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
var bar = gbm.Next(isNew: true);
|
||||
series.Add(bar.Time, bar.Close);
|
||||
}
|
||||
|
||||
var seriesResults = Alma.Batch(series, 10);
|
||||
|
||||
double[] input = series.Values.ToArray();
|
||||
double[] output = new double[input.Length];
|
||||
|
||||
Alma.Batch(input.AsSpan(), output.AsSpan(), 10);
|
||||
|
||||
for (int i = 0; i < input.Length; i++)
|
||||
{
|
||||
Assert.Equal(seriesResults[i].Value, output[i], 1e-9);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Alma_Update_IsNewFalse_CorrectsValue()
|
||||
{
|
||||
var alma = new Alma(10);
|
||||
var gbm = new GBM(startPrice: 100.0, mu: 0.05, sigma: 0.2, seed: 42);
|
||||
|
||||
// Feed initial data
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
var bar = gbm.Next(isNew: true);
|
||||
alma.Update(new TValue(bar.Time, bar.Close), isNew: true);
|
||||
}
|
||||
|
||||
// Update with isNew=false (correction)
|
||||
var newBar = gbm.Next(isNew: true);
|
||||
alma.Update(new TValue(newBar.Time, newBar.Close), isNew: true);
|
||||
|
||||
double valueAfterCommit = alma.Last.Value;
|
||||
|
||||
// Now update the SAME bar with a different value
|
||||
alma.Update(new TValue(newBar.Time, newBar.Close + 10.0), isNew: false);
|
||||
|
||||
double valueAfterCorrection = alma.Last.Value;
|
||||
|
||||
Assert.NotEqual(valueAfterCommit, valueAfterCorrection);
|
||||
|
||||
// Now restore original value
|
||||
alma.Update(new TValue(newBar.Time, newBar.Close), isNew: false);
|
||||
|
||||
Assert.Equal(valueAfterCommit, alma.Last.Value, 1e-9);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Alma_NaN_Input_UsesLastValidValue()
|
||||
{
|
||||
var alma = new Alma(5);
|
||||
|
||||
alma.Update(new TValue(DateTime.UtcNow, 100));
|
||||
alma.Update(new TValue(DateTime.UtcNow, 110));
|
||||
|
||||
var resultAfterNaN = alma.Update(new TValue(DateTime.UtcNow, double.NaN));
|
||||
|
||||
Assert.True(double.IsFinite(resultAfterNaN.Value));
|
||||
Assert.NotEqual(0, resultAfterNaN.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Alma_Reset_ClearsState()
|
||||
{
|
||||
var alma = new Alma(10);
|
||||
alma.Update(new TValue(DateTime.UtcNow, 100));
|
||||
alma.Update(new TValue(DateTime.UtcNow, 110));
|
||||
|
||||
Assert.True(alma.Last.Value > 0);
|
||||
|
||||
alma.Reset();
|
||||
|
||||
Assert.Equal(0, alma.Last.Value);
|
||||
Assert.False(alma.IsHot);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Alma_FirstValue_ReturnsExpected()
|
||||
{
|
||||
var alma = new Alma(10);
|
||||
TValue result = alma.Update(new TValue(DateTime.UtcNow, 100));
|
||||
Assert.Equal(100.0, result.Value, 1e-9);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Alma_Properties_Accessible()
|
||||
{
|
||||
var alma = new Alma(10);
|
||||
Assert.False(alma.IsHot);
|
||||
Assert.Equal(0, alma.Last.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Alma_Calc_IsNew_AcceptsParameter()
|
||||
{
|
||||
var alma = new Alma(10);
|
||||
alma.Update(new TValue(DateTime.UtcNow, 100), isNew: true);
|
||||
Assert.Equal(100, alma.Last.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Alma_IterativeCorrections_RestoreToOriginalState()
|
||||
{
|
||||
var alma = new Alma(10);
|
||||
var gbm = new GBM(startPrice: 100.0, mu: 0.02, sigma: 0.1);
|
||||
|
||||
// Feed 10 new values
|
||||
TValue tenthInput = default;
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var bar = gbm.Next(isNew: true);
|
||||
tenthInput = new TValue(bar.Time, bar.Close);
|
||||
alma.Update(tenthInput, isNew: true);
|
||||
}
|
||||
|
||||
// Remember state after 10 values
|
||||
double valueAfterTen = alma.Last.Value;
|
||||
|
||||
// Generate 9 corrections with isNew=false (different values)
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
var bar = gbm.Next(isNew: false);
|
||||
alma.Update(new TValue(bar.Time, bar.Close), isNew: false);
|
||||
}
|
||||
|
||||
// Feed the remembered 10th input again with isNew=false
|
||||
TValue finalValue = alma.Update(tenthInput, isNew: false);
|
||||
|
||||
// Should match the original state after 10 values
|
||||
Assert.Equal(valueAfterTen, finalValue.Value, 1e-9);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Alma_Infinity_Input_UsesLastValidValue()
|
||||
{
|
||||
var alma = new Alma(10);
|
||||
alma.Update(new TValue(DateTime.UtcNow, 100));
|
||||
alma.Update(new TValue(DateTime.UtcNow, 110));
|
||||
|
||||
var resultPosInf = alma.Update(new TValue(DateTime.UtcNow, double.PositiveInfinity));
|
||||
Assert.True(double.IsFinite(resultPosInf.Value));
|
||||
|
||||
var resultNegInf = alma.Update(new TValue(DateTime.UtcNow, double.NegativeInfinity));
|
||||
Assert.True(double.IsFinite(resultNegInf.Value));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Alma_MultipleNaN_ContinuesWithLastValid()
|
||||
{
|
||||
var alma = new Alma(10);
|
||||
alma.Update(new TValue(DateTime.UtcNow, 100));
|
||||
|
||||
var r1 = alma.Update(new TValue(DateTime.UtcNow, double.NaN));
|
||||
var r2 = alma.Update(new TValue(DateTime.UtcNow, double.NaN));
|
||||
|
||||
Assert.True(double.IsFinite(r1.Value));
|
||||
Assert.True(double.IsFinite(r2.Value));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Alma_AllModes_ProduceSameResult()
|
||||
{
|
||||
// Arrange
|
||||
const int period = 10;
|
||||
var gbm = new GBM(startPrice: 100, mu: 0.05, sigma: 0.2, seed: 123);
|
||||
var bars = gbm.Fetch(1000, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
|
||||
var series = bars.Close;
|
||||
|
||||
// 1. Batch Mode
|
||||
var batchSeries = Alma.Batch(series, period);
|
||||
double expected = batchSeries.Last.Value;
|
||||
|
||||
// 2. Span Mode
|
||||
var tValues = series.Values.ToArray();
|
||||
var spanInput = new ReadOnlySpan<double>(tValues);
|
||||
var spanOutput = new double[tValues.Length];
|
||||
Alma.Batch(spanInput, spanOutput, period);
|
||||
double spanResult = spanOutput[^1];
|
||||
|
||||
// 3. Streaming Mode
|
||||
var streamingInd = new Alma(period);
|
||||
for (int i = 0; i < series.Count; i++)
|
||||
{
|
||||
streamingInd.Update(series[i]);
|
||||
}
|
||||
double streamingResult = streamingInd.Last.Value;
|
||||
|
||||
// 4. Eventing Mode
|
||||
var pubSource = new TSeries();
|
||||
var eventingInd = new Alma(pubSource, period);
|
||||
for (int i = 0; i < series.Count; i++)
|
||||
{
|
||||
pubSource.Add(series[i]);
|
||||
}
|
||||
double eventingResult = eventingInd.Last.Value;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expected, spanResult, 1e-9);
|
||||
Assert.Equal(expected, streamingResult, 1e-9);
|
||||
Assert.Equal(expected, eventingResult, 1e-9);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Alma_SpanCalc_ValidatesInput()
|
||||
{
|
||||
double[] source = [1, 2, 3, 4, 5];
|
||||
double[] output = new double[5];
|
||||
double[] wrongSizeOutput = new double[3];
|
||||
|
||||
Assert.Throws<ArgumentException>(() => Alma.Batch(source.AsSpan(), output.AsSpan(), 0));
|
||||
Assert.Throws<ArgumentException>(() => Alma.Batch(source.AsSpan(), output.AsSpan(), 3, sigma: 0));
|
||||
Assert.Throws<ArgumentException>(() => Alma.Batch(source.AsSpan(), output.AsSpan(), 3, sigma: -1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Alma.Batch(source.AsSpan(), output.AsSpan(), 3, offset: -0.1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Alma.Batch(source.AsSpan(), output.AsSpan(), 3, offset: 1.1));
|
||||
Assert.Throws<ArgumentException>(() => Alma.Batch(source.AsSpan(), wrongSizeOutput.AsSpan(), 3));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Alma_SpanCalc_HandlesNaN()
|
||||
{
|
||||
double[] source = [100, 110, double.NaN, 120, 130];
|
||||
double[] output = new double[5];
|
||||
|
||||
Alma.Batch(source.AsSpan(), output.AsSpan(), 3);
|
||||
|
||||
foreach (var val in output)
|
||||
{
|
||||
Assert.True(double.IsFinite(val));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
using Skender.Stock.Indicators;
|
||||
using OoplesFinance.StockIndicators;
|
||||
using OoplesFinance.StockIndicators.Models;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace QuanTAlib.Tests;
|
||||
|
||||
public sealed class AlmaValidationTests : IDisposable
|
||||
{
|
||||
// Note: ALMA is not available in TA-Lib or Tulip,
|
||||
// validation is limited to Skender.Stock.Indicators and OoplesFinance.StockIndicators.
|
||||
|
||||
private readonly ValidationTestData _testData;
|
||||
private readonly ITestOutputHelper _output;
|
||||
private bool _disposed;
|
||||
|
||||
public AlmaValidationTests(ITestOutputHelper output)
|
||||
{
|
||||
_output = output;
|
||||
_testData = new ValidationTestData(count: 10000, seed: 42);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_disposed = true;
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
_testData?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_Skender_Batch()
|
||||
{
|
||||
int[] periods = { 9, 14, 20, 50 };
|
||||
const double offset = 0.85;
|
||||
double sigma = 6.0;
|
||||
|
||||
foreach (var period in periods)
|
||||
{
|
||||
// Calculate QuanTAlib ALMA (batch TSeries)
|
||||
var alma = new global::QuanTAlib.Alma(period, offset, sigma);
|
||||
var qResult = alma.Update(_testData.Data);
|
||||
|
||||
// Calculate Skender ALMA
|
||||
var sResult = _testData.SkenderQuotes.GetAlma(period, offset, sigma).ToList();
|
||||
|
||||
// Compare last 100 records
|
||||
ValidationHelper.VerifyData(qResult, sResult, (s) => s.Alma);
|
||||
}
|
||||
_output.WriteLine("ALMA Batch(TSeries) validated successfully against Skender");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_Skender_Streaming()
|
||||
{
|
||||
int[] periods = { 9, 14, 20, 50 };
|
||||
double offset = 0.85;
|
||||
double sigma = 6.0;
|
||||
|
||||
foreach (var period in periods)
|
||||
{
|
||||
// Calculate QuanTAlib ALMA (streaming)
|
||||
var alma = new global::QuanTAlib.Alma(period, offset, sigma);
|
||||
var qResults = new List<double>();
|
||||
foreach (var item in _testData.Data)
|
||||
{
|
||||
qResults.Add(alma.Update(item).Value);
|
||||
}
|
||||
|
||||
// Calculate Skender ALMA
|
||||
var sResult = _testData.SkenderQuotes.GetAlma(period, offset, sigma).ToList();
|
||||
|
||||
// Compare last 100 records
|
||||
ValidationHelper.VerifyData(qResults, sResult, (s) => s.Alma);
|
||||
}
|
||||
_output.WriteLine("ALMA Streaming validated successfully against Skender");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_Skender_Span()
|
||||
{
|
||||
int[] periods = { 9, 14, 20, 50 };
|
||||
double offset = 0.85;
|
||||
double sigma = 6.0;
|
||||
|
||||
// Prepare data for Span API
|
||||
ReadOnlySpan<double> sourceData = _testData.RawData.Span;
|
||||
|
||||
foreach (var period in periods)
|
||||
{
|
||||
// Calculate QuanTAlib ALMA (Span API)
|
||||
double[] qOutput = new double[sourceData.Length];
|
||||
global::QuanTAlib.Alma.Batch(sourceData, qOutput.AsSpan(), period, offset, sigma);
|
||||
|
||||
// Calculate Skender ALMA
|
||||
var sResult = _testData.SkenderQuotes.GetAlma(period, offset, sigma).ToList();
|
||||
|
||||
// Compare last 100 records
|
||||
ValidationHelper.VerifyData(qOutput, sResult, (s) => s.Alma);
|
||||
}
|
||||
_output.WriteLine("ALMA Span validated successfully against Skender");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_Ooples_Batch()
|
||||
{
|
||||
int[] periods = { 9, 14, 20, 50 };
|
||||
double offset = 0.85;
|
||||
double sigma = 6.0;
|
||||
|
||||
// Prepare data for Ooples
|
||||
var ooplesData = _testData.SkenderQuotes.Select(q => new TickerData
|
||||
{
|
||||
Date = q.Date,
|
||||
Open = (double)q.Open,
|
||||
High = (double)q.High,
|
||||
Low = (double)q.Low,
|
||||
Close = (double)q.Close,
|
||||
Volume = (double)q.Volume
|
||||
}).ToList();
|
||||
|
||||
foreach (var period in periods)
|
||||
{
|
||||
// 1. Calculate Ooples ALMA
|
||||
var stockData = new StockData(ooplesData);
|
||||
var oResult = stockData.CalculateArnaudLegouxMovingAverage(period, offset, (int)sigma);
|
||||
var oAlma = oResult.OutputValues["Alma"];
|
||||
|
||||
// 2. Calculate QuanTAlib ALMA
|
||||
var alma = new global::QuanTAlib.Alma(period, offset, sigma);
|
||||
var qResult = alma.Update(_testData.Data);
|
||||
|
||||
// 3. Verify
|
||||
ValidationHelper.VerifyData(qResult, oAlma, x => x, skip: 100, tolerance: ValidationHelper.OoplesTolerance);
|
||||
}
|
||||
_output.WriteLine("ALMA Batch validated successfully against Ooples");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user