quantwave
quantwave copied to clipboard
Python docs gaps: ATR is EMA-smoothed (not Wilder), beta argument order, empty docstrings, noisy import without polars
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.
- ATR smoothing.
q.atr(and soq.supertrend) smooths true range with an EMA, alpha = 2/(n+1). It is not Wilder's RMA.volatility.rssays 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.supertrenduses 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-1andcc=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).
- 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. - Empty docstrings.
q.beta.__doc__andq.supertrend.__doc__areNone, sohelp()shows nothing. - Return types.
q.supertrendreturns a list ofSuperTrendResultobjects, not arrays. The polars.ta.supertrendreturns direction as Float64, while the plain API returns int. - 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. - Import without polars.
import quantwavewithout 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.
Resolved in v0.10.0 (commits 080efe0c and df25c2cf).
- ATR Smoothing: Exposed
TaAtrandAtrWilderdirectly in Python. Documentedatr's default EMA smoothing vs Wilder's RMA in docstrings and metadata. Addedsmoothing="wilder" | "ema"option to SuperTrend. - Beta Argument Order: Documented
q.beta(n, market, stock)in docstrings and the.tanamespace. Supported keyword arguments (market,stock) inq.beta. - Docstrings: Populated docstrings on generated PyFunctions (
beta,supertrend,max,min,atr, etc.). - Import Warnings: Suppressed noisy
UserWarnings onimport quantwavein environments without Polars or NumPy. - Regression tests verified in
tests/python/test_dogfood_fixes.py.