Improve RMA indicator parity with Cython #2653
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Improve WilderMovingAverage (RMA) indicator parity with Cython #2507
Restores feature-parity and behavioural equivalence between the Rust
WilderMovingAverage
implementation and the canonical Python/Cython reference.1 · Why this matters — Context & Motivation
period = 1
,reset()
afterNaN
) previously left the indicator in an undefined state.2 · What changed
period > 0
assert!(period > 0)
with descriptive panicalpha
computation1 / period
price_type
propagationhandle_*
methodscount = 1
count = 0
count
incrementsperiod = 1
fast-pathreset()
semanticshas_inputs
Display::fmt
has_inputs
lifecyclereset()
reset()
Send + Sync
rstest
suite (18 cases, 100 % line cov)3 · Five practical ways to put RMA to work
atr = true_range.rma(14)
long when price < RMA - k·σ
stop = max(stop, RMA(20))
liq = volume.rma(30)
rank = close/RMA(100) - 1
4 · Implementation notes
period > 0
panic mirrors Python; prevents div-by-zero UB.period = 1
degeneracy — α = 1 → RMA = last sample; test shields future optimisers.update_raw
— inlined FMA (mul_add
) for numerical precision.has_inputs
— explicit, avoids needlessOption<f64>
allocations.NaN
enters, value remainsNaN
untilreset()
(same as reference).Send + Sync
; wrap inArc<Mutex<>>
for multi-thread.update_raw
) using nightlycore::simd
. 🚧 Flagged as prediction.5 · Tests added / updated
test_new_with_zero_period_panics
first_tick_seeding_parity
count = 1
numeric_parity_with_reference_series
test_rma_period_one_behaviour
test_rma_large_period_not_initialized
test_reset_reseeds_properly
test_default_price_type_is_last
PriceType::Last
sanity checktest_update_with_nan_propagates