quantwave
quantwave copied to clipboard
0.10.0: plain quantwave.atr and polars .ta.atr are different indicators; polars .ta lacks warmup=; roc/rocp unit mismatch
Found in trade_backtest on quantwave 0.10.0 (PyPI wheel). Reproduced. This breaks the bit-for-bit parity between the plain and polars layers that #60 aimed for, and screener and trade_backtest may use different layers.
import numpy as np, polars as pl, quantwave as q
rng = np.random.default_rng(1)
cc = 100 + np.cumsum(rng.normal(0, 1, 120))
hh = cc + rng.uniform(0, 2, 120)
ll = cc - rng.uniform(0, 2, 120)
a1 = np.array(q.atr(14, hh, ll, cc)) # plain: EMA, alpha 2/15, value from bar 0
a2 = pl.DataFrame({'h': hh, 'l': ll, 'c': cc}).select(
pl.col('c').ta.atr(pl.col('h'), pl.col('l'), 14))['c'].to_numpy() # polars: Wilder, alpha 1/14, first value at bar 14
a1[100], a2[100] # 2.2230 vs 2.1427
pl.DataFrame({'x': [1., 2, 3, 4]}).select(pl.col('x').ta.sma(3, warmup='nan'))
# TypeError: TaNamespace.sma() got an unexpected keyword argument 'warmup'
pl.DataFrame({'x': [1., 2, 3, 4]}).select(pl.col('x').ta.sma(3))['x'].to_list()
# [1.0, 1.5, 2.0, 3.0] still partial; there is no way to get NaN warm-up in polars
q.roc(1, [1., 2.])[1] # 100.0 (percent); polars .ta.rocp is a fraction; there is no top-level rocp
Asks:
- Make
atrthe same indicator in both layers, withsmoothing=exposed in both. Today the same name means EMA in one layer and Wilder in the other. - Add
warmup=to the polars.tamoving averages (sma,ema,alma). - Add a top-level
rocp, or document thatrocis in percent androcpis a fraction. - Nice to have: a run or gap reset helper that restarts an indicator after a hole of more than N bars in a series (trade_backtest rule S14), so screener can replicate it.
Resolved in v0.10.1 (commit 774fb70d, tag v0.10.1).
- ATR Plain vs. Polars Parity: Both
quantwave.atrandpl.col().ta.atrnow default to Wilder's RMA (alpha = 1/period, SMA-seeded afterperiodbars), giving bit-for-bit identical results (2.1427 on the repro). Both layers andAtrstreaming class supportsmoothing='wilder'andsmoothing='ema'(2.2230 on the repro). - Polars MA Warmup: Added
warmup='partial' | 'nan'acrosspl.col().ta.sma,pl.col().ta.ema, andpl.col().ta.alma. - Top-Level ROCP: Added
quantwave.rocpandquantwave.Rocpreturning the fractional return ratio(p - p_prev) / p_prev. Clarified docs onroc(percent, 100x) vsrocp(fraction, 1x). - Gap Reset Helper (Rule S14): Added
quantwave.apply_with_gap_reset(indicator_factory, *series_args, max_gap=5)to cleanly reset stateful indicators when gaps exceedingmax_gapconsecutive NaN/missing bars are encountered.