mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-18 18:48:05 +00:00
Enhance validation tests for various indicators with external library comparisons
- Added detailed comments explaining the validation limitations for MMA and ZLEMA due to differences in algorithm implementations. - Implemented validation tests for True Range against TALib and Tulip, ensuring directional agreement. - Updated Ulcer Index validation to clarify differences in algorithmic approaches between QuanTAlib and Skender. - Enhanced Ease of Movement tests to verify directional agreement with Tulip's EMV, noting differences in volume scaling. - Expanded Klinger Volume Oscillator tests to validate against Skender and Tulip, focusing on directional agreement across multiple period configurations. - Improved Negative Volume Index tests to compare percentage changes with Tulip, addressing differences in starting values. - Updated Positive Volume Index tests to validate against Tulip, emphasizing percentage change comparisons. - Enhanced Williams Accumulation/Distribution tests to verify directional agreement with Tulip, highlighting formula differences.
This commit is contained in:
@@ -1,13 +1,87 @@
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace QuanTAlib.Tests;
|
||||
|
||||
public class EomValidationTests
|
||||
/// <summary>
|
||||
/// Ease of Movement validation tests.
|
||||
/// Tulip has emv (Ease of Movement Value) but outputs raw unsmoothed values
|
||||
/// without volume scaling, while QuanTAlib applies SMA(period) smoothing with
|
||||
/// configurable volumeScale (default 10000). Direct comparison not possible.
|
||||
/// Skender, TA-Lib, and Ooples do not have EOM implementations.
|
||||
/// </summary>
|
||||
public sealed class EomValidationTests : IDisposable
|
||||
{
|
||||
private readonly ValidationTestData _data;
|
||||
private readonly ITestOutputHelper _output;
|
||||
private const int DefaultPeriod = 14;
|
||||
|
||||
public EomValidationTests()
|
||||
public EomValidationTests(ITestOutputHelper output)
|
||||
{
|
||||
_data = new ValidationTestData();
|
||||
_output = output;
|
||||
}
|
||||
|
||||
public void Dispose() { /* nothing to dispose */ }
|
||||
|
||||
[Fact]
|
||||
public void Eom_Matches_Tulip_Directional_Agreement()
|
||||
{
|
||||
// Tulip emv: inputs={high, low, volume}, options={}, outputs={emv}
|
||||
// Tulip computes raw EMV without SMA smoothing or volumeScale division.
|
||||
// QuanTAlib EOM = SMA(raw_eom / volumeScale, period).
|
||||
// We can only verify directional agreement (sign correlation) after warmup.
|
||||
var high = _data.Bars.High.Values.ToArray();
|
||||
var low = _data.Bars.Low.Values.ToArray();
|
||||
var volume = _data.Bars.Volume.Values.ToArray();
|
||||
|
||||
var tulipIndicator = Tulip.Indicators.emv;
|
||||
double[][] inputs = { high, low, volume };
|
||||
double[] options = Array.Empty<double>();
|
||||
double[][] outputs = { new double[high.Length] };
|
||||
|
||||
tulipIndicator.Run(inputs, options, outputs);
|
||||
double[] tResult = outputs[0];
|
||||
int lookback = tulipIndicator.Start(options);
|
||||
|
||||
// QuanTAlib EOM with period=1 (no smoothing) for directional comparison
|
||||
var eom = new Eom(1);
|
||||
var qValues = new double[_data.Bars.Count];
|
||||
int idx = 0;
|
||||
foreach (var bar in _data.Bars)
|
||||
{
|
||||
qValues[idx++] = eom.Update(bar).Value;
|
||||
}
|
||||
|
||||
_output.WriteLine($"Tulip EMV lookback: {lookback}, output length: {tResult.Length}");
|
||||
|
||||
// Verify directional agreement (both positive or both negative) in most bars
|
||||
int agreementCount = 0;
|
||||
int totalCompared = 0;
|
||||
int startIdx = lookback + 5;
|
||||
for (int i = startIdx; i < qValues.Length && (i - lookback) < tResult.Length; i++)
|
||||
{
|
||||
double qValue = qValues[i];
|
||||
double tValue = tResult[i - lookback];
|
||||
|
||||
// Skip near-zero values where sign is meaningless
|
||||
if (Math.Abs(qValue) < 1e-10 || Math.Abs(tValue) < 1e-10)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
totalCompared++;
|
||||
if (Math.Sign(qValue) == Math.Sign(tValue))
|
||||
{
|
||||
agreementCount++;
|
||||
}
|
||||
}
|
||||
|
||||
double agreementRate = totalCompared > 0 ? (double)agreementCount / totalCompared : 0;
|
||||
_output.WriteLine($"Tulip EMV directional agreement: {agreementCount}/{totalCompared} ({agreementRate:P1})");
|
||||
|
||||
// With period=1, directional agreement should be high (>80%)
|
||||
Assert.True(agreementRate > 0.80,
|
||||
$"EOM directional agreement with Tulip EMV should be >80%, got {agreementRate:P1}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -24,21 +98,6 @@ public class EomValidationTests
|
||||
Assert.True(true, "TA-Lib does not have an Ease of Movement implementation");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Eom_Matches_Tulip()
|
||||
{
|
||||
// Tulip has emv (Ease of Movement Value)
|
||||
// However, the implementation differs - Tulip uses a different formula
|
||||
Assert.True(true, "Tulip implementation differs from standard EOM");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Eom_Matches_Ooples()
|
||||
{
|
||||
// Ooples does not have a standard EOM implementation
|
||||
Assert.True(true, "Ooples does not have a standard Ease of Movement implementation");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Eom_Streaming_Matches_Batch()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user