|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Mesa Quant is a personal quantitative trading platform (written in Portuguese) targeting American markets — stocks, options, futures, and crypto. The project is in early-stage development (Phase 1 — Infrastructure). |
| 8 | + |
| 9 | +**Developer context:** Beginner in quantitative trading, intermediate Python developer. Prefers didactic code over premature optimization. Should be warned explicitly when implementations carry financial risk. |
| 10 | + |
| 11 | +## Commands |
| 12 | + |
| 13 | +```bash |
| 14 | +# Setup |
| 15 | +python3 -m venv venv |
| 16 | +source venv/bin/activate |
| 17 | +pip install -r requirements.txt |
| 18 | + |
| 19 | +# Copy and edit config before running anything |
| 20 | +cp configs/config.example.yaml configs/config.yaml |
| 21 | + |
| 22 | +# Tests |
| 23 | +pytest tests/ -v |
| 24 | + |
| 25 | +# Run a single test file |
| 26 | +pytest tests/path/to/test_file.py -v |
| 27 | +``` |
| 28 | + |
| 29 | +## Architecture |
| 30 | + |
| 31 | +Data flows top-to-bottom through three layers: |
| 32 | + |
| 33 | +**Collection → Persistence → Analysis/Execution** |
| 34 | + |
| 35 | +- **`src/collectors/`** — Data ingestion. `ib_connector.py` wraps `ib_insync` for Interactive Brokers (stocks, futures, historical bars). Crypto via `ccxt` is planned but not yet implemented. |
| 36 | +- **`src/utils/database.py`** — `DatabaseManager` handles TimescaleDB/PostgreSQL via SQLAlchemy. OHLCV data is stored in hypertables for time-series efficiency. |
| 37 | +- **`src/risk/risk_manager.py`** — Portfolio-level guardrails: max position size (5%), max daily loss (2%), max drawdown (10%). Also computes Kelly-based position sizing. |
| 38 | +- **`src/backtest/`** and **`src/execution/`** — Currently empty placeholders; VectorBT is the intended backtesting library; `ib_insync` for order execution. |
| 39 | +- **`tools/`** — Auxiliary Streamlit tools for research (seasonality analysis, etc.) |
| 40 | + |
| 41 | +Jupyter notebooks in `notebooks/` are for research and strategy development. Logs go to `logs/mesa_quant.log`. |
| 42 | + |
| 43 | +## Configuration |
| 44 | + |
| 45 | +All runtime config lives in `configs/config.yaml` (gitignored). Copy from `configs/config.example.yaml`. |
| 46 | + |
| 47 | +Key sections: |
| 48 | +- `interactive_brokers`: TWS/Gateway connection (paper port 7497/4002, live 7496/4001) |
| 49 | +- `database`: PostgreSQL/TimescaleDB credentials |
| 50 | +- `crypto`: Binance API keys |
| 51 | +- `risk`: Position and drawdown limits |
| 52 | +- `logging`: Log level and file path |
| 53 | + |
| 54 | +## Infrastructure Dependencies |
| 55 | + |
| 56 | +The platform requires external services to function: |
| 57 | +- **TimescaleDB** (PostgreSQL extension) — see `docs/setup_server.md` for server setup |
| 58 | +- **IB TWS or IB Gateway** — must be running and API connections enabled before `IBConnector` will work; on headless servers, use Xvfb |
| 59 | + |
| 60 | +## Risk Rules (non-negotiable) |
| 61 | + |
| 62 | +These limits are hardcoded in `src/risk/risk_manager.py` and must NOT be relaxed without explicit review: |
| 63 | +- Max position size: **5%** of portfolio per trade |
| 64 | +- Max daily loss: **2%** of portfolio (daily stop) |
| 65 | +- Max drawdown: **10%** (global stop) |
| 66 | +- Every new strategy must pass paper trading before going live |
| 67 | + |
| 68 | +## Git Workflow |
| 69 | + |
| 70 | +- `main` branch for production-ready code |
| 71 | +- `develop` branch for integration |
| 72 | +- Feature branches from `develop` |
| 73 | +- Commit format: `feat:`, `fix:`, `docs:`, `refactor:`, `test:` |
| 74 | + |
| 75 | +## Current Roadmap |
| 76 | + |
| 77 | +- [x] Initial project structure |
| 78 | +- [ ] **Phase 1** — Ubuntu Server + TimescaleDB setup |
| 79 | +- [ ] **Phase 2** — Historical data ingestion (IB + CCXT) |
| 80 | +- [ ] **Phase 3** — First backtests with VectorBT |
| 81 | +- [ ] **Phase 4** — Paper Trading |
| 82 | +- [ ] **Phase 5** — Live Trading with small capital |
| 83 | + |
| 84 | +## Language Note |
| 85 | + |
| 86 | +Code comments, docstrings, variable names, and documentation are written in Portuguese. User-facing messages and interactions with the developer are in Portuguese (BR). Follow this convention when adding new code. |
0 commit comments