Repository layout
The three-file rule
Any ML feature change touches exactly three files:ml/feature_engineering.pyβ add the feature computationml_config.jsonβfeaturesarray β add the name in the correct position- Retrain all 4 models β Signal, Position, SLTP, Risk (in that order)
models/model_compat.json file stores a hash of the feature list. On startup, EnsemblePredictor verifies the hash against the current ml_config.json. A mismatch raises ModelCompatibilityError immediately.
Strict training order
Models must always be trained in this order:| Model | Depends on |
|---|---|
| Signal | Nothing (first) |
| Position | Signal model paths (saved to disk) |
| SLTP | Signal + position models (saved to disk) |
| Risk | Completed backtest using SLTP models |
Backtester / live parity
backtest/run.py must always mirror trading/bot.py. Every change to execution logic in the bot must be reflected in the backtester, and vice versa.
Key parity invariants:
- Same feature engineering (
ml/feature_engineering.py) - Same model inference chain (calibrated pkl β ONNX β raw pkl)
- Same position sizing formula
- Same equity-aware SL cap
- Same circuit breakers and gates
- Same position model evaluation timing
Lane discipline
The codebase has two clearly separated lanes:| Lane | Who | What |
|---|---|---|
| Client/user lane | Trader on their machine | Pull approved models, run trading.py |
| Developer lane | Developer on their machine | Retrain, optimize, validate OOS, publish to HF Hub |
pip install -r requirements.txt is fine).
Config files
Two config files govern all behavior:| File | What it controls | Tracked in git |
|---|---|---|
config.json | Runtime params: symbol, risk, SL/TP, profile, filters, broker | Yes |
ml_config.json | Features, model paths, labeling, training params | Yes |
weekly_optimize.py updates config.json, the change appears in git history. This makes every optimization run fully auditable.
Multi-agent orchestration
For complex tasks, the codebase supports Claude Code agent orchestration:- Model Optimizer β assesses complexity, writes scope lock, prescribes model tier
- Project Manager β spawns worker agents within the scope lock
- Feature Engineer β validates feature changes, tests OOS impact
- NOVOSKY Optimizer β runs the full SHAP β Optuna β retrain β OOS loop