quantwave icon indicating copy to clipboard operation
quantwave copied to clipboard

Document ATR seed conventions and add explicit seed/warmup options (Wilder 1978 vs TA-Lib)

Open lavs9 opened this issue 3 weeks ago • 1 comments

Problem / Context

As observed by trade_backtest during dogfooding: qw.atr(h, l, c, period=14, smoothing='wilder') returns NaN for bars 0–13 and seeds at bar 14 as mean(TR[1..14]), matching TA-Lib. In contrast, J. Welles Wilder Jr.'s original 1978 specification (New Concepts in Technical Trading Systems) defines TR[0] = H[0] - L[0] and seeds the first ATR at bar 13 as mean(TR[0..13]), then recurses as ATR[t] = (13 * ATR[t-1] + TR[t]) / 14. The seed difference decays exponentially and falls below 1e-9 by bar 400, but creates a 1-bar phase difference and slight initial divergence on short lookbacks.

Asks

  1. Document the ATR seed convention across plain Python, Polars .ta, and Rust docstrings / CONVENTION_NOTES.
  2. Add an explicit seed= / warmup= parameter:
    • seed="talib" (default, standard TA-Lib behavior): bar 0 TR undefined, seeds at bar period from TR[1..period].
    • seed="wilder1978" (aliases: "classic", "wilder"): Wilder 1978 book formula with TR[0] = H[0] - L[0], seeds at bar period - 1 from TR[0..period-1].
    • Support in plain Python (qw.atr), streaming (qw.Atr), and Polars (pl.col().ta.atr).

lavs9 avatar Nov 11 '26 12:11 lavs9

Resolved: Added explicit seed='talib' (default) and seed='wilder1978' (or 'classic') options across plain Python qw.atr, streaming qw.Atr, and Polars pl.col().ta.atr. Documented the seed convention in docstrings and CONVENTION_NOTES.

lavs9 avatar Nov 11 '26 12:11 lavs9