stefan-jansen/machine-learning-for-trading
Code for Machine Learning for Trading, 3rd edition — from data sourcing to live execution.
What it solves
This project addresses the complexity of moving from a financial research idea to a live, production-ready trading strategy. It provides a disciplined framework to navigate the "evidence boundary" between model tuning and evaluation, helping practitioners avoid common pitfalls like overfitting, lookahead bias, and data leakage.
How it works
The repository follows a comprehensive workflow organized into five parts:
- Data Infrastructure: Managing market, fundamental, and alternative data, including synthetic data generation.
- Research & Feature Engineering: Defining learning tasks and transforming raw data into signals using techniques like fractional differencing and transformer-based embeddings.
- Model Development: Implementing a wide toolkit ranging from gradient boosting (XGBoost, LightGBM) to deep time-series architectures (PatchTST, Mamba) and causal machine learning.
- Strategy Implementation: Simulating strategies via event-driven backtesting, managing transaction costs, and constructing risk-aware portfolios.
- Advanced AI: Integrating reinforcement learning for execution, RAG for financial research, and multi-agent systems.
Who it’s for
It is designed for quantitative researchers, machine learning engineers, and algorithmic traders who need a rigorous, reproducible process for developing and deploying financial models in real markets.
Highlights
- Nine comprehensive case studies covering ETFs, crypto, equities, options, FX, and futures.
- Six production-oriented Python libraries for data acquisition, feature engineering, modeling, diagnostics, backtesting, and live deployment.
- Advanced AI integration featuring RAG grounded in SEC filings and autonomous multi-agent research systems.
- Methodological rigor including tools for multiple-testing control (Deflated Sharpe Ratio) and conformal prediction for uncertainty estimation.