perf: limit trend directional movement scan#22
Conversation
|
@ShauryaMallampati is attempting to deploy a commit to the dragoon4002's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Follow-up on checks: the visible Vercel status is blocked on repo-owner/team authorization, and the GitHub Actions workflows are waiting for maintainer approval to run on this forked PR. Local validation for this patch:
|
There was a problem hiding this comment.
Pull request overview
This PR optimizes MarketAnalyzer trend-metric computation by avoiding full-window directional-movement array materialization and instead aggregating only the final values needed for the simplified ADX calculation, with a new regression test intended to validate equivalence vs the prior approach.
Changes:
- Optimize simplified ADX directional-movement computation by summing only the last 14 deltas instead of building full
plus_dm/minus_dmarrays. - Add a reference implementation in tests and compare optimized vs full-array behavior for both long and short windows.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
app/market/market_analysis.py |
Limits directional-movement scanning to the last 14 deltas and computes ADX from rolling sums instead of full arrays. |
shared/tests/test_market_analysis.py |
Adds regression tests that compare the optimized trend-metrics path against a reference full-array calculation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Directional movement. The simplified ADX below only uses the | ||
| # final 14 values, so skip older bars instead of materializing | ||
| # full-window arrays for every feature computation. | ||
| plus_dm_sum = 0 | ||
| minus_dm_sum = 0 |
| def test_compute_trend_metrics_matches_reference_full_dm_arrays(): | ||
| candles = _candles(2016) | ||
| recent = candles[-288:] | ||
| medium = candles[-2016:] | ||
| long = candles | ||
|
|
||
| assert MarketAnalyzer._compute_trend_metrics(recent, medium, long) == _reference_trend_metrics( | ||
| recent, | ||
| medium, | ||
| long, | ||
| ) |
|
Addressed the Copilot review comments in
Validation:
|
Refs #2.
Summary
Benchmark
Local synthetic OHLCV inputs, best of 5 repeats:
Validation