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:
Miha Kralj
2026-02-11 14:46:56 -08:00
parent 6d6259a47d
commit 75c6a9f135
51 changed files with 7893 additions and 1274 deletions
@@ -1,3 +1,4 @@
using Skender.Stock.Indicators;
using Xunit.Abstractions;
namespace QuanTAlib.Tests;
@@ -512,4 +513,66 @@ public sealed class MaenvValidationTests : IDisposable
_output.WriteLine("Maenv SMA ring buffer O(1) validated");
}
[Fact]
public void Validate_Skender_SMA_Centerline()
{
// Skender GetMaEnvelopes(lookbackPeriods, percentOffset, MaType.SMA)
// QuanTAlib Maenv(period, percentage, MaenvType.SMA)
// Both compute: Middle = SMA(Close), Upper = Middle + Middle*pct/100, Lower = Middle - Middle*pct/100
// For SMA type, results should match exactly.
int[] periods = { 5, 10, 20, 50 };
double percentage = 2.5;
foreach (var period in periods)
{
var (qMiddle, _, _) = Maenv.Batch(_testData.Data, period, percentage, MaenvType.SMA);
var sResult = _testData.SkenderQuotes
.GetMaEnvelopes(period, percentage, MaType.SMA)
.ToList();
ValidationHelper.VerifyData(qMiddle, sResult, s => s.Centerline);
}
_output.WriteLine("Maenv SMA centerline validated against Skender for all periods");
}
[Fact]
public void Validate_Skender_SMA_UpperEnvelope()
{
int[] periods = { 5, 10, 20, 50 };
double percentage = 2.5;
foreach (var period in periods)
{
var (_, qUpper, _) = Maenv.Batch(_testData.Data, period, percentage, MaenvType.SMA);
var sResult = _testData.SkenderQuotes
.GetMaEnvelopes(period, percentage, MaType.SMA)
.ToList();
ValidationHelper.VerifyData(qUpper, sResult, s => s.UpperEnvelope);
}
_output.WriteLine("Maenv SMA upper envelope validated against Skender for all periods");
}
[Fact]
public void Validate_Skender_SMA_LowerEnvelope()
{
int[] periods = { 5, 10, 20, 50 };
double percentage = 2.5;
foreach (var period in periods)
{
var (_, _, qLower) = Maenv.Batch(_testData.Data, period, percentage, MaenvType.SMA);
var sResult = _testData.SkenderQuotes
.GetMaEnvelopes(period, percentage, MaType.SMA)
.ToList();
ValidationHelper.VerifyData(qLower, sResult, s => s.LowerEnvelope);
}
_output.WriteLine("Maenv SMA lower envelope validated against Skender for all periods");
}
}