Skip to content

perf: limit atr calculations to trailing window#9

Open
christianarriaga1234-coder wants to merge 1 commit into
Dragoon4002:mainfrom
christianarriaga1234-coder:perf/atr-tail-window
Open

perf: limit atr calculations to trailing window#9
christianarriaga1234-coder wants to merge 1 commit into
Dragoon4002:mainfrom
christianarriaga1234-coder:perf/atr-tail-window

Conversation

@christianarriaga1234-coder

Copy link
Copy Markdown

Summary

Optimizes repeated ATR-style calculations by limiting each helper to the trailing candle window actually used by the formula. This keeps the public return values and warmup behavior intact while avoiding full-history scans on every strategy tick.

Type

  • Bug fix
  • New strategy
  • New feature
  • Refactor
  • Documentation
  • Tests
  • Chore / dependency update

Related Issue

Refs #2

Changes

  • Limit ATR helpers in risk sizing, volatility, momentum, and smart-money strategies to the last period + 1 candles.
  • Limit the simplified ADX calculation to the trailing period needed for its final ATR/+DM/-DM values.
  • Add regression tests that compare the optimized helpers against legacy full-history implementations on 5,000 candles.

Testing

  • pytest tests/ passes locally
  • New tests added for new code
  • Manually tested (describe how): direct Python assertions for shared/tests/test_atr_tail_window.py passed.
  • python -m py_compile app/strategies/quant_algos/risk_sizing.py app/strategies/quant_algos/volatility_algos.py app/strategies/quant_algos/momentum_algos.py app/strategies/quant_algos/smart_money.py shared/tests/test_atr_tail_window.py
  • git diff --check on changed paths

Benchmark: synthetic 10,000-candle history, 2,000 repeated ATR calls. Legacy full-history scan: 8.428651s. Optimized trailing-window scan: 0.011347s. Speedup: 742.80x with equality asserted before timing.

Checklist

  • No secrets, API keys, or private keys committed
  • Type hints on all new public functions
  • docs/connections/service-map.md updated (if adding a new call path)
  • docs/architecture/data-model.md updated (if changing DB schema)
  • New strategy registered in app/strategies/signals.py (if adding a strategy)
  • New strategy added to strategy index in app/onchain_logger.py (if adding a strategy)
  • Breaking changes documented in PR description

Screenshots (if UI change)

N/A

@vercel

vercel Bot commented Jun 28, 2026

Copy link
Copy Markdown

@christianarriaga1234-coder is attempting to deploy a commit to the dragoon4002's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant