mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-25 22:08: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,172 @@
|
||||
using TradingPlatform.BusinessLayer;
|
||||
|
||||
namespace QuanTAlib.Tests;
|
||||
|
||||
public class T3IndicatorTests
|
||||
{
|
||||
[Fact]
|
||||
public void T3Indicator_Constructor_SetsDefaults()
|
||||
{
|
||||
var indicator = new T3Indicator();
|
||||
|
||||
Assert.Equal(10, indicator.Period);
|
||||
Assert.Equal(0.7, indicator.VolumeFactor);
|
||||
Assert.Equal(SourceType.Close, indicator.Source);
|
||||
Assert.True(indicator.ShowColdValues);
|
||||
Assert.Equal("T3 - Tillson T3 Moving Average", indicator.Name);
|
||||
Assert.False(indicator.SeparateWindow);
|
||||
Assert.True(indicator.OnBackGround);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void T3Indicator_MinHistoryDepths_EqualsSixTimesPeriod()
|
||||
{
|
||||
var indicator = new T3Indicator { Period = 10 };
|
||||
|
||||
// MinHistoryDepths is Period * 6 for T3 due to 6 stages
|
||||
Assert.Equal(0, T3Indicator.MinHistoryDepths);
|
||||
Assert.Equal(0, ((IWatchlistIndicator)indicator).MinHistoryDepths);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void T3Indicator_ShortName_IncludesPeriodAndFactor()
|
||||
{
|
||||
var indicator = new T3Indicator { Period = 15, VolumeFactor = 0.618 };
|
||||
|
||||
Assert.Contains("T3", indicator.ShortName, StringComparison.Ordinal);
|
||||
Assert.Contains("15", indicator.ShortName, StringComparison.Ordinal);
|
||||
Assert.Contains("0.62", indicator.ShortName, StringComparison.Ordinal); // F2 formatting
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void T3Indicator_Initialize_CreatesInternalT3()
|
||||
{
|
||||
var indicator = new T3Indicator { Period = 10 };
|
||||
|
||||
// Initialize should not throw
|
||||
indicator.Initialize();
|
||||
|
||||
// After init, line series should exist
|
||||
Assert.Single(indicator.LinesSeries);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void T3Indicator_ProcessUpdate_HistoricalBar_ComputesValue()
|
||||
{
|
||||
var indicator = new T3Indicator { 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 T3Indicator_ProcessUpdate_NewBar_ComputesValue()
|
||||
{
|
||||
var indicator = new T3Indicator { 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 T3Indicator_ProcessUpdate_NewTick_ProcessesWithoutError()
|
||||
{
|
||||
var indicator = new T3Indicator { 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 T3Indicator_MultipleUpdates_ProducesCorrectT3Sequence()
|
||||
{
|
||||
var indicator = new T3Indicator { 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)));
|
||||
}
|
||||
|
||||
double lastT3 = indicator.LinesSeries[0].GetValue(0);
|
||||
Assert.True(lastT3 >= 100 && lastT3 <= 110);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void T3Indicator_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 T3Indicator { 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 T3Indicator_Parameters_CanBeChanged()
|
||||
{
|
||||
var indicator = new T3Indicator { Period = 5, VolumeFactor = 0.5 };
|
||||
Assert.Equal(5, indicator.Period);
|
||||
Assert.Equal(0.5, indicator.VolumeFactor);
|
||||
|
||||
indicator.Period = 20;
|
||||
indicator.VolumeFactor = 0.9;
|
||||
Assert.Equal(20, indicator.Period);
|
||||
Assert.Equal(0.9, indicator.VolumeFactor);
|
||||
Assert.Equal(0, T3Indicator.MinHistoryDepths); // 20 * 6
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
|
||||
namespace QuanTAlib.Tests;
|
||||
|
||||
public class T3Tests
|
||||
{
|
||||
[Fact]
|
||||
public void BasicCalculation_DoesNotCrash()
|
||||
{
|
||||
var t3 = new T3(5, 0.7);
|
||||
var gbm = new GBM();
|
||||
var bars = gbm.Fetch(1000, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
|
||||
|
||||
for (int i = 0; i < bars.Count; i++)
|
||||
{
|
||||
t3.Update(new TValue(bars[i].Time, bars[i].Close));
|
||||
}
|
||||
|
||||
Assert.True(double.IsFinite(t3.Last.Value));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsNew_Consistency()
|
||||
{
|
||||
var t3 = new T3(5, 0.7);
|
||||
var gbm = new GBM();
|
||||
var bars = gbm.Fetch(100, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
|
||||
|
||||
// Feed first 99
|
||||
for (int i = 0; i < 99; i++)
|
||||
{
|
||||
t3.Update(new TValue(bars[i].Time, bars[i].Close));
|
||||
}
|
||||
|
||||
// Update with 100th point (isNew=true)
|
||||
t3.Update(new TValue(bars[99].Time, bars[99].Close), true);
|
||||
|
||||
// Update with modified 100th point (isNew=false)
|
||||
var val2 = t3.Update(new TValue(bars[99].Time, bars[99].Close + 1.0), false);
|
||||
|
||||
// Create new instance and feed up to modified
|
||||
var t3_2 = new T3(5, 0.7);
|
||||
for (int i = 0; i < 99; i++)
|
||||
{
|
||||
t3_2.Update(new TValue(bars[i].Time, bars[i].Close));
|
||||
}
|
||||
var val3 = t3_2.Update(new TValue(bars[99].Time, bars[99].Close + 1.0), true);
|
||||
|
||||
Assert.Equal(val3.Value, val2.Value, 1e-9);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Reset_Works()
|
||||
{
|
||||
var t3 = new T3(5, 0.7);
|
||||
var gbm = new GBM();
|
||||
var bars = gbm.Fetch(100, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
|
||||
|
||||
for (int i = 0; i < bars.Count; i++)
|
||||
{
|
||||
t3.Update(new TValue(bars[i].Time, bars[i].Close));
|
||||
}
|
||||
|
||||
t3.Reset();
|
||||
Assert.Equal(0, t3.Last.Value);
|
||||
Assert.False(t3.IsHot);
|
||||
|
||||
// Feed again
|
||||
for (int i = 0; i < bars.Count; i++)
|
||||
{
|
||||
t3.Update(new TValue(bars[i].Time, bars[i].Close));
|
||||
}
|
||||
|
||||
Assert.True(double.IsFinite(t3.Last.Value));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TSeries_Update_Matches_Streaming()
|
||||
{
|
||||
var t3 = new T3(5, 0.7);
|
||||
var gbm = new GBM();
|
||||
var bars = gbm.Fetch(200, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
|
||||
var series = bars.Close;
|
||||
|
||||
var streamingResults = new List<double>();
|
||||
for (int i = 0; i < series.Count; i++)
|
||||
{
|
||||
streamingResults.Add(t3.Update(series[i]).Value);
|
||||
}
|
||||
|
||||
var t3_2 = new T3(5, 0.7);
|
||||
var seriesResults = t3_2.Update(series);
|
||||
|
||||
Assert.Equal(streamingResults.Count, seriesResults.Count);
|
||||
for (int i = 0; i < seriesResults.Count; i++)
|
||||
{
|
||||
Assert.Equal(streamingResults[i], seriesResults.Values[i], 1e-9);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BatchCalculate_Matches_Streaming()
|
||||
{
|
||||
var gbm = new GBM();
|
||||
var bars = gbm.Fetch(200, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
|
||||
var series = bars.Close;
|
||||
|
||||
var t3 = new T3(5, 0.7);
|
||||
var streamingResults = new List<double>();
|
||||
for (int i = 0; i < series.Count; i++)
|
||||
{
|
||||
streamingResults.Add(t3.Update(series[i]).Value);
|
||||
}
|
||||
|
||||
var batchResults = T3.Batch(series, 5, 0.7);
|
||||
|
||||
Assert.Equal(streamingResults.Count, batchResults.Count);
|
||||
for (int i = 0; i < batchResults.Count; i++)
|
||||
{
|
||||
Assert.Equal(streamingResults[i], batchResults.Values[i], 1e-9);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BatchCalculateSpan_Matches_Streaming()
|
||||
{
|
||||
var gbm = new GBM();
|
||||
var bars = gbm.Fetch(200, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
|
||||
var series = bars.Close;
|
||||
|
||||
var t3 = new T3(5, 0.7);
|
||||
var streamingResults = new List<double>();
|
||||
for (int i = 0; i < series.Count; i++)
|
||||
{
|
||||
streamingResults.Add(t3.Update(series[i]).Value);
|
||||
}
|
||||
|
||||
var spanResults = new double[series.Count];
|
||||
T3.Batch(series.Values, spanResults, 5, 0.7);
|
||||
|
||||
for (int i = 0; i < spanResults.Length; i++)
|
||||
{
|
||||
Assert.Equal(streamingResults[i], spanResults[i], 1e-9);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Chainability_Works()
|
||||
{
|
||||
var t3 = new T3(5, 0.7);
|
||||
var gbm = new GBM();
|
||||
var bars = gbm.Fetch(10, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
|
||||
var series = bars.Close;
|
||||
|
||||
// Test TSeries chain
|
||||
var result = t3.Update(series);
|
||||
Assert.NotNull(result);
|
||||
Assert.IsType<TSeries>(result);
|
||||
|
||||
// Test TValue chain
|
||||
var result2 = t3.Update(series[0]);
|
||||
Assert.IsType<TValue>(result2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_InvalidParameters_ThrowsArgumentException()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => new T3(0));
|
||||
Assert.Throws<ArgumentException>(() => new T3(-1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_InvalidVFactor_NaN_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new T3(5, double.NaN));
|
||||
Assert.Equal("vfactor", ex.ParamName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_InvalidVFactor_PositiveInfinity_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new T3(5, double.PositiveInfinity));
|
||||
Assert.Equal("vfactor", ex.ParamName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_InvalidVFactor_NegativeInfinity_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new T3(5, double.NegativeInfinity));
|
||||
Assert.Equal("vfactor", ex.ParamName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_InvalidVFactor_Zero_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new T3(5, 0.0));
|
||||
Assert.Equal("vfactor", ex.ParamName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_InvalidVFactor_Negative_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new T3(5, -0.5));
|
||||
Assert.Equal("vfactor", ex.ParamName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_InvalidVFactor_GreaterThanOne_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new T3(5, 1.5));
|
||||
Assert.Equal("vfactor", ex.ParamName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_ValidVFactor_EdgeCases_DoesNotThrow()
|
||||
{
|
||||
// Smallest valid value just above 0
|
||||
var t3_1 = new T3(5, 0.001);
|
||||
Assert.NotNull(t3_1);
|
||||
|
||||
// Valid value of 1.0 (edge case)
|
||||
var t3_2 = new T3(5, 1.0);
|
||||
Assert.NotNull(t3_2);
|
||||
|
||||
// Typical valid values
|
||||
var t3_3 = new T3(5, 0.5);
|
||||
Assert.NotNull(t3_3);
|
||||
|
||||
var t3_4 = new T3(5, 0.7);
|
||||
Assert.NotNull(t3_4);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BatchSpan_InvalidVFactor_NaN_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
var input = new double[10];
|
||||
var output = new double[10];
|
||||
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => T3.Batch(input, output, 5, double.NaN));
|
||||
Assert.Equal("vfactor", ex.ParamName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BatchSpan_InvalidVFactor_Infinity_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
var input = new double[10];
|
||||
var output = new double[10];
|
||||
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => T3.Batch(input, output, 5, double.PositiveInfinity));
|
||||
Assert.Equal("vfactor", ex.ParamName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BatchSpan_InvalidVFactor_OutOfRange_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
var input = new double[10];
|
||||
var output = new double[10];
|
||||
|
||||
var ex1 = Assert.Throws<ArgumentOutOfRangeException>(() => T3.Batch(input, output, 5, 0.0));
|
||||
Assert.Equal("vfactor", ex1.ParamName);
|
||||
|
||||
var ex2 = Assert.Throws<ArgumentOutOfRangeException>(() => T3.Batch(input, output, 5, -0.5));
|
||||
Assert.Equal("vfactor", ex2.ParamName);
|
||||
|
||||
var ex3 = Assert.Throws<ArgumentOutOfRangeException>(() => T3.Batch(input, output, 5, 1.5));
|
||||
Assert.Equal("vfactor", ex3.ParamName);
|
||||
}
|
||||
|
||||
private class TestPublisher : ITValuePublisher
|
||||
{
|
||||
public event TValuePublishedHandler? Pub;
|
||||
public int SubscriberCount => Pub?.GetInvocationList().Length ?? 0;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_SubscribesToSource()
|
||||
{
|
||||
var source = new TestPublisher();
|
||||
_ = new T3(source, 5);
|
||||
|
||||
Assert.Equal(1, source.SubscriberCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Dispose_UnsubscribesFromSource()
|
||||
{
|
||||
var source = new TestPublisher();
|
||||
var t3 = new T3(source, 5);
|
||||
|
||||
Assert.Equal(1, source.SubscriberCount);
|
||||
|
||||
t3.Dispose();
|
||||
|
||||
Assert.Equal(0, source.SubscriberCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Dispose_CanBeCalledMultipleTimes()
|
||||
{
|
||||
var source = new TestPublisher();
|
||||
var t3 = new T3(source, 5);
|
||||
|
||||
t3.Dispose();
|
||||
#pragma warning disable S3966 // Objects should not be disposed more than once
|
||||
t3.Dispose();
|
||||
#pragma warning restore S3966 // Objects should not be disposed more than once
|
||||
|
||||
Assert.Equal(0, source.SubscriberCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Dispose_DoesNothing_WhenNoSource()
|
||||
{
|
||||
var t3 = new T3(5);
|
||||
|
||||
var exception = Record.Exception(() => t3.Dispose());
|
||||
Assert.Null(exception);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
using OoplesFinance.StockIndicators;
|
||||
using OoplesFinance.StockIndicators.Models;
|
||||
using Skender.Stock.Indicators;
|
||||
using TALib;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace QuanTAlib.Tests;
|
||||
|
||||
public class T3ValidationTests
|
||||
{
|
||||
private readonly ValidationTestData _testData;
|
||||
private readonly ITestOutputHelper _output;
|
||||
|
||||
public T3ValidationTests(ITestOutputHelper output)
|
||||
{
|
||||
_output = output;
|
||||
_testData = new ValidationTestData();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_Skender_Batch()
|
||||
{
|
||||
int[] periods = { 5, 10, 20 };
|
||||
const double vFactor = 0.7;
|
||||
|
||||
foreach (var period in periods)
|
||||
{
|
||||
// Calculate QuanTAlib T3
|
||||
var t3 = new global::QuanTAlib.T3(period, vFactor);
|
||||
var qResult = t3.Update(_testData.Data);
|
||||
|
||||
// Calculate Skender T3
|
||||
var sResult = _testData.SkenderQuotes.GetT3(period, vFactor).ToList();
|
||||
|
||||
// Compare last 100 records
|
||||
ValidationHelper.VerifyData(qResult, sResult, x => x.T3);
|
||||
}
|
||||
_output.WriteLine("T3 Batch(TSeries) validated successfully against Skender");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_Talib_Batch()
|
||||
{
|
||||
int[] periods = { 5, 10, 20 };
|
||||
double vFactor = 0.7;
|
||||
|
||||
// Prepare data for TA-Lib
|
||||
double[] output = new double[_testData.RawData.Length];
|
||||
|
||||
foreach (var period in periods)
|
||||
{
|
||||
// Calculate QuanTAlib T3
|
||||
var t3 = new global::QuanTAlib.T3(period, vFactor);
|
||||
var qResult = t3.Update(_testData.Data);
|
||||
|
||||
// Calculate TA-Lib T3
|
||||
var retCode = TALib.Functions.T3<double>(_testData.RawData.Span, 0..^0, output, out var outRange, period, vFactor);
|
||||
Assert.Equal(TALib.Core.RetCode.Success, retCode);
|
||||
|
||||
int lookback = TALib.Functions.T3Lookback(period);
|
||||
|
||||
// Compare last 100 records
|
||||
ValidationHelper.VerifyData(qResult, output, outRange, lookback);
|
||||
}
|
||||
_output.WriteLine("T3 Batch(TSeries) validated successfully against TA-Lib");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_Talib_Streaming()
|
||||
{
|
||||
int[] periods = { 5, 10, 20 };
|
||||
double vFactor = 0.7;
|
||||
|
||||
// Prepare data for TA-Lib
|
||||
double[] output = new double[_testData.RawData.Length];
|
||||
|
||||
foreach (var period in periods)
|
||||
{
|
||||
// Calculate QuanTAlib T3 (streaming)
|
||||
var t3 = new global::QuanTAlib.T3(period, vFactor);
|
||||
var qResults = new List<double>();
|
||||
foreach (var item in _testData.Data)
|
||||
{
|
||||
qResults.Add(t3.Update(item).Value);
|
||||
}
|
||||
|
||||
// Calculate TA-Lib T3
|
||||
var retCode = TALib.Functions.T3<double>(_testData.RawData.Span, 0..^0, output, out var outRange, period, vFactor);
|
||||
Assert.Equal(TALib.Core.RetCode.Success, retCode);
|
||||
|
||||
int lookback = TALib.Functions.T3Lookback(period);
|
||||
|
||||
// Compare last 100 records
|
||||
ValidationHelper.VerifyData(qResults, output, outRange, lookback);
|
||||
}
|
||||
_output.WriteLine("T3 Streaming validated successfully against TA-Lib");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_Talib_Span()
|
||||
{
|
||||
int[] periods = { 5, 10, 20 };
|
||||
double vFactor = 0.7;
|
||||
|
||||
// Prepare data
|
||||
double[] talibOutput = new double[_testData.RawData.Length];
|
||||
|
||||
foreach (var period in periods)
|
||||
{
|
||||
// Calculate QuanTAlib T3 (Span API)
|
||||
double[] qOutput = new double[_testData.RawData.Length];
|
||||
global::QuanTAlib.T3.Batch(_testData.RawData.Span, qOutput.AsSpan(), period, vFactor);
|
||||
|
||||
// Calculate TA-Lib T3
|
||||
var retCode = TALib.Functions.T3<double>(_testData.RawData.Span, 0..^0, talibOutput, out var outRange, period, vFactor);
|
||||
Assert.Equal(TALib.Core.RetCode.Success, retCode);
|
||||
|
||||
int lookback = TALib.Functions.T3Lookback(period);
|
||||
|
||||
// Compare last 100 records
|
||||
ValidationHelper.VerifyData(qOutput, talibOutput, outRange, lookback);
|
||||
}
|
||||
_output.WriteLine("T3 Span validated successfully against TA-Lib");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_Against_Ooples()
|
||||
{
|
||||
int[] periods = { 5, 10, 20 };
|
||||
double vFactor = 0.7;
|
||||
|
||||
// Prepare data for Ooples (List<TickerData>)
|
||||
var ooplesData = _testData.SkenderQuotes.Select(q => new TickerData
|
||||
{
|
||||
Date = q.Date,
|
||||
Close = (double)q.Close,
|
||||
High = (double)q.High,
|
||||
Low = (double)q.Low,
|
||||
Open = (double)q.Open,
|
||||
Volume = (double)q.Volume
|
||||
}).ToList();
|
||||
|
||||
foreach (var period in periods)
|
||||
{
|
||||
// Calculate QuanTAlib T3
|
||||
var t3 = new global::QuanTAlib.T3(period, vFactor);
|
||||
var qResult = t3.Update(_testData.Data);
|
||||
|
||||
// Calculate Ooples T3
|
||||
var stockData = new StockData(ooplesData);
|
||||
var oResult = stockData.CalculateTillsonT3MovingAverage(length: period, vFactor: vFactor);
|
||||
var oValues = oResult.OutputValues["T3"];
|
||||
|
||||
// Compare
|
||||
ValidationHelper.VerifyData(qResult, oValues, (s) => s, tolerance: ValidationHelper.OoplesTolerance);
|
||||
}
|
||||
_output.WriteLine("T3 validated successfully against Ooples");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user