Skip to main content

Overview

Feature engineering is the first step in both training and inference. ml/feature_engineering.py transforms raw OHLCV candles into the 62-feature vector consumed by all four models. The feature list is a contract. The training pipeline, inference pipeline, and ml_config.json must all reference the same 62 features in the same order. Any change requires retraining all 4 models.

Feature groups

These features must never be dropped based on SHAP analysis alone. Historical testing showed removing them increased drawdown significantly. They carry regime and timing information not captured by price alone.
Never drop is_news_near, news_minutes_away, news_count_today, is_news_risk_window, is_london_session, is_ny_session, or is_asian_session based on SHAP importance alone. Low SHAP mean β‰  useless. These features encode risk context that only matters during specific market regimes.
These features are computed at runtime from live account data, not from candles. They allow the models to adapt to current account health.
Derived entirely from existing OHLCV data β€” no external API dependencies.

Labeling

ml/feature_engineering.py uses ATR-aware forward labeling to generate training targets. For signal model labels:
The tp_atr multiplier is tuned during Optuna search. Labels are generated using the same ATR-based SL/TP logic that the live bot uses, ensuring training distribution matches live inference distribution. For position model labels, ml/position_labeling.py generates EXIT labels when the price subsequently reverses by more than a configurable threshold before reaching TP.

Adding or modifying features

The Three-File Rule applies to all feature changes:
  1. ml/feature_engineering.py β€” add the computation
  2. ml_config.json β†’ features array β€” add the name in the correct position
  3. Retrain all 4 models
After retraining, run python ml/hf_hub.py --push to publish the new models and models/model_compat.json to Hugging Face Hub. Do not add features speculatively. Every added feature increases the risk of overfitting and must be validated with an OOS backtest showing improvement.