Skip to content

Fix hourly TimeFrame crash; switch equity profile QQQ to TSLA - #9

Merged
utkarshp845 merged 1 commit into
masterfrom
claude/trading-bot-version-error-dd1a9b
Aug 5, 2026
Merged

Fix hourly TimeFrame crash; switch equity profile QQQ to TSLA#9
utkarshp845 merged 1 commit into
masterfrom
claude/trading-bot-version-error-dd1a9b

Conversation

@utkarshp845

Copy link
Copy Markdown
Owner

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.

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>
@utkarshp845
utkarshp845 merged commit 8c6dcf5 into master Aug 5, 2026
2 checks passed
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