machine-learning-for-trading

stefan-jansen/machine-learning-for-trading

Code repository for Machine Learning for Trading, focusing on developing and deploying trading strategies using ML techniques.

20k
Stars
5.4k
Forks
1
Open issues
445
Watchers
Jupyter Notebook MITLast pushed Jul 7, 2026

Overview

This repository is associated with the book 'Machine Learning for Trading' (3rd Edition) by Stefan Jansen. It includes code snippets and projects related to algorithmic trading, data science, deep learning, and reinforcement learning in quantitative finance contexts. Additionally, it highlights applications of generative AI and autonomous agents.

Categories

Tags

Similar tools

Install

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

README

Machine Learning for Trading — 3rd Edition

Build, test, and deploy ML-driven trading strategies — from data sourcing to live execution.

This repository hosts the code for Machine Learning for Trading, 3rd Edition by Stefan Jansen — a ground-up rebuild, organized around one end-to-end workflow: how you define a research idea and develop it iteratively into a strategy you can actually run, and keep running, in a live market.

  • Nine case studies illustrate the workflow throughout the 27 chapters of the book, from raw data through features, models, backtests, costs, and risk to deployment.
  • Generative AI and autonomous agents are new to this edition and cut across that workflow, bringing retrieval-augmented generation, knowledge graphs, and multi-agent systems to financial research.
  • The companion website features 112 primers, 56 agent skills, and six production Python libraries that facilitate substantial parts of the workflow.

🎓 New: Live Courses & Lightning Lessons

For the first time, the third edition comes with a live cohort course, hands-on workshops, and free lightning lessons taught by Stefan on Maven — full schedule on the courses page.


What's New in the Third Edition

The whole book traces one path: from data infrastructure and strategy research, across an evidence boundary that separates tuning from evaluation, to deployment and monitoring — with a feedback loop that retrains, pauses, or retires a strategy as its edge decays.

Where earlier editions moved technique by technique, the third edition runs that one process end to end — and adds substantial new material:

  • A wider model toolkit: from gradient boosting (XGBoost, LightGBM, CatBoost) to deep time-series architectures (PatchTST, iTransformer, TSMixer, TCN, Mamba) and newer tabular and latent-factor models (TabPFN, TabM, conditional and supervised autoencoders).
  • Dedicated strategy-design chapters: transaction costs and risk management are now full chapters, neither of which existed before, joining portfolio construction and strategy synthesis so a raw signal is carried through to a sized, cost- and risk-aware portfolio.
  • **A full produc