quantwave icon indicating copy to clipboard operation
quantwave copied to clipboard

Python docs gaps: ATR is EMA-smoothed (not Wilder), beta argument order, empty docstrings, noisy import without polars

Open lavs9 opened this issue 3 weeks ago • 1 comments

Found while moving the trade_backtest 9-EMA Bounce backtest onto quantwave 0.9.0 (PyPI wheel, Python 3.12, macOS arm64). Every repro below was rerun and reproduces.

  1. ATR smoothing. q.atr (and so q.supertrend) smooths true range with an EMA, alpha = 2/(n+1). It is not Wilder's RMA.
    • volatility.rs says so, but the Python side does not.
    • TaATR (Wilder) is not exposed in Python.
    • The SuperTrend metadata cites a TradingView script, and TradingView's ta.supertrend uses Wilder ATR. So quantwave's SuperTrend matches TradingView's flip rule but not its ATR. That is fine, since we adopted quantwave's convention, but it must be documented.
    • Repro: with hh=np.array([10,11,12,11.5,13,14,13.5,12,11,10.5,10,9.5,10,11.]), ll=hh-1 and cc=hh-.4, q.atr(5,hh,ll,cc)[-3:] gives [1.2428, 1.1619, 1.2412]. Wilder RMA(5) gives [1.2883, 1.2306, 1.2645].
    • Ask: document it, and expose a Wilder ATR (and a SuperTrend option to use it).
  2. Beta argument order. q.beta(52, market, stock) is the stock's beta, cov(m,s)/var(m) = 1.497. q.beta(52, stock, market) gives 0.401. The order is undocumented.
  3. Empty docstrings. q.beta.__doc__ and q.supertrend.__doc__ are None, so help() shows nothing.
  4. Return types. q.supertrend returns a list of SuperTrendResult objects, not arrays. The polars .ta.supertrend returns direction as Float64, while the plain API returns int.
  5. Polars signature. pl.col('c').ta.supertrend('h','l',10,3.0) passes high and low as arguments to the close expression, which is unusual.
  6. Import without polars. import quantwave without polars emits 8 UserWarnings, one per optional submodule. One warning, or none, would do.

Positive: roc, beta on clean series, ema and supertrend are bit-identical to hand references once the seed convention is known. The polars namespace equals the plain API. supertrend takes about 0.13 ms for 1,300 bars.

lavs9 avatar Nov 11 '26 03:11 lavs9

Resolved in v0.10.0 (commits 080efe0c and df25c2cf).

  • ATR Smoothing: Exposed TaAtr and AtrWilder directly in Python. Documented atr's default EMA smoothing vs Wilder's RMA in docstrings and metadata. Added smoothing="wilder" | "ema" option to SuperTrend.
  • Beta Argument Order: Documented q.beta(n, market, stock) in docstrings and the .ta namespace. Supported keyword arguments (market, stock) in q.beta.
  • Docstrings: Populated docstrings on generated PyFunctions (beta, supertrend, max, min, atr, etc.).
  • Import Warnings: Suppressed noisy UserWarnings on import quantwave in environments without Polars or NumPy.
  • Regression tests verified in tests/python/test_dogfood_fixes.py.

lavs9 avatar Nov 11 '26 05:11 lavs9