stefan-jansen/machine-learning-for-trading

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

What it solves

It provides a comprehensive, end-to-end framework for building, testing, and deploying machine learning-driven trading strategies. The project addresses the gap between theoretical research and live market execution by establishing a disciplined workflow that manages data infrastructure, signal generation, rigorous evaluation (the "evidence boundary"), and production MLOps to prevent common pitfalls like overfitting and lookahead bias.

How it works

The project is organized around a research-to-production pipeline implemented across six specialized Python libraries:

  • Data: Unified acquisition from 19+ providers (ml4t-data).
  • Signal: Feature engineering and leakage-safe dataset preparation (ml4t-engineer).
  • Models: Implementation of finance-native latent factors and portfolio learning (ml4t-models).
  • Evaluation: Strategy diagnostics and feature validation (ml4t-diagnostic).
  • Strategy: Event-driven backtesting with realistic execution (ml4t-backtest).
  • Deployment: Broker integrations for live trading (ml4t-live).

It employs a wide array of techniques, including gradient boosting, deep time-series architectures (e.g., PatchTST, Mamba), Causal ML, Reinforcement Learning for execution, and Generative AI (RAG and multi-agent systems) for financial research.

Who it’s for

Quantitative researchers, algorithmic traders, and ML engineers who want to move from raw financial data to a production-ready trading system using a rigorous, evidence-based methodology.

Highlights

  • End-to-End Workflow: Covers the entire lifecycle from data sourcing and feature engineering to risk management and live deployment.
  • Diverse Model Toolkit: Includes everything from linear baselines and XGBoost to advanced deep learning and Causal ML.
  • Generative AI Integration: Implements RAG grounded in SEC filings, knowledge graphs, and autonomous multi-agent research systems.
  • Rigorous Validation: Uses walk-forward cross-validation and tools like the Deflated Sharpe Ratio to combat overfitting.
  • Nine Case Studies: Applies the same pipeline across various asset classes including ETFs, Crypto, FX, and Equities.

Related

  • Project
  • Project
  • Project
  • Project
  • Project