# 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 ```bash # 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 # 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 - `.env` file required: `ALPACA_API_KEY`, `ALPACA_SECRET_KEY`, optional `DASHBOARD_PORT` - Persistent state stored in `~/.local/share/invest-bot/` (positions, equity history, logs) - Backtest outputs: `backtest_equity_curve.csv`, `backtest_trades.csv` in working directory