Complete machine learning pipeline for trading: feature engineering, AutoML, deep learning, and financial RL. Use for automated parameter sweeps, feature creation, model training, and anti-leakage validation.
Unified skill for the complete ML pipeline within a quant trading research system.
Consolidates eight prior skills into a single authoritative reference covering
the full lifecycle: data validation, feature creation, selection,
transformation, anti-leakage checks, pipeline automation, deep learning optimization, and deployment.
1. When to Use
Activate this skill when the task involves any of the following:
Creating, selecting, or transforming features for an ML-driven strategy.
Auditing an existing feature pipeline for data leakage or overfitting risk.
Automating an end-to-end ML pipeline (data prep through model export).
Evaluating feature importance, scaling, encoding, or interaction effects.
Integrating features with a feature store (Feast, Tecton, custom Parquet store).
Explaining core ML concepts (bias-variance, cross-validation, regularisation)
in the context of feature engineering decisions.
2. Inputs to Gather
Before starting work, collect or confirm:
Input
Details
관련 스킬
Objective
Target metric (Sharpe, accuracy, RMSE ...), constraints, time horizon.
Data
Symbols / instruments, timeframe, bar type, sampling frequency, data sources.
Leakage risks
Point-in-time concerns, survivorship bias, look-ahead in labels or features.
Compute budget
CPU/GPU limits, wall-clock budget for AutoML search.
Latency
Online vs. offline inference, acceptable prediction latency.
Interpretability
Regulatory or research need for explainable features / models.
Deployment target
Where the model will run (notebook, backtest harness, live engine).
3. Feature Creation Patterns
3.1 Numerical Features
Interaction terms: price * volume, high / low, close - open.
Rolling statistics: mean, std, skew, kurtosis over configurable windows.
Permutation importance: model-agnostic; run on out-of-fold predictions.
4. Anti-Leakage Checks
Data leakage is the single most common cause of inflated backtest results.
Apply these checks at every pipeline stage:
4.1 Label Leakage
Labels must be computed from future returns relative to the feature
timestamp. Verify that the label window does not overlap the feature window.
Use purging and embargo when labels span multiple bars.
4.2 Feature Leakage
No feature may use information from time t+1 or later at prediction time t.
Rolling statistics must use a closed left window: df['feat'].rolling(20).mean().shift(1).
Target-encoded categoricals must be computed on the training fold only.
4.3 Cross-Validation Leakage
Use purged k-fold or walk-forward CV for time-series. Never use random
k-fold on ordered data.
Insert an embargo gap between train and test folds to prevent bleed-through
from autocorrelation.
4.4 Survivorship & Selection Bias
Ensure the universe of instruments at time t reflects what was actually
tradable at that time (delisted stocks, halted symbols removed later).
Backfill from point-in-time databases where available.
4.5 Validation Checklist
Run before every backtest:
[ ] Labels computed strictly from future returns (no overlap with features)
[ ] All rolling features shifted by at least 1 bar
[ ] Target encoding uses in-fold means only
[ ] Walk-forward or purged CV used (no random shuffle on time-series)
[ ] Embargo gap >= max(label_horizon, autocorrelation_lag)
[ ] Universe is point-in-time (no survivorship bias)
[ ] No global scaling fitted on full dataset (fit on train, transform test)
5. Pipeline Automation (AutoML)
5.1 Prerequisites
Python environment with one or more AutoML libraries:
Auto-sklearn, TPOT, H2O AutoML, PyCaret, Optuna, or custom Optuna pipelines.
Training data in CSV / Parquet / database.
Problem type identified: classification, regression, or time-series forecasting.
5.2 Pipeline Steps
Step
Action
1. Define requirements
Problem type, evaluation metric, time/resource budget, interpretability needs.
deployment/ -- prediction API code, input validation, requirements.txt.
6. Core ML Fundamentals (Feature-Engineering Context)
6.1 Bias-Variance Trade-off
More features increase model capacity (lower bias) but risk overfitting (higher variance).
Use regularisation (L1/L2), feature selection, or dimensionality reduction to manage.
6.2 Evaluation Strategy
Walk-forward validation: the gold standard for time-series strategies.
Roll a fixed-width training window forward; test on the next out-of-sample period.
Monte Carlo permutation tests: shuffle labels and re-evaluate to estimate
the probability that observed performance is due to chance.
Combinatorial purged CV (CPCV): generate many train/test combinations with
purging for more robust performance estimates.
6.3 Feature Scaling
Fit scalers (StandardScaler, MinMaxScaler, RobustScaler) on the training set only.
Apply the same fitted scaler to validation and test sets.
RobustScaler is often preferred for financial data due to heavy tails.
6.4 Handling Missing Data
Forward-fill then backward-fill for price data (be aware of leakage on backfill).
Indicator column for missingness can itself be informative.
Tree-based models can handle NaN natively; linear models cannot.
7. Workflow
For any feature engineering task, follow this sequence:
Restate the task in measurable terms (metric, constraints, deadline).