Improve EMA indicator parity with Cython #2642
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 EMA indicator parity with Cython
Restores feature-parity and behavioural equivalence between the Rust
ExponentialMovingAverage
(EMA) implementation and the canonical Python/Cython reference.1 Why this matters — Context & Motivation
reset()
afterNaN
) previously left the indicator in an undefined state.2 What changed
period > 0
assert!(period > 0)
alpha
forperiod = 1
count
= 1count
= 0count
incrementsreset()
semanticshas_inputs
Display::fmt
Send + Sync
rstest
suite3 Five practical ways to put EMA to work
long when price > EMA
, exit on cross-down.slope / ATR
.size = k · d(EMA)/dt
.quote_mid = EMA(last_trade)
.σ(price – EMA)
≈ realised σ without extra filters.close / EMA – 1
.4 Implementation notes
period > 0
panic matches Python.has_inputs
lifecycle — toggled on first sample, cleared onreset()
.reset()
.Send + Sync
; wrap inMutex/Arc
for multi-threaded use.5 Tests added / updated
test_period_one_behaviour
— α = 1 behaviourtest_nan_poisoning_and_reset_recovery
test_has_inputs_lifecycle
test_subnormal_inputs_do_not_underflow
new_panics_on_zero_period
Related: #2507