Python toolkit for trading research that backtests thousands of strategy ideas across assets and timeframes using vectorized NumPy and pandas operations.
stefan-jansen/machine-learning-for-trading
Companion code for the book Machine Learning for Trading (3rd edition), covering an end-to-end workflow from data sourcing to live trading.
- Stars
- 21,737
- Forks
- 5,761
- Open issues
- 1
- Last commit
- 21 hours ago
Repolode describes open-source projects and does not give investment advice. Trading and investing can lose money: assess the risk yourself and follow the laws where you live before using this project.
What is it?
This repository contains the code for Machine Learning for Trading, 3rd Edition. It is organized as 27 chapters, each with Jupyter notebooks and a guide, plus nine case studies that run the same pipeline across different markets: ETFs, crypto perpetuals, intraday equities, options, FX, futures, and equity factor panels. The project focuses on turning a research idea into a costed, risk-aware strategy and then into a live trading system with monitoring.
The covered material spans financial data handling with Polars, feature engineering, models from linear baselines and gradient boosting to deep time-series architectures, reinforcement learning for execution and hedging, causal machine learning, and retrieval-augmented generation and agents applied to financial research. Backtesting, transaction-cost modeling, portfolio construction, and overfitting controls such as the Deflated Sharpe Ratio are treated as core topics.
Setup is provided through a Docker image or a local uv environment, with scripts to download the free datasets and verify the installation. Earlier material remains available on the second-edition branch.
Key features
- 01Twenty-seven chapter directories with Jupytext notebooks and guides mapping sections to code
- 02Nine case studies covering ETFs, crypto perpetuals, options, FX, futures, and equities
- 03Gradient boosting, deep time-series, latent factor, and causal models with walk-forward validation
- 04Backtesting, transaction-cost, and risk-management modules tied to a live-trading track
- 05Docker and local uv setups with scripts to download free datasets and verify installation
Use cases
- Learning an end-to-end quantitative research workflow from data to backtest
- Reproducing or extending the nine case-study strategies on your own data
- Comparing classic and deep learning models for return prediction under realistic costs
- Exploring how to move a trading strategy into monitored live execution
In collections
Topics
FAQ
- What is machine-learning-for-trading?
- Companion code for the book Machine Learning for Trading (3rd edition), covering an end-to-end workflow from data sourcing to live trading. This repository contains the code for Machine Learning for Trading, 3rd Edition. It is organized as 27 chapters, each with Jupyter notebooks and a guide, plus nine case studies that run the same pipeline across different markets: ETFs, crypto perpetuals, intraday equities, options, FX, futures, and equity factor panels. The project focuses on turning a research idea into a costed, risk-aware strategy and then into a live trading system with monitoring.
- Is machine-learning-for-trading free to use? What license does it have?
- machine-learning-for-trading is open source under the MIT license. Check the license terms before using it in commercial products.
- Is machine-learning-for-trading still maintained?
- Actively maintained. The last commit to machine-learning-for-trading was on Nov 6, 2026.
- What can I use machine-learning-for-trading for?
- Learning an end-to-end quantitative research workflow from data to backtest Reproducing or extending the nine case-study strategies on your own data Comparing classic and deep learning models for return prediction under realistic costs Exploring how to move a trading strategy into monitored live execution
- Where can I get machine-learning-for-trading?
- The source code and installation instructions are on GitHub: https://github.com/stefan-jansen/machine-learning-for-trading
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
AI-oriented quantitative investment platform from Microsoft covering data, model training, backtesting and order execution for quant research.
Python framework for backtesting and live trading algorithmic strategies on decentralised exchanges, with on-chain market data.
Rust-native, event-driven trading engine with Python control plane for backtesting and live trading across crypto, FX, equities, futures, options and betting venues.
A self-hosted Python framework for researching, backtesting, optimizing and live-trading your own crypto trading strategies.
Python framework for training ML models on historic crypto market data with feature engineering, then running them as an online service that sends trading signals.