Skip to content

Fix AroonOscillator lowest low scan and tie handling - #4914

Merged
cjdsellers merged 1 commit into
nautechsystems:developfrom
haeganm:fix-aroon-lowest-low-scan
Sep 5, 2026
Merged

cjdsellers merged 1 commit into
nautechsystems:developfrom
haeganm:fix-aroon-lowest-low-scan

Conversation

@haeganm

@haeganm haeganm commented Sep 2, 2026

Copy link
Copy Markdown
Contributor
  • A maintainer agreed on the problem and approach in an issue, or this is a small,
    self-contained fix that does not need prior discussion
  • I have read and followed
    CONTRIBUTING.md
    and, if I used AI,
    AI_POLICY.md
  • I understand and can explain every submitted change and all information in this PR description
  • This change is complete, locally validated, and ready for review, or a maintainer requested
    this draft
  • I ran make format, then ran make pre-commit locally and confirmed it passed, or I
    described an agreed limitation below
  • I ran all relevant tests locally, no tests apply to this change, or I described an agreed
    limitation below
  • I have not modified RELEASES.md (maintainers keep it current to avoid merge conflicts)

Summary

AroonOscillator::calculate_aroon scanned the highs over the full period + 1 bar 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 of 100 / period and could never reach 0 while Aroon Up could. On the fixture in test_value_twenty_inputs the oscillator produced -25 where the correct value is +30, a sign flip on a trend signal. Tie handling was also inverted relative to the v1 Cython implementation, which used np.argmax / np.argmin over 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 of aroon_up in 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 needs period + 1 elements while the backing ArrayDeque capacity is MAX_PERIOD, so at period = 1024 the window silently caps at 1024 elements (and the debug_assert_eq! fires in debug builds). This predates this change.

Related issues/PRs

Closes #4913

Type of change

  • Bug fix (non-breaking)

Breaking change details (if applicable)

n/a (output values change because they were incorrect; no API or behavioral contract changes)

Documentation

  • Documentation changes follow the style guide (docs/developer_guide/docs.md)
  • For PyO3 binding or wrapped Rust doc changes, I ran make py-stubs and committed the generated output

Testing

  • I added/updated tests to cover new or changed logic

Test changes:

  • Corrected the fixtures that had pinned the defective behavior: test_value_one_input and test_value_twenty_inputs in Rust, and test_handle_bar_uses_bar_high_and_low, test_value_with_two_inputs, and test_value_with_twenty_inputs in 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.py at v1.231.0: 9.999999999999998 / 19.999999999999996 / -9.999999999999998; the float noise there comes from v1's 100.0 * (1.0 - n / period) formulation, while the Rust computation is exact for these values).
  • Renamed test_ignore_oldest_low to test_lowest_low_at_oldest_bar with the corrected expectation (down == 0), since the previous name and assertion described the defect.
  • Added test_tie_favors_most_recent_occurrence covering 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-indicators clean, cargo +nightly fmt no 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-first deque(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.

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
@CLAassistant

CLAassistant commented Sep 2, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cjdsellers cjdsellers left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
cjdsellers merged commit 8d9a922 into nautechsystems:develop Sep 5, 2026
30 checks passed
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AroonOscillator excludes the oldest bar when scanning for the lowest low

3 participants