Improve SMA indicator parity with Cython #2655
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.
1 · Why this matters — Context & Motivation
2 · What changed
assert period > 0
assert!(period > 0)
, descriptive panicdeque
for O(1) pop/pushVec
− O(n) pop(0)VecDeque
— amortised O(1)process_raw()
process_raw()
called by all handlersperiod
period = 1
degeneracyreset()
semanticsinitialized
Display::fmt
"SMA(10)"
3 · Test strategy — from broad guarantees to surgical edge-cases
sma_new_with_zero_period_panics
#[should_panic]
onperiod = 0
with exact msg.sma_initialized_state
initialized == false
,has_inputs == false
, fmt string.sma_update_raw_exact_period
period
samples seed correctly.count == period
,value == expected
count_progression_respects_period
(parametrised)period
.count() ≤ period
forperiod ∈ {1,3,5,16}
count_after_reset_is_zero
(parametrised)reset()
used to leavecount
stale.reset()
:count == 0
, flags cleared.sma_handle_single_quote
count == 1
,value == quote.mid()
sma_handle_multiple_quotes
period
quotes in window.sma_handle_trade
value == trade.price
after single tick.count_edge_case_period_one
count == 1
always,value == last price
.sliding_window_correctness
initialized_transitions_with_count
(param)initialized
flips exactly whencount == period
.false
→ stepperiod
true
.sma_rolling_mean_exact_values
abs_err < 1e-12
.sma_matches_reference_implementation
abs_err < 1e-12
for every step.sma_handles_bad_floats
deque_and_count_always_match
inputs.len() == count()
.sma_multiple_resets
period
warm-up, etc.