Fix hourly TimeFrame crash; switch equity profile QQQ to TSLA - #9
Merged
Merged
Conversation
bot/broker_alpaca.py::get_historical_bars built Alpaca's TimeFrame as TimeFrame(timeframe_minutes, Minute) unconditionally. Alpaca rejects Minute-unit amounts outside 1-59, so TIMEFRAME_MINUTES=60 (every hourly profile) crashed every run after the startup sleep with "ValueError: Second or Minute units can only be used with amounts between 1-59", wiping the whole trade cycle instead of recording a HOLD. Added _resolve_timeframe() to express 60 minutes as TimeFrame(1, Hour) and exact-day multiples as TimeFrame(1, Day). Regression tests in tests/test_broker_alpaca.py. Also switched config/live_spy.env and config/paper_spy.env from SYMBOL=QQQ to SYMBOL=TSLA. Not a drop-in swap: TSLA's hourly ATR% runs ~3x QQQ's, so the QQQ-tuned config replayed on TSLA unchanged produced a 29.6% max drawdown for ~breakeven P&L. Re-ran the repo's walk-forward optimizer against TSLA bars (yfinance, no Alpaca keys available outside EC2) and re-tuned entry filters and position sizing (90% -> 60% target notional) specifically for TSLA. Shipped config: 28 trades / ~2.9yr, PF 1.56 (1.55 under 2x slippage), max DD 9.4%, net +$33.0 (+22%) on $150 -- but almost all of that P&L came from the 2024 rally year; 2023/2025/2026 were each roughly flat-to-negative. Full methodology and every acceptance-check number in docs/strategy_tsla_2026-08.md. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
bot/broker_alpaca.py::get_historical_bars built Alpaca's TimeFrame as TimeFrame(timeframe_minutes, Minute) unconditionally. Alpaca rejects Minute-unit amounts outside 1-59, so TIMEFRAME_MINUTES=60 (every hourly profile) crashed every run after the startup sleep with "ValueError: Second or Minute units can only be used with amounts between 1-59", wiping the whole trade cycle instead of recording a HOLD. Added _resolve_timeframe() to express 60 minutes as TimeFrame(1, Hour) and exact-day multiples as TimeFrame(1, Day). Regression tests in tests/test_broker_alpaca.py.
Also switched config/live_spy.env and config/paper_spy.env from SYMBOL=QQQ to SYMBOL=TSLA. Not a drop-in swap: TSLA's hourly ATR% runs ~3x QQQ's, so the QQQ-tuned config replayed on TSLA unchanged produced a 29.6% max drawdown for ~breakeven P&L. Re-ran the repo's walk-forward optimizer against TSLA bars (yfinance, no Alpaca keys available outside EC2) and re-tuned entry filters and position sizing (90% -> 60% target notional) specifically for TSLA. Shipped config: 28 trades / ~2.9yr, PF 1.56 (1.55 under 2x slippage), max DD 9.4%, net +$33.0 (+22%) on $150 -- but almost all of that P&L came from the 2024 rally year; 2023/2025/2026 were each roughly flat-to-negative. Full methodology and every acceptance-check number in docs/strategy_tsla_2026-08.md.