Files
QuanTAlib/docs/validation.md
T
Miha Kralj 92709ef2ed Add Stochastic Oscillator implementation and validation tests
- Implemented Stochastic Oscillator (%K and %D) in Stoch.cs with streaming and batch processing capabilities.
- Added validation tests for the Stochastic Oscillator in Stoch.Validation.Tests.cs, ensuring consistency with Skender.Stock.Indicators.
- Created documentation for the Stochastic Oscillator in Stoch.md, detailing its mathematical formula, architecture, parameters, and common pitfalls.
- Updated project file to include necessary numeric libraries for highest and lowest calculations.
2026-02-12 14:29:54 -08:00

28 KiB

Validation Across TA Libraries

"Trust, but verify." — Russian proverb (applicable to both Cold War diplomacy and technical indicator libraries)

Every indicator implementation makes implicit claims about correctness. QuanTAlib validates these claims by comparing outputs against established libraries: TA-Lib, Tulip, Skender.Stock.Indicators, and OoplesFinance. Where implementations diverge, the differences get documented.

Reading the Matrix

Symbol Meaning
✔️ Validated: outputs match within floating-point tolerance (1e-9)
⚠️ Partial match: minor discrepancies documented in indicator notes
Implementation exists but not validated
- No implementation in that library

Tolerance rationale: Financial data uses double precision. Differences below 1e-9 stem from floating-point arithmetic order, not algorithmic divergence.

Validation Philosophy

Three levels of confidence:

Level 1: Cross-Library Agreement Multiple independent implementations produce identical results. Highest confidence. Most mainstream indicators (SMA, EMA, RSI, MACD) fall here.

Level 2: Original Source Agreement No cross-library validation available, but implementation matches original research paper or patent description. JMA, various proprietary indicators fall here.

Level 3: Mathematical Correctness Only No external reference exists. Implementation verified through unit tests, edge case handling, and mathematical properties (e.g., filter stability, energy preservation). Novel or obscure indicators fall here.

Technical Indicators

Indicator QuanTAlib TA-Lib Tulip Skender Ooples
Aberration Bands Abber - - - -
Absolute Price Oscillator Apo ✔️ ✔️ - ✔️
Acceleration Bands AccBands - - - -
Acceleration Oscillator Ac - - -
Accumulation/Distribution Line Adl ✔️ ✔️ ✔️ ✔️
Accumulation/Distribution Oscillator Adosc ✔️ ✔️ ✔️ ✔️
Adaptive Price Zone Apz - - -
Andrews' Pitchfork Apchannel - - - -
Archer Moving Averages Trends Amat - - ✔️ ✔️
Archer On-Balance Volume Aobv - - - -
Arnaud Legoux Moving Average Alma - - ✔️ ✔️
Aroon Aroon ✔️ ✔️ ✔️ -
Aroon Oscillator AroonOsc ✔️ ✔️ ✔️ -
ATR Bands Atrbands - - -
Adaptive FIR Moving Average Afirma - - - -
Average Daily Range Adr - - - -
Average Directional Index Adx ✔️ ✔️ ✔️ ✔️
Average Directional Movement Rating Adxr ✔️ ✔️ - -
Average True Range Atr ✔️ ✔️ ✔️ ✔️
Average True Range Normalized [0,1] Atrn - - - -
Average True Range Percent Atrp ✔️ ✔️ ✔️ ✔️
Awesome Oscillator Ao - ✔️ ✔️ ✔️
Balance of Power Bop ✔️ ✔️ ✔️ ✔️
Bollinger Bands Bbands - ✔️ ✔️ ✔️
Bessel Filter Bessel - - - -
Bessel-Weighted MA Bwma - - - -
Beta Coefficient Beta ✔️ - ✔️ -
Bias Bias - - - -
Bilateral Filter Bilateral - - - -
Blackman Window MA Blma - - - -
Bollinger %B Bbb - - -
Bollinger Band Squeeze Bbs - - -
Bollinger Band Width Bbw - - -
Bollinger Band Width Normalized Bbwn - - - -
Bollinger Band Width Percentile Bbwp - - - -
Bollinger Bands Bbands ✔️ ✔️ ✔️
Butterworth Filter Butter - - - ✔️
Camarilla Pivot Points Pivotcam - - -
Chaikin Money Flow Cmf - - ✔️
Chaikin Volatility Cvi - ✔️ -
Chande Forecast Oscillator Cfo - ✔️ -
Chande Momentum Oscillator Cmo ✔️ ✔️ ✔️
Chebyshev Type I Filter Cheby1 - - - -
Chebyshev Type II Filter Cheby2 - - - -
Choppiness Index Chop - - ✔️
Close-to-Close Volatility Ccv - - - -
Cointegration Cointegration - - - -
Commodity Channel Index Cci ✔️ ✔️ ✔️
Composite Fractal Behavior Cfb - - - -
Conditional Volatility Cv - - - -
Convolution Moving Average Conv ✔️ ✔️ ✔️ ✔️
Correlation Correlation ✔️ - ✔️ -
Cumulative Moving Average Cma - - - -
Decay Min-Max Channel Decaychannel - - - -
DeMark Pivot Points Pivotdem - - -
Detrended Price Oscillator Dpo - ⚠️ -
Detrended Synthetic Price Dsp - - -
Deviation-Scaled MA Dsma - - -
Directional Movement Index Dx ✔️ ✔️ - -
Directional Movement Index (Jurik) Dmx - - - -
Dirty Data Detection Dirty - - - -
Donchian Channels Dchannel - - ✔️
Double Exponential Moving Average Dema ✔️ ✔️ ✔️ ✔️
Double Weighted Moving Average Dwma - - - -
Ease of Movement Eom - - - -
Ehlers Autocorrelation Periodogram Eacp - - - -
BandPass Filter Bpf ✔️ - - -
Ehlers Center of Gravity Cg - - -
Ehlers Even Better Sinewave Ebsw - - -
Ehlers Fractal Adaptive MA Frama - - -
Ehlers Highpass Filter Hpf - - -
Ehlers Phasor Analysis Phasor - - - -
Ehlers Sine Wave Sine - - -
Ehlers SSF-Based Detrended Synthetic Price Ssfdsp - - - -
Ehlers Super Smooth Filter Ssf - - - ✔️
Ehlers Ultrasmooth Filter Usf - - - -
Elliptic (Cauer) Filter Elliptic - - -
Exponential Moving Average Ema ✔️ ✔️ ✔️ ✔️
Exponential Transformation Exptrans - - - -
Exponential Weighted MA Volatility Ewma - - - -
Extended Traditional Pivots Pivotext - - - -
Fibonacci Pivot Points Pivotfib - - -
Fisher Transform Fisher - ✔️ ✔️
Force Index Efi - - - -
Fractal Chaos Bands Fcb - - ✔️
Garman-Klass Volatility Gkv - - - -
Gaussian Filter Gauss - - -
Gaussian-Weighted MA Gwma - - - -
Geometric Mean Geomean - - - -
Granger Causality Test Granger - - - -
Hamming Window MA Hamma - - -
Hann FIR Filter Hann - - - -
Hanning Window MA Hanma - - -
Harmonic Mean Harmean - - - -
High-Low Volatility (Parkinson) Hlv - - - -
Highest value Highest ✔️ ✔️ - -
Hilbert Transform Dominant Cycle Period HtDcPeriod ✔️ - - -
Hilbert Transform Dominant Cycle Phase HtDcPhase ✔️ - - -
Hilbert Transform Instantaneous Trend Htit ✔️ - ✔️ ✔️
Hilbert Transform Phasor HtPhasor ✔️ - - -
Hilbert Transform Sine Wave HtSine ✔️ - - -
Hilbert Transform Trend Mode Ht_trendmode ✔️ - - -
Historical Volatility (Close-to-Close) Hv - - - -
Hodrick-Prescott Filter Hp - - - -
Holt Weighted MA Hwma - - -
Homodyne Discriminator Dominant Cycle Homod - - -
Huber Loss Huber - - - -
Hull Exponential MA Hema - - - -
Hull Moving Average Hma - ✔️ ✔️ ⚠️
Hurst Exponent Hurst - - ✔️
Ichimoku Cloud Ichimoku - - ✔️
Inertia Inertia - - -
Interquartile Range Iqr - - - -
Intraday Intensity Index Iii - - - -
Intraday Momentum Index Imi - - -
Jarque-Bera Test Jb - - - -
Jurik Moving Average Jma - - -
Jurik Volatility Jvolty - - - -
Jurik Adaptive Envelope Bands Jbands - - - -
Jurik Volatility Normalized [0,100] Jvoltyn - - - -
Kalman Filter Kalman - - - -
Kaufman Adaptive Moving Average Kama ✔️ ✔️ ✔️ ✔️
KDJ Indicator Kdj - - - -
Keltner Channel Kchannel - - ✔️
Kendall Rank Correlation Kendall - - -
Klinger Volume Oscillator Kvo - ✔️ ✔️
Kurtosis Kurtosis - - -
Least Squares Moving Average Lsma ✔️ - ✔️
Linear Regression LinReg ✔️ ✔️ ✔️ ⚠️
Linear Transformation Lineartrans - - - -
Linear Trend MA Ltma - - - -
LOESS/LOWESS Smoothing Loess - - - -
Logarithmic Transformation Logtrans - - - -
Logistic Function Sigmoid - - - -
Lowest value Lowest ✔️ ✔️ - -
Lunar Phase Lunar - - - -
Lowest value Lowest ✔️ ✔️ - -
Lunar Phase Lunar - - - -
Mass Index Massi - ✔️ -
McGinley Dynamic Mgdi - - ✔️ ✔️
Mean Absolute Error Mae - - - -
Mean Absolute Percentage Difference Mapd - - - -
Mean Absolute Percentage Error Mape - - - -
Mean Absolute Scaled Error Mase - - - -
Mean Error Me - - - -
Mean Percentage Error Mpe - - - -
Mean Squared Error Mse - - - -
Mean Squared Logarithmic Error Msle - - - -
MESA Adaptive Moving Average Mama ✔️ - ✔️ ✔️
Midpoint Midpoint ✔️ - - -
Min-Max Channel Mmchannel ✔️ ✔️ ✔️ -
Min-Max Scaling (Normalization) Normalize - - - -
Mode (Most Frequent) Mode - - - -
Modified MA Mma - - - -
Momentum Mom ✔️ ✔️ -
Momentum change; 2nd derivative Accel - - - -
Money Flow Index Mfi ✔️ ✔️ ✔️
Moon Phase Moon - - - -
Moving Average Convergence/Divergence Macd ✔️ ✔️ ✔️
Moving Average Envelopes Maenv - - ✔️
Negative Volume Index Nvi - ✔️ - -
Normalized Average True Range Natr ✔️ ✔️ - -
Normalized Shannon Entropy Entropy - - - -
Notch Filter Notch - - - -
On Balance Volume Obv ⚠️ ✔️ ✔️ ⚠️
Parabolic SAR Psar ✔️ ✔️ ✔️
Pascal Weighted Moving Average Pwma - - - -
Percentage Change Change ✔️ - - -
Percentage Price Oscillator Ppo ✔️ ✔️ -
Percentage Volume Oscillator Pvo - - ✔️
Percentile Percentile - - - -
Pivot Points Pivot - - ✔️
Positive Volume Index Pvi - ✔️ - -
Pretty Good Oscillator Pgo - - -
Price Channel Pchannel - - - ✔️
Price Momentum Oscillator Pmo - - ✔️
Price Relative Strength Prs - - ✔️ -
Price Volume Divergence Pvd - - - -
Price Volume Rank Pvr - - - ✔️
Price Volume Trend Pvt - - ✔️ ✔️
Qstick Indicator Qstick - - -
Quad Exponential MA Qema - - - -
Quantile Quantile - - - -
Rate of acceleration; 3rd derivative Jerk - - - -
Rate of Change Roc ✔️ ✔️ ✔️
Rate of change; 1st derivative Slope ✔️ ✔️ ✔️
Rate of Change Percentage Rocp ✔️ - - -
Rate of Change Ratio Rocr ✔️ ✔️ - -
Realized Volatility Rv - - - -
Rectified Linear Unit Relu - - - -
Recursive Gaussian MA Rgma - - - -
Regression Channels Regchannel - - - -
Regularized Exponential MA Rema - - -
Relative Absolute Error Rae - - - -
Relative Squared Error Rse - - - -
Relative Strength Index Rsi ✔️ ✔️ ✔️ ✔️
Relative Strength Quality Index Rsx - - -
Relative Volatility Index Rvi - - -
Renko - - - ✔️ -
Rogers-Satchell Volatility Rsv - - - -
Root Mean Squared Error Rmse - - - -
Root Mean Squared Logarithmic Error Rmsle - - - -
R-Squared RSquared - - ✔️
Savitzky-Golay Filter Sgf - - - -
Savitzky-Golay MA Sgma - - - -
Schaff Trend Cycle Stc - - ✔️
Simple Moving Average Sma ✔️ ✔️ ✔️ ✔️
Sine-weighted MA Sinema - - - -
Smoothed Moving Average Rma - ✔️ ✔️ ✔️
Solar Activity Cycle Solar - - - -
Spearman Rank Correlation Spearman - - -
Square Root Transformation Sqrttrans - - - -
Standard Deviation Channel Sdchannel - - -
Standardization (Z-score) Standardize - - -
Starc Bands Starc - - - -
Stochastic Fast Stochf ✔️ - -
Stochastic Momentum Index Smi - - ✔️
Stochastic Oscillator Stoch - - ✔️ -
Stochastic RSI Stochrsi ✔️ ✔️ ✔️
Stoller Average Range Channel Starchannel - - -
Super Trend Bands Stbands - - - -
SuperTrend Super - - ✔️
Swing High/Low Detection Swings - - - -
Symmetric Mean Absolute Percentage Error Smape - - - -
T3 Moving Average T3 ✔️ - ✔️ ✔️
Theil Index Theil - - - -
Time Series Forecast Tsf ✔️ ✔️ -
Time Weighted Average Price Twap - - - -
Trade Volume Index Tvi - - -
Triangular Moving Average Trima ✔️ ✔️ ✔️
Triple Exponential Average Trix ✔️ ✔️ ✔️
Triple Exponential Moving Average Tema ✔️ ✔️ ✔️
True Range Tr ✔️ ✔️ ✔️ -
True Strength Index Tsi - - ✔️
TTM Trend Ttm - - - -
Two-Argument Arctangent Atan2 - - - -
Ulcer Index Ui - - ✔️
Ultimate Bands (Ehlers) Ubands - - - -
Ultimate Channel Uchannel - - - -
Ultimate Oscillator Ultosc ✔️ ✔️ ✔️ ✔️
Variable Index Dynamic Average Vidya - ✔️ -
Velocity (Jurik) Vel - - - -
Volatility Adjusted Moving Average Vama - - -
Volatility of Volatility Vov - - - -
Volatility Ratio Vr - - - -
Volume Accumulation Va - - -
Volume Force Vf - - - -
Volume Oscillator Vo - ✔️ - -
Volume Rate of Change Vroc - - - -
Volume Weighted Accumulation/Distribution Vwad - - - -
Volume Weighted Average Price Vwap - - ✔️ ✔️
Volume Weighted Moving Average Vwma - - ✔️ -
Vortex Indicator Vortex - - ✔️
VWAP Bands Vwapbands - - - -
VWAP with Standard Deviation Bands Vwapsd - - - -
Weighted Moving Average Wma ✔️ ✔️ ✔️ ✔️
Wiener Filter Wiener - - - -
Williams %R Willr ✔️ ✔️ ✔️
Williams Accumulation/Distribution Wad - - - ⚠️
Williams Alligator Alligator - - ✔️
Williams Fractal Fractals - - ✔️
Woodie's Pivot Points Pivotwood - - -
Yang-Zhang Volatility Yzv - - - -
Yang-Zhang Volatility Adjusted MA Yzvama - - - -
Zero-Lag Double Exponential MA Zldema - - - -
Zero-Lag Exponential Moving Average Zlema - ✔️ -
Zero-Lag Triple Exponential MA Zltema - - -
ZigZag - - - ✔️ -
Z-score standardization Zscore - - -
Z-Test Ztest - - - -

Statistical Indicators

Indicator QuanTAlib MathNet TA-Lib Tulip Skender
Autocorrelation Function Acf - - - -
Covariance Covariance - - - -
Median (Statistical) Median ✔️ - - -
Skewness Skew ✔️ - - -
Standard Deviation StdDev ✔️ ✔️ ✔️ ✔️
Sum (Rolling) Sum - ✔️ ✔️ -
Partial Autocorrelation Function Pacf - - - -
Variance Variance ✔️ ✔️ ✔️ ✔️

Error Metrics

Indicator QuanTAlib MathNet Notes
Mean Absolute Error Mae ✔️ Validated via Distance.MAE()
Mean Squared Error Mse ✔️ Validated via Distance.MSE()
Root Mean Squared Error Rmse ✔️ Validated via sqrt(Distance.MSE())
R-Squared Rsquared - Uses streaming-optimized TSS calculation
Huber Loss Huber - No external validation available
Pseudo-Huber Loss PseudoHuber - No external validation available
Log-Cosh Loss LogCosh - No external validation available
Tukey Loss Tukey - No external validation available
Quantile Loss Quantile - No external validation available
MAPE Mape - No external validation available
SMAPE Smape - No external validation available
MAAPE Maape - No external validation available
MASE Mase - No external validation available
MSLE Msle - No external validation available
RMSLE Rmsle - No external validation available
Theil U TheilU - No external validation available
Mean Error Me - No external validation available
MPE Mpe - No external validation available
RSE Rse - No external validation available
RAE Rae - No external validation available
MRAE Mrae - No external validation available
MdAE MdAE - No external validation available
MdAPE MdAPE - No external validation available
MAPD Mapd - No external validation available
WMAPE Wmape - No external validation available
WRMSE Wrmse - Validated via internal RMSE equivalence (uniform weights)

Validation Libraries

Library Language License Notes
TA-Lib C (via .NET wrapper) BSD Industry standard. C implementation, battle-tested.
Tulip C (via .NET wrapper) LGPL Lightweight, well-documented.
Skender.Stock.Indicators C# MIT Pure .NET. Active development.
OoplesFinance C# Apache 2.0 Large indicator collection. Validation coverage varies.
MathNet.Numerics C# MIT Statistical functions, not TA-specific.

Running Validation Tests

# All validation tests
dotnet test lib/QuanTAlib.Tests.csproj --filter "Category=Validation"

# Specific library comparison
dotnet test lib/QuanTAlib.Tests.csproj --filter "FullyQualifiedName~TalibValidation"
dotnet test lib/QuanTAlib.Tests.csproj --filter "FullyQualifiedName~SkenderValidation"

# Single indicator validation
dotnet test lib/QuanTAlib.Tests.csproj --filter "FullyQualifiedName~EmaValidation"

Discrepancy Investigation

When validation fails:

  1. Check parameter mapping. TA-Lib uses 0-based indexing for some parameters. Skender uses 1-based.
  2. Check warmup handling. Different libraries handle the first N values differently.
  3. Check smoothing assumptions. Some libraries use SMA for initial EMA seed. Others use the first value.
  4. Check edge cases. NaN handling, zero division, and boundary conditions vary.

Discrepancies get documented in the indicator's markdown file under a "Validation Notes" section. The goal is not to match every library exactly. The goal is to understand why differences exist and document them.

References