Skip to content

Guide · Open source

How to use machine-learning-for-trading: clone, run notebooks, learn the workflow

Updated · written with AI from the project's own documentation and checked against our catalogue data

machine-learning-for-trading is the open-source code repository for the third edition of Stefan Jansen's book Machine Learning for Trading. It covers one end-to-end workflow: sourcing market data, researching strategy ideas, evaluating them with backtests, and deploying them to live markets. This guide shows you how to get the code, what you need installed, and how to start running the book's examples. By the end you will have cloned the repository and know where to begin with its chapters and case studies.

Machine Learning for Tradingstefan-jansen/machine-learning-for-trading · ★ 21.7k · MIT

Quick start

  1. 1Install Git and Python. Install Git and a Python version of your choice, checking the repository for the version it expects. The README does not state the version in the excerpt.
  2. 2Install Jupyter Notebook. Install Jupyter Notebook so you can open and run the repository's notebook files.
  3. 3Clone the repository. Run git clone https://github.com/stefan-jansen/machine-learning-for-trading to create a local copy.
  4. 4Read the Quick start. Open the Quick start section of the README for the data download and first-notebook steps.
  5. 5Pick a chapter or case study. Choose a chapter guide to learn one technique, or a case study to see the full pipeline on a single market.
  6. 6Run and check the results. Run the notebooks, then test the backtest results against the methodology the book describes before drawing conclusions.

What you need before you start

The README lists three prerequisites: Git, Python, and Jupyter Notebook. It does not state a specific Python version in the excerpt, so check the repository's own files for that before installing.

The material assumes working knowledge of Python and finance, so this repo suits developers and readers comfortable with notebooks more than complete beginners.

  • Git, to clone the repository
  • Python (version not stated in the README excerpt)
  • Jupyter Notebook, since the code is in Jupyter Notebook files

Get the code by cloning the repository

Clone the repository with Git using the command from the README. This creates a local copy of the code for all 27 chapters and the nine case studies.

git clone https://github.com/stefan-jansen/machine-learning-for-trading

Find your way around the chapters and case studies

The code is organised chapter by chapter, with 27 chapter guides, and the nine case studies run the same pipeline across different markets: ETFs, crypto perpetuals, intraday equities, options, FX, futures, and equity factor panels. The README notes that each case study carries one process from raw data and labels to features, models, backtests, costs, risk overlays, and a final deployment assessment.

If you want to see the whole process first, read the case study that matches an asset class you care about, then go back to the chapters that explain each stage.

  • Start with a chapter guide to learn one technique at a time
  • Use a case study to see the full pipeline on one market
  • The README's Repository layout section describes where folders sit

Download the data and run your first notebook

The README's Quick start section covers installing, downloading the data, and running your first notebook. The excerpt provided here is truncated before those exact steps, so follow the Quick start section in the full README for the data download and notebook commands rather than relying on this guide for them.

Use the second-edition branch if you have that book

The README says the second edition is complete and stable on a separate branch named second-edition. If you are working from the second book, switch to that branch so the code matches its text.

git checkout second-edition

Understand what the code does and does not prove

The repository presents code for learning and research, not a tested investment product. The book puts weight on methodology, including walk-forward cross-validation and checks against overfitting such as the Deflated Sharpe Ratio. Treat backtest results as evidence to examine, not as proof that a strategy will make money in live markets.

  • Do not read the examples as ready-made trading signals
  • Review the evidence boundary between tuning and evaluation before trusting a result

What people use it for

  • Working through the book's chapters while running the matching code
  • Studying applied machine learning on financial time series
  • Comparing how one pipeline behaves across ETFs, FX, futures, or options in the case studies
  • Reviewing a worked example of an end-to-end strategy workflow from data to deployment

Frequently asked questions

Is machine-learning-for-trading free to use?

The repository is released under the MIT licence, as stated in the README metadata. Check the LICENSE file in the repo for the full terms before reuse.

What do I need installed to run machine-learning-for-trading?

You need Git to clone the repository, Python, and Jupyter Notebook. The README excerpt does not state a required Python version, so check the repo's documentation.

How do I install machine-learning-for-trading?

Clone it with git clone https://github.com/stefan-jansen/machine-learning-for-trading, then follow the Quick start section of the README to set up and run the notebooks.

Can I use this repo for a profitable trading strategy?

The README presents the code for learning and research, not a tested investment product. It is not a ready-made profitable strategy.

Is this code for the second edition too?

The third edition is the main branch. The second edition is complete and stable on the second-edition branch, which you can check out with git checkout second-edition.

What are the alternatives to machine-learning-for-trading?

Projects listed as comparable include FinRL, Qlib, Zipline, and backtrader. These cover related areas such as reinforcement learning, quantitative research, and backtesting.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Use this repository if you own or are reading the third edition of Machine Learning for Trading and want to run its code, or if you are a Python developer learning applied machine learning on financial data. Pick a different project if you want a ready-made trading strategy, or if you are new to Python or finance, since the material assumes both.

Install options & downloads