About this project
This repository hosts the code accompanying Machine Learning for Trading, 3rd Edition by Stefan Jansen. It is organized around a single end-to-end workflow: defining a research idea and iteratively developing it into a strategy that can be run and maintained in a live market. The material spans 27 chapters and nine case studies, moving from raw data through features, models, backtests, transaction costs and risk to deployment and monitoring.
What the third edition adds, as described in the README:
- A broader model toolkit, including gradient boosting (XGBoost, LightGBM, CatBoost), deep time-series architectures (PatchTST, iTransformer, TSMixer, TCN, Mamba), and tabular or latent-factor models such as TabPFN, TabM, and conditional/supervised autoencoders.
- Dedicated chapters on transaction costs and risk management, alongside portfolio construction and strategy synthesis.
- A production track covering live trading systems (Interactive Brokers, Alpaca, QuantConnect), MLOps and governance topics such as drift detection, safe rollout, circuit breakers, feature stores, and experiment tracking.
- Generative AI material: retrieval-augmented generation grounded in SEC filings, knowledge graphs and Graph RAG, and multi-agent research systems.
- Causal machine learning (Double ML, Bayesian structural time series, causal discovery), reinforcement learning for execution, market making and hedging, and synthetic financial data generators (TimeGAN, Tail-GAN, Sig-CWGAN, diffusion-based methods).
The README emphasizes methodological rigor: an explicit evidence boundary between exploration and confirmation, walk-forward cross-validation, and tools for multiple-testing and overfitting control such as the Deflated Sharpe Ratio, the Rademacher Anti-Serum, White's Reality Check, and conformal prediction. The data layer uses Polars, and chapters are described as shipping in reproducible Docker environments, with PyTorch, LightGBM, Optuna, and Plotly in the modeling and visualization stack.
Nine case studies run through the book, each carried through the same pipeline: ETFs (daily, cross-asset momentum and mean reversion), crypto perpetuals (8-hourly, funding-rate arbitrage), NASDAQ-100 (15-minute intraday microstructure), S&P 500 equity plus options (daily), US firm characteristics (monthly), FX pairs (daily carry and momentum), CME futures (daily term structure and roll yield), S&P 500 options (daily), and a broad US equities panel (daily factor exposures).
The notebooks are built on six companion Python libraries, one per workflow stage: ml4t-data for market-data acquisition from multiple providers, ml4t-engineer for features, labels, alternative bars and leakage-safe dataset preparation, ml4t-models for finance-native latent factors and portfolio learning, ml4t-diagnostic for feature validation, strategy diagnostics and the Deflated Sharpe Ratio, ml4t-backtest for event-driven backtesting, and ml4t-live for production trading with broker integrations. The README states each is documented and usable on its own.
A companion website is referenced for 112 free primers, 61 agent skills for coding agents, and the six libraries. The README also lists paid courses, workshops, and free live sessions, plus an installation guide covering Linux, Windows WSL2, macOS, Docker, and GPU setups. Quick-start instructions offer either a Docker Compose environment or a local uv environment; the local path compiles several dependencies and is noted to require a C/C++ compiler and roughly 16 GB of disk. Platform guidance recommends Docker on Intel macOS and the local environment on Apple Silicon, with reasons given for each.
This is educational and research-oriented code for quantitative finance and machine learning, not a packaged trading product; the README explicitly points readers to a document describing what the repository is and is not, including what requires real compute or licensed data.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.