quantwave icon indicating copy to clipboard operation
quantwave copied to clipboard

Missing validation: period 0 accepted, negative period gives OverflowError, mismatched H/L/C lengths silently truncated

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.

import numpy as np, quantwave as q
q.ema(0, np.arange(1., 6))     # -> [1, 3, 3, 5, 5]   (alpha = 2), no error
q.sma(0, np.arange(1., 6))     # -> all NaN, no error
q.ema(-1, np.arange(1., 6))    # OverflowError: can't convert negative int to unsigned
len(q.supertrend(3, 2.0, np.arange(5.), np.arange(4.), np.arange(5.)))   # -> 4, no error

Ask:

  • Raise ValueError for period < 1, as documented.
  • Raise when the high, low and close lengths differ.

lavs9 avatar Nov 11 '26 03:11 lavs9

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

  • Period Validation: Implemented the ValidateParam trait across PyO3 indicator macros, converting periods < 1 (including 0 and negative values) into descriptive ValueErrors instead of PyO3 OverflowErrors.
  • Length Alignment: All multi-input macros (ohlc, hl, co, pv, ohlc4, hlcv) validate that input array lengths match, raising ValueError on length mismatches.
  • Regression tests verified in tests/python/test_dogfood_fixes.py::test_gh57_period_validation_raises_value_error and test_gh57_mismatched_lengths_raises_value_error.

lavs9 avatar Nov 11 '26 05:11 lavs9