trading-algo
Multi-strategy quant trading system. US stocks through Interactive Brokers, crypto through Binance/Kraken/Hyperliquid. Runs 25 strategies in parallel, has its own backtester, goes live through IBKR with safety gates. Claude Code sits on top and operates the whole thing.
What's inside
| Piece | Where | What it does |
|---|---|---|
| Equity strategies | trading_algo/multi_strategy/ | ~15 adapters: momentum, mean reversion, pairs, ORB, flow, regime, Hurst, 3-state HMM, more |
| Crypto edges | crypto_alpha/edges/ | 9 edges on perp futures — funding, basis, cross-exchange, liquidation cascades |
| Options book | quant_core/strategies/options/ | wheel, PMCC, jade lizard, put spreads, portfolio wheel, hybrid regime |
| ATLAS | quant_core/models/atlas/ | RL trader, Mamba-2 + cross-attention, PPO + EWC (v7) |
| IBKR data/ops CLI | trading_algo/ibkr_tool.py | ~46 commands — quotes, chains, depth, history, scanners, orders, what-if calcs |
| Flex CLI | trading_algo/flex_tool.py | ~31 commands for the Flex Web Service — statements, P&L, cash, dividends |
| Gemini trader | trading_algo/llm/ | unwired. Lit doesn't back LLM trading signals. Notes |
| Risk controller | quant_core/risk/ | hard-coded rules — size, correlation, drawdown, freeze-qty, market hours, TFSA / MIS |
Claude Code reads the strategy signals, recent fills, position state, and live world-context (through worldmonitor-mcp), then proposes an action. The risk controller decides whether the proposal transmits. The agent can't skip that step — anything rejected gets logged with the reason.
Why CLIs instead of HTTP for the agent surface: structured envelopes, stable exit codes, idempotency keys, no auth layer to misconfigure, and every action is a shell command in the audit log. Also the thing about HTTP being basically unusable for an agent without a parser per endpoint.
ATLAS
RL trader. Hybrid Mamba-2 SSM + cross-attention policy network, ≈84M params. PPO + behavioral-cloning warm-start, curriculum learning across crash/uptrend/high-IV regimes, EWC experiments for continual learning. Seven training iterations to date.
v7 is blocked in-sample. Pivoting toward a LightGBM ranker on the same dataset because the gradient on a 84M-param policy net through PPO is doing less work per epoch than the gradient through a tree ensemble on the same features. Will revisit the SSM track later.
The ablation harness varies SSM block depth, state dim, and the BC coefficient annealing schedule. Evaluation is per-regime, not pooled — a single Sharpe across mixed regimes hides exactly the failure modes you'd want to catch. Inference runs on PyTorch for training and Apple MLX on the M-series box for paper-trade smoke tests.
Backtester
The whole system is worthless if the backtests lie, so it got a lot of attention.
- Signals on bar N fill at bar N+1 open — no same-bar look-ahead.
- Hard IS/OOS split, walk-forward across sequential folds.
- Commissions ~$0.0035/share, slippage 2bp. Crypto adds funding settlement at correct UTC hours.
- Deflated Sharpe (Bailey & López de Prado) with a p-value, not a point estimate. Current p < 0.001 on V11.
- PBO and White's Reality Check on every config before it leaves research.
- Fraud-detection suite: random signals must give Sharpe ~0, reversed signals must flip PnL, doubled costs must crush the edges, single-asset isolation must show where alpha actually comes from. If any null test passes-when-it-shouldn't, the infra is lying.
- 12 documented limitations in the repo. Worth reading those before trusting anything else here.
Live safety
Five gates before any order transmits:
gate 1 · TRADING_ALLOW_LIVE=true in env
gate 2 · --allow-live on the command line
gate 3 · paper-only enforcement explicitly disabled
gate 4 · per-order YES typed at the terminal
gate 5 · confirmation callback wired through the CLI
Any missing gate blocks the call outright — not warns, not retries. Most of the live runs go through IB Gateway via IBC in tmux with AutoRestartTime=23:55 so it survives the broker's nightly disconnect. Paper and live can run on different ports at the same time.
Numbers (V11)
Equity is 2016–2026 (10 yr). DSR 16, p < 0.001. Alpha vs SPY ≈ 4% annualized at beta 0.12. Crypto: Sharpe 0.28, +7.7% return, 21.8% MDD over 2022–2026, which lags BTC buy-and-hold (Sharpe ~0.80). The crypto book is a diversification asset, not a replacement, and the README says exactly that.
Known issues
- Crypto lags BTC buy-and-hold. Three of nine edges are positive standalone (IMC +0.72, CED +0.40, PBMR +0.33); the other six work as diversifiers.
_strategy_positionsin the controller never gets populated, so per-strategy position limits are dormant. Falls back to aggregate limits.- Trailing stops are off in V11 — they hurt Sharpe on every config I tried.
- Crypto funding data has gaps depending on which exchange API the pull hits.
- ATLAS v7 training needs the R3000 survivors dataset, which isn't in the repo. Pivoting toward LightGBM anyway.
Status
Live capital, small. Returns are near the S&P benchmark — the operational loop is what I'm proving right now, not the alpha. ATLAS pivot in progress. Looking for production / academic data partners (Polygon, Algoseek, Refinitiv Tick History) — email if you have a clean L2 feed or a research seat.
mahimn · trading-algo · live since 2024 · last updated apr 2026