stefan-jansen/machine-learning-for-trading
Code for Machine Learning for Trading, 3rd edition — from data sourcing to live execution.
📚 What is this?
Machine Learning for Trading, 3rd Edition is a companion code repository for Stefan Jansen’s textbook. It contains a complete, end‑to‑end pipeline that takes raw market data, turns it into features, trains a variety of models, back‑tests the resulting signals, and finally shows how to ship a strategy to a live broker (IB, Alpaca, QuantConnect). The repo is organized chapter‑by‑chapter so you can follow the book and run the same nine case studies on different asset classes.
🚀 Core ideas & workflow
- Data layer – Uses Polars for fast, expression‑based data manipulation; supports daily, intraday, and alternative data (SEC filings, on‑chain crypto, macro). Synthetic data generators (TimeGAN, Tail‑GAN, diffusion) are also provided.
- Evidence boundary – A strict split between model‑tuning (research) and out‑of‑sample evaluation (confirmation). Walk‑forward cross‑validation, multiple‑testing corrections, and statistical tools such as the Deflated Sharpe Ratio, Rademacher Anti‑Serum, and White’s Reality Check are built‑in.
- Model toolkit – From classic linear models to gradient‑boosting (XGBoost, LightGBM, CatBoost) and deep time‑series nets (PatchTST, iTransformer, TSMixer, TCN, Mamba). Tabular‑specific nets (TabPFN, TabM) and causal methods (Double‑ML, Bayesian structural time series) are also included.
- Strategy construction – Portfolio optimisation (mean‑variance, HRP, Kelly), transaction‑cost modelling, risk‑management (VaR, CVaR, deep hedging), and a final synthesis step that ties predictions to a cost‑aware, risk‑aware portfolio.
- Production & MLOps – Dockerised reproducible environments, feature stores, experiment tracking, drift detection, circuit‑breakers, and live‑trading adapters for Interactive Brokers, Alpaca, and QuantConnect.
- Advanced AI – Retrieval‑augmented generation (RAG) over SEC filings, knowledge‑graph pipelines, and autonomous multi‑agent research systems built with LangGraph/Claude SDK.
📂 Repository layout (high‑level)
case_studies/– Nine end‑to‑end pipelines (ETFs, crypto perpetuals, NASDAQ‑100 microstructure, options, FX, futures, etc.).01_process_is_edge/…27_systematic_edge/– One folder per book chapter, each containing a short guide and the notebooks that implement the chapter’s concepts.docs/– Quick‑start, installation, and usage guides.docker/– Docker‑Compose files that pull a ready‑to‑run image with all dependencies (PyTorch, LightGBM, Optuna, Plotly, etc.).assets/– Book cover and workflow diagrams.
🛠️ Getting started (as per the README)
- Clone the repo and copy the example env file.
- Choose Docker (pull
ml4timage) or a localuvenvironment. - Follow the three‑step “What this repo is, Installation, Running notebooks” guide in
docs/. - Pick a case‑study folder and run the provided notebooks to see the full pipeline in action.
🎓 Who might benefit?
- Quant researchers who want a reproducible, production‑ready code base that mirrors a textbook workflow.
- Data scientists looking to practice time‑series, tabular, and causal ML on real financial data.
- Engineers interested in MLOps for low‑latency trading systems (feature stores, drift detection, safe roll‑outs).
- Students of quantitative finance who need a hands‑on complement to the book’s theory.
📚 Related resources mentioned
- The second‑edition branch (
second-edition) contains the previous stable version. - Live courses & workshops on Maven (foundations, research‑to‑production, AI agents, etc.).
- Weekly Insights newsletter for ongoing updates.
All details above are taken directly from the repository’s README; no additional features have been inferred.
Related
- Project
- Project
- Project
- Project
- Project