Model or dataset
stefan-jansen/machine-learning-for-trading avatar
stefan-jansen/machine-learning-for-trading

Machine Learning for Trading, 3rd Edition: A Code Repository Built Around One End-to-End Workflow

Code for Machine Learning for Trading, 3rd edition, from data sourcing to live execution.

20,908 stars5,615 forksJupyter NotebookMIT

At a glance

What is it?
Stefan Jansen's third-edition repository for Machine Learning for Trading is a ground-up rebuild that organizes nine case studies around a single pipeline, from data sourcing to live execution. This review assesses its structure, the new generative AI and causal ML content, and where the repository's ambitions outrun its documentation.
Who is it for?
Adopt this repository if you are a quant researcher or developer who wants a coherent, end-to-end workflow for ML-driven trading strategies, especially if you value methodological rigor like walk-forward validation and the evidence boundary. Do not adopt it if you need a plug-and-play trading system or if you expect the code to run without reading the book, since the repository is a companion to the text and many details live in the 27 chapters.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository received new commits within the last day.
What is it written in?
Mainly Jupyter Notebook, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 15, 2026, and from our analysis. They are not legal advice.

DEEP OPEN-SOURCE ANALYSIS

What This Repository Actually Solves

The repository addresses a specific pain: quant research code is usually a patchwork of notebooks and scripts that never cohere into a deployable strategy. Jansen's third edition rebuilds the code around one process, from raw data to features, models, backtests, costs, risk, and deployment. It is for engineers and researchers who want to see how a single disciplined pipeline can be applied across different asset classes, not for traders looking for ready-made signals. The README is explicit that the nine case studies run the same pipeline through ETFs, crypto perpetuals, intraday equities, options, FX, futures, and equity factor panels. That breadth is the point: it shows where the process works and where it breaks. The repository does not promise a universal strategy; it promises a repeatable method.

The Evidence Boundary and Walk-Forward Validation

A central design choice is the 'evidence boundary,' a conceptual line that separates exploration from confirmation. The README says the book draws this line explicitly and uses walk-forward cross-validation throughout. In practice, this means the repository's code likely separates model tuning from evaluation, so you do not accidentally tune on your test set. The material also confronts multiple-testing and overfitting with tools like the Deflated Sharpe Ratio, the Rademacher Anti-Serum, and White's Reality Check. These are not standard in most quant repos, and their inclusion signals that the author treats methodological rigor as a first-class feature. For an engineer, this means the codebase is not just about fitting models; it is about validating that a signal is real and not a statistical fluke. The trade-off is that this rigor adds complexity, and you must understand these concepts to use the repository effectively.

How the Pipeline Is Organized: Data, Features, Models, Deployment

The repository's architecture is visible in the case study folders and the companion website. Each case study follows the same stages: raw data, labels, features, models, backtests, costs, risk overlays, and a final deployment assessment. The data layer moves to Polars, a fast expression-based DataFrame library, which is a shift from pandas-heavy approaches. The README lists PyTorch, LightGBM, Optuna, and Plotly as the modeling and visualization stack. The workflow includes a feedback loop that retrains, pauses, or retires a strategy as its edge decays, which is a realistic operational concern. The production track covers live trading systems for Interactive Brokers, Alpaca, and QuantConnect, plus MLOps topics like drift detection, safe rollout, circuit breakers, and feature stores. This is not a toy backtesting library; it is a full lifecycle framework, but the code's actual data flow is not documented in the README beyond these high-level stages.

Getting It Running: Installation and Docker

The README points to docs/installation.md as the starting point, claiming it walks a blank Linux, Windows, or macOS machine to a running notebook, prerequisites included. The Quick Start section is meant to be the short version. The repository ships reproducible Docker environments for every chapter, which is a strong commitment to cross-machine repeatability. The v3.0.0-artifacts release provides pre-computed case study artifacts for v3.0, which could save time if you want to inspect results without running long computations. However, the README does not include any actual commands, so you must open the installation doc to see how to pull Docker images or set up a conda environment. The reliance on Docker means you need a working Docker installation, and for GPU-heavy models like deep time-series architectures, you will need to configure GPU passthrough, which the README does not detail.

What's New: Generative AI, Causal ML, and Synthetic Data

The third edition adds substantial new material that is not in typical quant repos. Generative AI includes retrieval-augmented generation grounded in SEC filings, knowledge graphs, and Graph RAG, plus autonomous multi-agent research systems. Causal machine learning covers Double ML, Bayesian structural time series, and causal discovery. There is also reinforcement learning for optimal execution, market making with inventory, and deep hedging. Synthetic financial data generation uses TimeGAN, Tail-GAN, Sig-CWGAN, and diffusion-based generators. These are advanced topics, and the repository's code for them is likely experimental. The risk is that these cutting-edge sections may be less mature than the core pipeline, and the README does not indicate which parts are stable. For an engineer, this means you should treat the generative AI and RL code as research prototypes, not production-ready modules.

Limitations and Where It Is the Wrong Tool

The repository is a companion to a book, not a standalone library. The README references 27 chapters, 112 primers, and 61 agent skills on the companion website, which suggests that much of the explanatory context lives outside the code. If you expect to clone the repo and run a strategy without reading the book, you will struggle. The case studies cover specific asset classes and frequencies, so if your market is not listed, you will need to adapt the pipeline yourself. The README does not provide data download commands, and for some asset classes like options or FX, sourcing data can be expensive or restricted. The evidence boundary is a conceptual tool, not a code feature, so implementing it correctly requires understanding the methodology. Also, the repository is large; nine case studies plus production code means a significant disk and compute footprint. For a quick proof of concept, a simpler library like backtrader or zipline might be more appropriate.

Alternatives: How This Differs from Other Quant Repos

A common alternative is a library like QuantLib or a backtesting framework such as Backtrader, which focus on specific components like pricing or order simulation. This repository is different because it is a full workflow with a methodological stance. It does not just give you tools; it gives you a process that includes validation and deployment. Another alternative is the QuantConnect Lean engine, which is an open-source backtesting and live trading platform. Lean provides a unified API and a cloud service, but it does not come with the educational narrative or the evidence boundary framework. In contrast, Jansen's repo is tightly coupled to the book and the case studies, so you get a guided path through the entire lifecycle. The trade-off is that Lean is a more polished, standalone product, while this repository is a teaching artifact that requires more setup and conceptual investment. For a team that wants to learn and apply a rigorous process, this repo is stronger; for a team that wants to deploy a strategy quickly, Lean might be faster.

Maintenance, Licensing, and Upgrade Cost

The repository is licensed under MIT, which is permissive for commercial use, but that does not mean the code is legally risk-free for trading; you must do your own due diligence. The last push was July 2026, and there are alpha releases plus a v3.0.0-artifacts release, indicating active development. The upgrade cost is real: if you used the second edition, the third is a ground-up rebuild, so your old code will not port over. The move to Polars means you must learn a new data manipulation API if you are used to pandas. The Docker environments reduce environment drift but add a layer of abstraction. The companion website offers 112 primers and 61 agent skills, which are presumably free but require time to consume. There is no explicit changelog in the README, so you must rely on release notes or the book to understand what changed between alpha versions. For a production team, this means budgeting time for migration and learning, not just a simple pip install.

Editorial conclusion

Adopt this repository if you are a quant researcher or developer who wants a coherent, end-to-end workflow for ML-driven trading strategies, especially if you value methodological rigor like walk-forward validation and the evidence boundary. Do not adopt it if you need a plug-and-play trading system or if you expect the code to run without reading the book, since the repository is a companion to the text and many details live in the 27 chapters. Before committing, verify that your hardware can run Docker environments and that you can source the data for the case studies you care about, as the README does not list data download commands. Also check that the v3.0.0-artifacts release matches your desired case study, since pre-computed artifacts are only for v3.0.

Official sources

  1. Official documentation
  2. Official README
  3. Project repository
  4. Release notes
Community notes

Community notes