Improve AMAT indicator parity with Cython #2669
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
VecDeque
could silently grow and re-allocate, undermining latency guarantees; fixed-capacityArrayDeque
removes that risk.signal_period
, surfacing config errors early.DEFAULT_MA_TYPE = Exponential
constant replaces scatteredunwrap_or(Simple)
calls; trend logic is condensed and explicit.2 · What changed
VecDeque
, manualif len()>n { pop_front() }
ArrayDeque<f64, { MAX_SIGNAL + 1 }>
(constant memory, no alloc)Simple
fallbackDEFAULT_MA_TYPE = Exponential
new()
panics if periods ≤ 0,slow ≤ fast
, orsignal > MAX_SIGNAL
ArrayDeque
; explicit regression testhas_inputs
+ len checksinitialized = slow_ma.ready && buf_full
///
invariants3 · Implementation notes
ArrayDeque<f64, { MAX_SIGNAL + 1 }, Wrapping>
guarantees O(1) push/pop and ~8 KiB max footprint.ma_type
parameter now fully respected; default selection (Exponential
) matches TA-Lib/NumPy behaviour.≥/≤
deltas to avoid edge-case oscillation.MAX_SIGNAL
capped at 1024; larger windows can be re-enabled behind a feature flag if needed.4 · Tests added / updated
default_ma_type_is_exponential
new_panics_on_zero_*
new_panics_when_slow_not_greater_than_fast
buffer_len_never_exceeds_signal_plus_one
initialized_becomes_true_after_slow_ready_and_buffer_full
long_run_flag_sets_on_bullish_trend
/short_run_flag_sets_on_bearish_trend
reset_clears_internal_state
ma_type_override_is_respected
Related #2507. Supersedes earlier exploratory diffs on AMAT buffer handling.