- Added HOURLY_ATR_STOP_MULTIPLIER (1.8x) vs daily (3.5x) - Added hourly-specific trail multipliers - Strategy now uses timeframe field to select appropriate stops - Tested multiple configurations on hourly: * 3.5x stops: -0.5% return, 45% max DD * 1.8x stops: -45% return, 53% max DD (worse) * Conservative regime (0.25x): -65% return, 67% max DD (terrible) - Conclusion: Hourly doesn't work with this strategy - Daily with relaxed regime remains best: +17.4% over 5yr, 24% max DD Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
3.0 KiB
3.0 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
Vibe Invest is a Rust algorithmic trading bot using the Alpaca paper trading API. It executes a hybrid momentum + mean-reversion strategy across 50 tech/financial stocks. It has two execution modes: live paper trading and historical backtesting, plus a web dashboard.
Build & Run Commands
# Build
cargo build --release
# Run live paper trading (requires .env with ALPACA_API_KEY and ALPACA_SECRET_KEY)
cargo run --release
cargo run --release -- --timeframe hourly
# Run backtesting
cargo run --release -- --backtest --years 3
cargo run --release -- --backtest --years 5 --capital 50000
cargo run --release -- --backtest --years 1 --months 6 --timeframe hourly
# Run backtesting with custom date range
cargo run --release -- --backtest --start-date 2007-01-01 --end-date 2008-12-31
cargo run --release -- --backtest --start-date 2020-03-01 --end-date 2020-12-31 --timeframe hourly
# Lint and format (available via nix flake)
cargo clippy
cargo fmt
There are no tests currently in the project.
Architecture
main.rs CLI parsing (clap), logging setup, mode routing
├── bot.rs Live trading loop: market hours detection, per-symbol analysis,
│ order execution, position tracking (JSON persistence)
├── backtester.rs Historical simulation: processes bars sequentially, tracks
│ positions, calculates metrics (CAGR, Sharpe, Sortino, drawdown)
├── alpaca.rs Alpaca REST API client with rate limiting (200 req/min via governor)
├── indicators.rs Technical indicators: EMA, SMA, RSI, MACD, ADX, ATR,
│ Bollinger Bands, ROC. Signal scoring algorithm in generate_signal()
├── dashboard.rs Axum web server (default port 5000) with Chart.js frontend
├── config.rs Strategy parameters, stock universe (50 symbols), risk limits
├── types.rs Domain types: Signal, TradeSignal, Trade, BacktestResult, Bar, etc.
└── paths.rs XDG-compliant file paths (~/.local/share/invest-bot/)
Key data flow: Both bot.rs and backtester.rs call indicators::generate_signal() which scores multiple indicators into a composite buy/sell signal. The bot executes via alpaca.rs; the backtester simulates internally.
Strategy Parameters (config.rs)
- Hourly mode scales all indicator periods by 7x
- Risk: max 22% position size, 2.5% stop-loss, 40% take-profit, trailing stop at 7% after 12% gain
- Signal thresholds: StrongBuy ≥ 6.0, Buy ≥ 3.5, Sell ≤ -3.5, StrongSell ≤ -6.0
- Backtester restricts to top 4 momentum stocks; live mode does not
Environment
- Nix flake provides dev tools: rustc, cargo, clippy, rustfmt, rust-analyzer, cargo-watch
.envfile required:ALPACA_API_KEY,ALPACA_SECRET_KEY, optionalDASHBOARD_PORT- Persistent state stored in
~/.local/share/invest-bot/(positions, equity history, logs) - Backtest outputs:
backtest_equity_curve.csv,backtest_trades.csvin working directory