Repository navigation
Fix AroonOscillator lowest low scan and tie handling - #4914
Merged
cjdsellers merged 1 commit intoSep 5, 2026
Merged
Conversation
The low scan in calculate_aroon excluded the oldest bar of the period + 1 window via skip(1), so Aroon Down was overstated whenever the lowest low was the oldest bar and, once initialized, could never reach zero. Both scans also kept the oldest occurrence of the extreme on ties, inverting the v1 semantics. Scan the full window from newest to oldest with strict comparisons so the enumeration index is the periods-since count directly and ties resolve to the most recent occurrence, restoring the v1 window-scan and tie-break semantics. Correct the test fixtures that had pinned the defective values and add tie-break coverage. Fixes #4913
cjdsellers
approved these changes
Sep 5, 2026
cjdsellers
left a comment
Member
There was a problem hiding this comment.
Hi @haeganm,
Thanks for the PR. I've had a look and this looks good from my side. The implementation matches the v1 behavior, and the regression coverage exercises both affected cases 👍
cjdsellers
added a commit
that referenced
this pull request
Sep 6, 2026
- Upgrade compatible dependencies and record `cargo-vet` audits - Upgrade `uv`, `prek`, and Ruff across Docker and pre-commit - Add release sources to shared engineering tool metadata - Backfill current release notes for recently merged changes - Related to #4868, #4895, #4907, #4914, #4922, and #4924
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
self-contained fix that does not need prior discussion
CONTRIBUTING.md
and, if I used AI,
AI_POLICY.md
this draft
make format, then ranmake pre-commitlocally and confirmed it passed, or Idescribed an agreed limitation below
limitation below
RELEASES.md(maintainers keep it current to avoid merge conflicts)Summary
AroonOscillator::calculate_aroonscanned the highs over the fullperiod + 1bar window but scanned the lows with.iter().skip(1), excluding the oldest bar, so Aroon Down was overstated whenever the lowest low of the window was the oldest bar; once initialized, Aroon Down had a floor of100 / periodand could never reach 0 while Aroon Up could. On the fixture intest_value_twenty_inputsthe oscillator produced-25where the correct value is+30, a sign flip on a trend signal. Tie handling was also inverted relative to the v1 Cython implementation, which usednp.argmax/np.argminover a newest-first deque (most recent occurrence of the extreme wins); the current code kept the oldest occurrence. The fix rewrites both scans to iterate the window from newest to oldest with strict comparisons, so the enumeration index is directly the periods-since count and ties resolve to the most recent occurrence, restoring the v1 window-scan and tie-break semantics for a full window and keeping the two scans symmetric.Note this corrects the emitted values: any consumer of
aroon_down(and ofaroon_upin tie cases) will see different numbers after this change, which is the point of the fix but worth flagging for anyone comparing output across versions. No in-repo strategies, examples, or docs consume the affected values.Unrelated issue noted, not fixed here:
AroonOscillator::new(MAX_PERIOD)is accepted, but the window needsperiod + 1elements while the backingArrayDequecapacity isMAX_PERIOD, so atperiod = 1024the window silently caps at 1024 elements (and thedebug_assert_eq!fires in debug builds). This predates this change.Related issues/PRs
Closes #4913
Type of change
Breaking change details (if applicable)
n/a (output values change because they were incorrect; no API or behavioral contract changes)
Documentation
docs/developer_guide/docs.md)make py-stubsand committed the generated outputTesting
Test changes:
test_value_one_inputandtest_value_twenty_inputsin Rust, andtest_handle_bar_uses_bar_high_and_low,test_value_with_two_inputs, andtest_value_with_twenty_inputsin Python. The corrected Python expectations for the 20-input, period-10 fixture (up == 10.0,down == 20.0,value == -10.0) match what the legacy Cython-era test asserted for the identical inputs and period (tests/unit_tests/indicators/test_aroon.pyat v1.231.0:9.999999999999998/19.999999999999996/-9.999999999999998; the float noise there comes from v1's100.0 * (1.0 - n / period)formulation, while the Rust computation is exact for these values).test_ignore_oldest_lowtotest_lowest_low_at_oldest_barwith the corrected expectation (down == 0), since the previous name and assertion described the defect.test_tie_favors_most_recent_occurrencecovering the tie-break behavior for both sides.Validation:
cargo test -p nautilus-indicators --lib(568 passed),pytest python/tests/unit/indicators/(148 passed),cargo clippy -p nautilus-indicatorsclean,cargo +nightly fmtno changes. I also ran a differential test of the built module against a reference implementation of the v1 semantics (pure-Python argmax/argmin over a newest-firstdeque(maxlen=period + 1), first occurrence wins) across 500 random walks with mixed periods: 0 mismatches over 8,156 full-window evaluations; script available on request.