trading-algo
Personal quantitative-research and broker-operations system. US stocks run through Interactive Brokers and crypto through Binance, Kraken, and Hyperliquid. The emphasis is validation, explicit order safeguards, reconciliation, and auditability.
What's inside
| Piece | Where | What it does |
|---|---|---|
| Equity research | trading_algo/multi_strategy/ | momentum, mean reversion, pairs, opening-range, flow, and regime experiments |
| Crypto research | crypto_alpha/edges/ | funding, basis, cross-exchange, and liquidation studies |
| Options book | quant_core/strategies/options/ | wheel, PMCC, jade lizard, put spreads, portfolio wheel, hybrid regime |
| ATLAS | quant_core/models/atlas/ | experimental Mamba-2 and cross-attention policy model; currently blocked in-sample |
| IBKR data/ops CLI | trading_algo/ibkr_tool.py | quotes, chains, depth, history, scanners, orders, and what-if calculations |
| Flex CLI | trading_algo/flex_tool.py | statements, P&L, cash, and dividends from the Flex Web Service |
| 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 |
The operator layer can read strategy signals, recent fills, position state, and public-data context, then propose an action. The risk controller decides whether the proposal can transmit. Rejections are logged with the reason.
The operator surface is a CLI because structured envelopes, stable exit codes, idempotency keys, and command-level audit records are easier to inspect than a second local HTTP layer.
ATLAS
ATLAS is an experimental policy model combining Mamba-2, cross-attention, PPO, and a behavioral-cloning warm start. It is evaluated by regime rather than through one blended score.
The current iteration is blocked in-sample. A simpler LightGBM ranker on the same dataset is now the primary comparison because it is easier to diagnose and cheaper to falsify.
The ablation harness varies SSM block depth, state dim, and the BC coefficient annealing schedule. Evaluation is per-regime, because 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, PBO, and benchmark-relative statistics are computed alongside point estimates.
- White's Reality Check and sequential out-of-sample evaluation are part of the research workflow.
- 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.
- Known limitations are documented in the repository and treated as part of the result.
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. 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.
Evidence boundary
I do not publish private backtest returns here. They are easy to overstate, change as the research changes, and have not been independently audited. The public claim is narrower: the repository contains research, broker integration, validation, and safety infrastructure that can be inspected directly.
Known issues
- The crypto research has not produced a robust benchmark-beating portfolio.
_strategy_positionsin the controller never gets populated, so per-strategy position limits are dormant. Falls back to aggregate limits.- Trailing stops remain disabled because they degraded the tested configurations.
- 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
Active personal research. The current focus is the operational loop—clean data, reproducible evaluation, broker reconciliation, and guarded order flow—not a public performance claim. If you work with academic-grade market data, email me.
mahimn · trading-algo · personal system · copy reviewed jul 2026