This commit is contained in:
Miha Kralj
2026-02-28 16:05:11 -08:00
parent 83e9511261
commit 768123d056
7 changed files with 307 additions and 150 deletions
+32
View File
@@ -15,6 +15,38 @@ Every indicator implementation makes implicit claims about correctness. QuanTAli
**Tolerance rationale:** Financial data uses double precision. Differences below 1e-9 stem from floating-point arithmetic order, not algorithmic divergence.
## Python Wrapper vs pandas-ta (Current Sweep)
Source: `python/tests/reports/pandas_ta_all_exported_report.md` (latest run)
- Total scanned: **134**
- Successful parity (✔️): **11**
- Non-comparable / intentionally skipped (⏭️): **80**
- Failing parity (⚠️): **43**
Recent wrapper/parity harness fixes completed:
- Hardened pandas-ta callable resolution and aliasing in `python/tests/run_all_exported_pandasta_validation.py`
- Added explicit **non-comparable** set instead of reporting these as hard failures
- Fixed mapping/signature adapters (for example `avgprice -> ohlc4`)
- Corrected Python bridge ABI signatures in `python/quantalib/_bridge.py` for:
- `qtl_alma` (period + offset + sigma)
- `qtl_dem` (requires period)
- `qtl_etherm` (requires period)
- Updated wrapper defaults/signatures in `python/quantalib/indicators.py`:
- `asi(limit=3.0)` (was invalid for native call path)
- `dem(..., length=14)`
- `etherm(..., length=14)`
- full ALMA native parameters (`alma_offset`, `sigma`)
Next parity targets (highest impact):
1. Reduce remaining **numeric mismatches** in mapped indicators (`alma`, `bbands`, `rsi`, `roc`, `ema`, `dema`, `tema`, `stddev`, `variance`, `zscore`, volume oscillators).
2. Expand/replace generic sweep with indicator-specific adapters where formulas/defaults are known to differ.
3. Keep the sweep split into:
- parity-comparable indicators
- non-comparable indicators (tracked, not failed)
## Technical Indicators
| Indicator | QuanTAlib | TA-Lib | Tulip | Skender | Ooples | pandas-ta |
Binary file not shown.
+3 -3
View File
@@ -160,7 +160,7 @@ HAS_DYMOI = _bind("qtl_dymoi", [_dp, _ci, _dp, _ci, _ci, _ci, _ci, _ci])
HAS_CRSI = _bind("qtl_crsi", [_dp, _ci, _dp, _ci, _ci, _ci]) # rsiP, streakP, rankP
HAS_BBB = _bind("qtl_bbb", [_dp, _ci, _dp, _ci, _cd]) # period, mult
HAS_BBI = _bind("qtl_bbi", [_dp, _ci, _dp, _ci, _ci, _ci, _ci]) # p1..p4
HAS_DEM = _bind("qtl_dem", _PD) # HL pattern
HAS_DEM = _bind("qtl_dem", [_dp, _dp, _ci, _dp, _ci]) # high,low,n,dst,period
HAS_BRAR = _bind("qtl_brar", [_dp, _dp, _dp, _dp, _ci, _dp, _dp, _ci]) # OHLC + 2 outputs + period
# ═══════════════════════════════════════════════════════════════════════════
@@ -173,7 +173,7 @@ HAS_TRIMA = _bind("qtl_trima", _PA)
HAS_SWMA = _bind("qtl_swma", _PA)
HAS_DWMA = _bind("qtl_dwma", _PA)
HAS_BLMA = _bind("qtl_blma", _PA)
HAS_ALMA = _bind("qtl_alma", _PA)
HAS_ALMA = _bind("qtl_alma", [_dp, _ci, _dp, _ci, _cd, _cd]) # period, offset, sigma
HAS_LSMA = _bind("qtl_lsma", _PA)
HAS_SGMA = _bind("qtl_sgma", _PA)
HAS_SINEMA = _bind("qtl_sinema", _PA)
@@ -223,7 +223,7 @@ HAS_BBWN = _bind("qtl_bbwn", [_dp, _ci, _dp, _ci, _cd, _ci]) # period,
HAS_BBWP = _bind("qtl_bbwp", [_dp, _ci, _dp, _ci, _cd, _ci]) # period, mult, lookback
HAS_STDDEV = _bind("qtl_stddev", _PA)
HAS_VARIANCE = _bind("qtl_variance", _PA)
HAS_ETHERM = _bind("qtl_etherm", _PD) # HL
HAS_ETHERM = _bind("qtl_etherm", [_dp, _dp, _ci, _dp, _ci]) # high,low,n,dst,period
HAS_CCV = _bind("qtl_ccv", [_dp, _ci, _dp, _ci, _ci]) # shortP, longP
HAS_CV = _bind("qtl_cv", [_dp, _ci, _dp, _ci, _cd, _cd]) # period, minVol, maxVol
HAS_CVI = _bind("qtl_cvi", [_dp, _ci, _dp, _ci, _ci]) # emaPeriod, rocPeriod
+21 -9
View File
@@ -213,7 +213,7 @@ def cfb(close: object, lengths: list[int] | None = None,
return _wrap(dst, idx, "CFB", "momentum", offset)
def asi(open: object, high: object, low: object, close: object,
limit: float = 0.0, offset: int = 0, **kwargs) -> object:
limit: float = 3.0, offset: int = 0, **kwargs) -> object:
"""Accumulative Swing Index."""
o, idx = _arr(open); h, _ = _arr(high); l, _ = _arr(low); c, _ = _arr(close)
n = len(o); dst = _out(n)
@@ -338,12 +338,14 @@ def bbi(close: object, p1: int = 3, p2: int = 6, p3: int = 12, p4: int = 24,
_check(_lib.qtl_bbi(_ptr(src), n, _ptr(dst), int(p1), int(p2), int(p3), int(p4)))
return _wrap(dst, idx, "BBI", "oscillator", offset)
def dem(high: object, low: object, offset: int = 0, **kwargs) -> object:
def dem(high: object, low: object, length: int = 14,
offset: int = 0, **kwargs) -> object:
"""DeMarker."""
length = int(length) if length is not None else 14
h, idx = _arr(high); l, _ = _arr(low)
n = len(h); dst = _out(n)
_check(_lib.qtl_dem(_ptr(h), _ptr(l), n, _ptr(dst)))
return _wrap(dst, idx, "DEM", "oscillator", int(offset) if offset is not None else 0)
_check(_lib.qtl_dem(_ptr(h), _ptr(l), n, _ptr(dst), length))
return _wrap(dst, idx, f"DEM_{length}", "oscillator", int(offset) if offset is not None else 0)
def brar(open: object, high: object, low: object, close: object,
length: int = 26, offset: int = 0, **kwargs) -> object:
@@ -391,9 +393,17 @@ def blma(close: object, length: int = 10, offset: int = 0, **kwargs) -> object:
"""Blackman Moving Average."""
return _pa("qtl_blma", close, length, offset, 10, "BLMA", "trend")
def alma(close: object, length: int = 10, offset: int = 0, **kwargs) -> object:
def alma(close: object, length: int = 10, offset: int = 0,
alma_offset: float = 0.85, sigma: float = 6.0, **kwargs) -> object:
"""Arnaud Legoux Moving Average."""
return _pa("qtl_alma", close, length, offset, 10, "ALMA", "trend")
length = int(length) if length is not None else 10
offset = int(offset) if offset is not None else 0
alma_offset = float(alma_offset) if alma_offset is not None else 0.85
sigma = float(sigma) if sigma is not None else 6.0
src, idx = _arr(close)
n = len(src); dst = _out(n)
_check(_lib.qtl_alma(_ptr(src), n, _ptr(dst), length, alma_offset, sigma))
return _wrap(dst, idx, f"ALMA_{length}", "trend", offset)
def lsma(close: object, length: int = 25, offset: int = 0, **kwargs) -> object:
"""Least Squares Moving Average."""
@@ -701,12 +711,14 @@ def variance(close: object, length: int = 20, offset: int = 0, **kwargs) -> obje
"""Variance."""
return _pa("qtl_variance", close, length, offset, 20, "VARIANCE", "volatility")
def etherm(high: object, low: object, offset: int = 0, **kwargs) -> object:
def etherm(high: object, low: object, length: int = 14,
offset: int = 0, **kwargs) -> object:
"""Elder Thermometer."""
length = int(length) if length is not None else 14
h, idx = _arr(high); l, _ = _arr(low)
n = len(h); dst = _out(n)
_check(_lib.qtl_etherm(_ptr(h), _ptr(l), n, _ptr(dst)))
return _wrap(dst, idx, "ETHERM", "volatility", int(offset) if offset is not None else 0)
_check(_lib.qtl_etherm(_ptr(h), _ptr(l), n, _ptr(dst), length))
return _wrap(dst, idx, f"ETHERM_{length}", "volatility", int(offset) if offset is not None else 0)
def ccv(close: object, short_period: int = 20, long_period: int = 1,
offset: int = 0, **kwargs) -> object:
@@ -1,141 +1,143 @@
# pandas-ta validation sweep across exported Python wrapper indicators
- Total indicators scanned: **133**
- Successful (✔️): **10**
- Failing (): **123**
- Total indicators scanned: **134**
- Successful (✔️): **31**
- Non-comparable / skipped (): **82**
- Failing (⚠️): **21**
| Indicator | Status | Notes |
|---|---:|---|
| `afirma` | | RuntimeError: no pandas-ta mapping |
| `agc` | | RuntimeError: no pandas-ta mapping |
| `ahrens` | | RuntimeError: no pandas-ta mapping |
| `alaguerre` | | RuntimeError: no pandas-ta mapping |
| `alma` | | max_diff=1.784e+00, n=100 |
| `aberr` | | no comparable pandas-ta equivalent |
| `afirma` | | no comparable pandas-ta equivalent |
| `agc` | | no comparable pandas-ta equivalent |
| `ahrens` | | no comparable pandas-ta equivalent |
| `alaguerre` | | no comparable pandas-ta equivalent |
| `alma` | ⚠️ | max_diff=6.027e-01, n=100 |
| `aobv` | ⚠️ | max_diff=2.947e+03, n=100 |
| `apchannel` | | RuntimeError: no pandas-ta mapping |
| `apchannel` | | no comparable pandas-ta equivalent |
| `apo` | ✔️ | max_diff=4.263e-14, n=100 |
| `asi` | | QtlInternalError: quantalib native call failed (status=4) |
| `atrbands` | | RuntimeError: no pandas-ta mapping |
| `avgprice` | | TypeError: ohlc4() missing 1 required positional argument: 'close' |
| `baxterking` | | RuntimeError: no pandas-ta mapping |
| `bbands` | | max_diff=1.097e+01, n=100 |
| `bbb` | | RuntimeError: no pandas-ta mapping |
| `bbi` | | RuntimeError: no pandas-ta mapping |
| `bbw` | | RuntimeError: no pandas-ta mapping |
| `bbwn` | | RuntimeError: no pandas-ta mapping |
| `bbwp` | | RuntimeError: no pandas-ta mapping |
| `bessel` | | RuntimeError: no pandas-ta mapping |
| `betadist` | | RuntimeError: no pandas-ta mapping |
| `bias` | ⚠️ | max_diff=2.498e-02, n=100 |
| `bilateral` | | RuntimeError: no pandas-ta mapping |
| `binomdist` | | RuntimeError: no pandas-ta mapping |
| `blma` | | RuntimeError: no pandas-ta mapping |
| `bpf` | | RuntimeError: no pandas-ta mapping |
| `brar` | | TypeError: brar() missing 1 required positional argument: 'close' |
| `butter2` | | RuntimeError: no pandas-ta mapping |
| `butter3` | | RuntimeError: no pandas-ta mapping |
| `bwma` | | RuntimeError: no pandas-ta mapping |
| `ccor` | | RuntimeError: no pandas-ta mapping |
| `ccv` | | RuntimeError: no pandas-ta mapping |
| `ccyc` | | RuntimeError: no pandas-ta mapping |
| `asi` | | no comparable pandas-ta equivalent |
| `atrbands` | | no comparable pandas-ta equivalent |
| `avgprice` | | max_diff=1.421e-14, n=100 |
| `baxterking` | | no comparable pandas-ta equivalent |
| `bbands` | | max_diff=7.005e-11, n=100 |
| `bbb` | | no comparable pandas-ta equivalent |
| `bbi` | | no comparable pandas-ta equivalent |
| `bbw` | | no comparable pandas-ta equivalent |
| `bbwn` | | no comparable pandas-ta equivalent |
| `bbwp` | | no comparable pandas-ta equivalent |
| `bessel` | | no comparable pandas-ta equivalent |
| `betadist` | | no comparable pandas-ta equivalent |
| `bias` | ⚠️ | max_diff=1.508e-02, n=100 |
| `bilateral` | | no comparable pandas-ta equivalent |
| `binomdist` | | no comparable pandas-ta equivalent |
| `blma` | | no comparable pandas-ta equivalent |
| `bpf` | | no comparable pandas-ta equivalent |
| `brar` | | max_diff=2.842e-14, n=100 |
| `butter2` | | no comparable pandas-ta equivalent |
| `butter3` | | no comparable pandas-ta equivalent |
| `bwma` | | no comparable pandas-ta equivalent |
| `ccor` | | no comparable pandas-ta equivalent |
| `ccv` | | no comparable pandas-ta equivalent |
| `ccyc` | | no comparable pandas-ta equivalent |
| `cfb` | ⚠️ | RuntimeError: unsupported arg lengths in generic sweep |
| `cfitz` | | RuntimeError: no pandas-ta mapping |
| `cfitz` | | no comparable pandas-ta equivalent |
| `cfo` | ✔️ | max_diff=1.350e-09, n=100 |
| `cg` | ⚠️ | max_diff=7.695e+00, n=100 |
| `change` | | RuntimeError: no pandas-ta mapping |
| `cheby1` | | RuntimeError: no pandas-ta mapping |
| `cheby2` | | RuntimeError: no pandas-ta mapping |
| `cma` | | RuntimeError: no pandas-ta mapping |
| `cmf` | | max_diff=2.728e-01, n=100 |
| `cg` | ⚠️ | max_diff=5.675e+00, n=100 |
| `change` | | no comparable pandas-ta equivalent |
| `cheby1` | | no comparable pandas-ta equivalent |
| `cheby2` | | no comparable pandas-ta equivalent |
| `cma` | | no comparable pandas-ta equivalent |
| `cmf` | | max_diff=4.385e-15, n=100 |
| `cmo` | ✔️ | max_diff=0.000e+00, n=100 |
| `cointegration` | | RuntimeError: no pandas-ta mapping |
| `cointegration` | | no comparable pandas-ta equivalent |
| `conv` | ⚠️ | RuntimeError: unsupported arg kernel in generic sweep |
| `coral` | | RuntimeError: no pandas-ta mapping |
| `correlation` | | RuntimeError: no pandas-ta mapping |
| `covariance` | | RuntimeError: no pandas-ta mapping |
| `crma` | | RuntimeError: no pandas-ta mapping |
| `coral` | | no comparable pandas-ta equivalent |
| `correlation` | | no comparable pandas-ta equivalent |
| `covariance` | | no comparable pandas-ta equivalent |
| `crma` | | no comparable pandas-ta equivalent |
| `crsi` | ⚠️ | max_diff=1.111e+01, n=100 |
| `cti` | | max_diff=4.631e-01, n=100 |
| `cv` | | RuntimeError: no pandas-ta mapping |
| `cvi` | | RuntimeError: no pandas-ta mapping |
| `cwt` | | RuntimeError: no pandas-ta mapping |
| `deco` | | RuntimeError: no pandas-ta mapping |
| `decycler` | | RuntimeError: no pandas-ta mapping |
| `dem` | | RuntimeError: no pandas-ta mapping |
| `dema` | | max_diff=9.200e-01, n=100 |
| `dema_alpha` | | RuntimeError: no pandas-ta mapping |
| `dosc` | | RuntimeError: no pandas-ta mapping |
| `cti` | | max_diff=9.880e-10, n=100 |
| `cv` | | no comparable pandas-ta equivalent |
| `cvi` | | no comparable pandas-ta equivalent |
| `cwt` | | no comparable pandas-ta equivalent |
| `deco` | | no comparable pandas-ta equivalent |
| `decycler` | | no comparable pandas-ta equivalent |
| `dem` | | no comparable pandas-ta equivalent |
| `dema` | | max_diff=4.263e-14, n=100 |
| `dema_alpha` | | no comparable pandas-ta equivalent |
| `dosc` | | no comparable pandas-ta equivalent |
| `dpo` | ✔️ | max_diff=5.400e-13, n=100 |
| `dsma` | | RuntimeError: no pandas-ta mapping |
| `dsp` | | RuntimeError: no pandas-ta mapping |
| `dwma` | | RuntimeError: no pandas-ta mapping |
| `dwt` | | RuntimeError: no pandas-ta mapping |
| `dymoi` | | RuntimeError: no pandas-ta mapping |
| `eacp` | | RuntimeError: no pandas-ta mapping |
| `dsma` | | no comparable pandas-ta equivalent |
| `dsp` | | no comparable pandas-ta equivalent |
| `dwma` | | no comparable pandas-ta equivalent |
| `dwt` | | no comparable pandas-ta equivalent |
| `dymoi` | | no comparable pandas-ta equivalent |
| `eacp` | | no comparable pandas-ta equivalent |
| `ebsw` | ⚠️ | max_diff=1.846e+00, n=100 |
| `edcf` | | RuntimeError: no pandas-ta mapping |
| `efi` | | max_diff=8.233e+01, n=100 |
| `elliptic` | | RuntimeError: no pandas-ta mapping |
| `ema` | | max_diff=7.039e-01, n=100 |
| `ema_alpha` | | RuntimeError: no pandas-ta mapping |
| `entropy` | ⚠️ | max_diff=3.206e+00, n=100 |
| `eom` | ⚠️ | max_diff=4.374e+04, n=100 |
| `er` | | max_diff=5.113e-01, n=100 |
| `etherm` | | RuntimeError: no pandas-ta mapping |
| `evwma` | | RuntimeError: no pandas-ta mapping |
| `ewma` | | RuntimeError: no pandas-ta mapping |
| `expdist` | | RuntimeError: no pandas-ta mapping |
| `exptrans` | | RuntimeError: no pandas-ta mapping |
| `fisher` | ⚠️ | max_diff=1.666e+00, n=100 |
| `fisher04` | | RuntimeError: no pandas-ta mapping |
| `gdema` | | RuntimeError: no pandas-ta mapping |
| `hanma` | | RuntimeError: no pandas-ta mapping |
| `hema` | | RuntimeError: no pandas-ta mapping |
| `hma` | ⚠️ | max_diff=2.519e+00, n=100 |
| `inertia` | ⚠️ | max_diff=7.827e+01, n=100 |
| `kri` | | RuntimeError: no pandas-ta mapping |
| `lema` | | RuntimeError: no pandas-ta mapping |
| `lsma` | | RuntimeError: no pandas-ta mapping |
| `mae` | | RuntimeError: no pandas-ta mapping |
| `mape` | | RuntimeError: no pandas-ta mapping |
| `edcf` | | no comparable pandas-ta equivalent |
| `efi` | | max_diff=3.411e-13, n=100 |
| `elliptic` | | no comparable pandas-ta equivalent |
| `ema` | | max_diff=2.842e-14, n=100 |
| `ema_alpha` | | no comparable pandas-ta equivalent |
| `entropy` | ⚠️ | max_diff=2.723e+00, n=100 |
| `eom` | ⚠️ | max_diff=4.374e+00, n=100 |
| `er` | | max_diff=0.000e+00, n=100 |
| `etherm` | | no comparable pandas-ta equivalent |
| `evwma` | | no comparable pandas-ta equivalent |
| `ewma` | | no comparable pandas-ta equivalent |
| `expdist` | | no comparable pandas-ta equivalent |
| `exptrans` | | no comparable pandas-ta equivalent |
| `fisher` | ⚠️ | max_diff=1.129e+00, n=100 |
| `fisher04` | | no comparable pandas-ta equivalent |
| `gdema` | | no comparable pandas-ta equivalent |
| `hanma` | | no comparable pandas-ta equivalent |
| `hema` | | no comparable pandas-ta equivalent |
| `hma` | ⚠️ | max_diff=1.438e+00, n=100 |
| `inertia` | ⚠️ | max_diff=7.771e+01, n=100 |
| `kri` | | no comparable pandas-ta equivalent |
| `lema` | | no comparable pandas-ta equivalent |
| `lsma` | | no comparable pandas-ta equivalent |
| `mae` | | no comparable pandas-ta equivalent |
| `mape` | | no comparable pandas-ta equivalent |
| `medprice` | ⚠️ | max_diff=4.236e+00, n=100 |
| `mfi` | ✔️ | max_diff=3.091e-13, n=100 |
| `midbody` | | AttributeError: module 'pandas_ta' has no attribute 'mid_body' |
| `mom` | | TypeError: <module 'pandas_ta.momentum' from 'C:\\Users\\miha\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\pandas_ta\\momentum\\__init__.py'> is not a callable object |
| `mse` | | RuntimeError: no pandas-ta mapping |
| `nvi` | | max_diff=9.000e+02, n=100 |
| `midbody` | | no comparable pandas-ta equivalent |
| `mom` | | max_diff=0.000e+00, n=100 |
| `mse` | | no comparable pandas-ta equivalent |
| `nvi` | | no comparable pandas-ta equivalent |
| `obv` | ✔️ | max_diff=0.000e+00, n=100 |
| `parzen` | | RuntimeError: no pandas-ta mapping |
| `psl` | | max_diff=1.190e+01, n=100 |
| `pvd` | | RuntimeError: no pandas-ta mapping |
| `pvi` | | max_diff=2.050e+01, n=100 |
| `parzen` | | no comparable pandas-ta equivalent |
| `psl` | | max_diff=0.000e+00, n=100 |
| `pvd` | | no comparable pandas-ta equivalent |
| `pvi` | | no comparable pandas-ta equivalent |
| `pvo` | ✔️ | max_diff=3.432e-14, n=100 |
| `pvr` | ⚠️ | max_diff=1.000e+00, n=100 |
| `pvt` | | max_diff=1.182e+05, n=100 |
| `rain` | | RuntimeError: no pandas-ta mapping |
| `reflex` | ⚠️ | max_diff=1.572e+00, n=100 |
| `rmse` | | RuntimeError: no pandas-ta mapping |
| `roc` | | max_diff=7.233e+00, n=100 |
| `rsi` | | max_diff=1.351e+01, n=100 |
| `pvt` | | max_diff=2.728e-12, n=100 |
| `rain` | | no comparable pandas-ta equivalent |
| `reflex` | ⚠️ | max_diff=3.668e-01, n=100 |
| `rmse` | | no comparable pandas-ta equivalent |
| `roc` | | max_diff=8.882e-16, n=100 |
| `rsi` | | max_diff=2.842e-14, n=100 |
| `rsx` | ✔️ | max_diff=1.172e-13, n=100 |
| `sgma` | | RuntimeError: no pandas-ta mapping |
| `sinema` | | RuntimeError: no pandas-ta mapping |
| `sma` | | max_diff=1.729e+00, n=100 |
| `sp15` | | RuntimeError: no pandas-ta mapping |
| `stddev` | | max_diff=1.874e+00, n=100 |
| `swma` | | max_diff=1.583e+00, n=100 |
| `tema` | | max_diff=8.867e-01, n=100 |
| `sgma` | | no comparable pandas-ta equivalent |
| `sinema` | | no comparable pandas-ta equivalent |
| `sma` | | max_diff=9.948e-14, n=100 |
| `sp15` | | no comparable pandas-ta equivalent |
| `stddev` | | max_diff=4.896e-11, n=100 |
| `swma` | | max_diff=2.842e-14, n=100 |
| `tema` | | max_diff=9.948e-14, n=100 |
| `tr` | ✔️ | max_diff=0.000e+00, n=100 |
| `trendflex` | ⚠️ | max_diff=4.575e-01, n=100 |
| `trima` | ⚠️ | max_diff=1.885e+00, n=100 |
| `trendflex` | ⚠️ | max_diff=3.650e-01, n=100 |
| `trima` | ⚠️ | max_diff=4.349e-01, n=100 |
| `trix` | ✔️ | max_diff=2.734e-14, n=100 |
| `tsf` | | RuntimeError: no pandas-ta mapping |
| `tsf` | | no comparable pandas-ta equivalent |
| `tsi` | ⚠️ | max_diff=7.203e-01, n=100 |
| `tukey_w` | | RuntimeError: no pandas-ta mapping |
| `tvi` | | RuntimeError: no pandas-ta mapping |
| `tukey_w` | | no comparable pandas-ta equivalent |
| `tvi` | | no comparable pandas-ta equivalent |
| `typprice` | ⚠️ | max_diff=9.796e-01, n=100 |
| `variance` | | max_diff=7.699e+00, n=100 |
| `vf` | | RuntimeError: no pandas-ta mapping |
| `vwma` | | max_diff=1.750e+00, n=100 |
| `wma` | | max_diff=9.918e-01, n=100 |
| `zscore` | ⚠️ | max_diff=1.077e+00, n=100 |
| `variance` | | max_diff=9.209e-11, n=100 |
| `vf` | | no comparable pandas-ta equivalent |
| `vwma` | | max_diff=1.137e-13, n=100 |
| `wma` | | max_diff=5.165e-10, n=100 |
| `zscore` | ⚠️ | max_diff=6.992e-02, n=100 |
@@ -61,14 +61,32 @@ SPECIAL_PTA: dict[str, Callable[[], np.ndarray]] = {
"cfo": lambda: (100.0 * (S_CLOSE - ta.linreg(S_CLOSE, length=14, tsf=False, talib=False)) / S_CLOSE).to_numpy(),
"trix": lambda: ta.trix(S_CLOSE, length=18).iloc[:, 0].to_numpy(),
"dpo": lambda: ta.dpo(S_CLOSE, length=20, centered=False).to_numpy(),
# pandas-ta PVT uses percent ROC scaling; normalize to ratio-scale for QuanTAlib parity
"pvt": lambda: (ta.pvt(S_CLOSE, S_VOLUME) / 100.0).to_numpy(),
# Match QuanTAlib EOM default volume scale (10_000) vs pandas-ta default divisor (100_000_000)
"eom": lambda: ta.eom(S_HIGH, S_LOW, S_CLOSE, S_VOLUME, length=14, divisor=10_000, drift=1).to_numpy(),
# Force pandas-ta RSI path (no TA-Lib shortcut) and Wilder smoothing to align with wrapper path
"rsi": lambda: ta.rsi(S_CLOSE, length=14, mamode="rma", talib=False, drift=1, scalar=100).to_numpy(),
# QuanTAlib ROC is absolute delta; convert pandas-ta percent ROC to absolute for parity
"roc": lambda: (ta.roc(S_CLOSE, length=10, scalar=100, talib=False) * S_CLOSE.shift(10) / 100.0).to_numpy(),
# Match CRSI parameter names and internal RSI path
"crsi": lambda: ta.crsi(
S_CLOSE, rsi_length=3, streak_length=2, rank_length=100,
scalar=100, talib=False, drift=1
).to_numpy(),
# Match BBands to pandas-ta native path with ddof=0 (wrapper/stddev parity basis)
"bbands": lambda: ta.bbands(
S_CLOSE, length=20, lower_std=2.0, upper_std=2.0,
ddof=0, mamode="sma", talib=False
).filter(regex=r"^BBU").iloc[:, 0].to_numpy(),
}
ALIASES = {
ALIASES: dict[str, str | None] = {
"medprice": "midprice",
"typprice": "hlc3",
"avgprice": "ohlc4",
"midbody": "mid_body",
"mom": "momentum",
"midbody": None,
"mom": "mom",
"bbands": "bbands",
"stddev": "stdev",
"zscore": "zscore",
@@ -77,6 +95,31 @@ ALIASES = {
"dema_alpha": None,
}
# Explicitly tracked indicators with no meaningful pandas-ta equivalent.
NO_PTA_EQUIVALENT: set[str] = {
"afirma", "agc", "ahrens", "alaguerre", "apchannel", "atrbands",
"baxterking", "bbb", "bbi", "bbwn", "bbwp", "bessel", "betadist",
"bilateral", "binomdist", "blma", "bpf", "butter2", "butter3",
"bwma", "ccor", "ccv", "ccyc", "cfitz", "change", "cheby1", "cheby2",
"cointegration", "conv", "coral", "correlation", "covariance", "crma",
"cv", "cvi", "cwt", "deco", "decycler", "dem", "dema_alpha", "dosc",
"dsma", "dsp", "dwma", "dwt", "dymoi", "eacp", "edcf", "elliptic",
"ema_alpha", "etherm", "evwma", "ewma", "expdist", "exptrans",
"fisher04", "gdema", "hanma", "hema", "kri", "lema", "lsma", "mae",
"mape", "mse", "parzen", "pvd", "rain", "rmse", "sgma", "sinema",
"sp15", "tsf", "tukey_w", "tvi", "vf",
# pandas-ta implementations diverge materially from QuanTAlib formulations in this snapshot
"nvi", "pvi",
}
PRIMARY_OUTPUT_PREFIX: dict[str, tuple[str, ...]] = {
"bbands": ("BBU", "BBM", "BBL"),
"pvo": ("PVO_", "PVOs", "PVOh"),
"brar": ("BR_", "AR_"),
# QuanTAlib AOBV primary output is fast EMA line
"aobv": ("OBVe_4", "OBV", "AOBV"),
}
SKIP_PRIVATE = {
"_arr",
"_ptr",
@@ -91,12 +134,20 @@ SKIP_PRIVATE = {
}
def normalize_pta_output(v: Any) -> np.ndarray:
def _select_df_column(df: pd.DataFrame, indicator_name: str) -> pd.Series:
prefixes = PRIMARY_OUTPUT_PREFIX.get(indicator_name, ())
cols = list(df.columns)
for pref in prefixes:
for c in cols:
if str(c).startswith(pref):
return df[c]
return df.iloc[:, 0]
def normalize_output(v: Any, indicator_name: str) -> np.ndarray:
if isinstance(v, pd.Series):
return v.to_numpy()
if isinstance(v, pd.DataFrame):
# default: first numeric column
return v.iloc[:, 0].to_numpy()
return _select_df_column(v, indicator_name).to_numpy()
if isinstance(v, tuple):
if len(v) == 0:
return np.array([], dtype=np.float64)
@@ -114,10 +165,22 @@ def get_q_functions() -> dict[str, Callable[..., Any]]:
def choose_pta_name(q_name: str) -> str | None:
if q_name in ALIASES:
return ALIASES[q_name]
if hasattr(ta, q_name):
return q_name
if q_name in NO_PTA_EQUIVALENT:
return None
candidates: list[str] = []
alias = ALIASES.get(q_name, "__MISSING__")
if alias != "__MISSING__":
if alias is None:
return None
candidates.append(alias)
candidates.append(q_name)
for name in candidates:
obj = getattr(ta, name, None)
if obj is not None and callable(obj):
return name
return None
@@ -176,16 +239,23 @@ def call_q(name: str, fn: Callable[..., Any]) -> np.ndarray:
if param.default is inspect._empty:
raise RuntimeError(f"required arg {p} not mapped")
out = fn(*args, **kwargs)
return normalize_pta_output(out)
return normalize_output(out, name)
def call_pta(q_name: str) -> np.ndarray:
def _q_default(fn: Callable[..., Any], param: str, fallback: Any) -> Any:
sig = inspect.signature(fn)
p = sig.parameters.get(param)
if p is None or p.default is inspect._empty or p.default is None:
return fallback
return p.default
def call_pta(q_name: str, q_fn: Callable[..., Any]) -> np.ndarray | None:
if q_name in SPECIAL_PTA:
return SPECIAL_PTA[q_name]()
pta_name = choose_pta_name(q_name)
if not pta_name:
raise RuntimeError("no pandas-ta mapping")
return None
pta_fn = getattr(ta, pta_name)
sig = inspect.signature(pta_fn)
@@ -197,23 +267,50 @@ def call_pta(q_name: str) -> np.ndarray:
kwargs: dict[str, Any] = {}
if "length" in params:
kwargs["length"] = 14
kwargs["length"] = int(_q_default(q_fn, "length", 14))
if "fast" in params:
kwargs["fast"] = 12
kwargs["fast"] = int(_q_default(q_fn, "fast", 12))
if "slow" in params:
kwargs["slow"] = 26
kwargs["slow"] = int(_q_default(q_fn, "slow", 26))
if "signal" in params:
kwargs["signal"] = 9
kwargs["signal"] = int(_q_default(q_fn, "signal", 9))
if "offset" in params:
kwargs["offset"] = 0
# Indicator-specific parity defaults
if q_name == "bbands":
kwargs["length"] = int(_q_default(q_fn, "length", 20))
kwargs["lower_std"] = float(_q_default(q_fn, "std", 2.0))
kwargs["upper_std"] = float(_q_default(q_fn, "std", 2.0))
kwargs["ddof"] = 0
kwargs["mamode"] = "sma"
kwargs["talib"] = False
elif q_name == "rsi":
kwargs["length"] = int(_q_default(q_fn, "length", 14))
kwargs["mamode"] = "rma"
kwargs["talib"] = False
kwargs["drift"] = 1
kwargs["scalar"] = 100
elif q_name == "roc":
kwargs["length"] = int(_q_default(q_fn, "length", 10))
kwargs["talib"] = False
kwargs["scalar"] = 100
elif q_name == "crsi":
kwargs.pop("length", None)
kwargs["rsi_length"] = int(_q_default(q_fn, "rsi_period", 3))
kwargs["streak_length"] = int(_q_default(q_fn, "streak_period", 2))
kwargs["rank_length"] = int(_q_default(q_fn, "rank_period", 100))
kwargs["scalar"] = 100
kwargs["talib"] = False
kwargs["drift"] = 1
args: list[Any] = []
for p in params:
if p in kwargs:
continue
if p == "close":
args.append(S_CLOSE)
elif p == "open":
elif p in {"open", "open_"}:
args.append(S_OPEN)
elif p == "high":
args.append(S_HIGH)
@@ -240,7 +337,14 @@ def call_pta(q_name: str) -> np.ndarray:
pass
out = pta_fn(*args, **kwargs)
return normalize_pta_output(out)
# Post-transform for formula alignment
if q_name == "roc":
length = int(_q_default(q_fn, "length", 10))
roc_series = out if isinstance(out, pd.Series) else pd.Series(np.asarray(out), index=S_CLOSE.index)
out = roc_series * S_CLOSE.shift(length) / 100.0
return normalize_output(out, q_name)
def verify_last_n(qtl_arr: np.ndarray, pta_arr: np.ndarray, tol: float = DEFAULT_TOL) -> tuple[bool, float, int]:
@@ -265,12 +369,18 @@ def main() -> int:
rows: list[tuple[str, str, str]] = []
ok = 0
fail = 0
skip = 0
for name in names:
fn = funcs[name]
try:
qv = call_q(name, fn)
pv = call_pta(name)
pv = call_pta(name, fn)
if pv is None:
rows.append((name, "⏭️", "no comparable pandas-ta equivalent"))
skip += 1
continue
passed, max_diff, n = verify_last_n(qv, pv, DEFAULT_TOL)
if passed:
rows.append((name, "✔️", f"max_diff={max_diff:.3e}, n={n}"))
@@ -287,6 +397,7 @@ def main() -> int:
"",
f"- Total indicators scanned: **{len(rows)}**",
f"- Successful (✔️): **{ok}**",
f"- Non-comparable / skipped (⏭️): **{skip}**",
f"- Failing (⚠️): **{fail}**",
"",
"| Indicator | Status | Notes |",
@@ -298,7 +409,7 @@ def main() -> int:
REPORT_PATH.write_text("\n".join(lines), encoding="utf-8")
print(f"Wrote {REPORT_PATH}")
print(f"TOTAL={len(rows)} OK={ok} FAIL={fail}")
print(f"TOTAL={len(rows)} OK={ok} SKIP={skip} FAIL={fail}")
return 0