docs: make Chinese README the default

This commit is contained in:
wehub-resource-sync
2026-07-13 10:38:17 +00:00
parent 910278a2f7
commit 1979d8ffcf
+146 -251
View File
@@ -1,361 +1,263 @@
# Machine Learning for Trading — 3rd Edition
<!-- WEHUB_ZH_README -->
> [!NOTE]
> 本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。
> [English](./README.en.md) · [原始项目](https://github.com/stefan-jansen/machine-learning-for-trading) · [上游 README](https://github.com/stefan-jansen/machine-learning-for-trading/blob/HEAD/README.md)
> 原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。
**Build, test, and deploy ML-driven trading strategies — from data sourcing to live execution.**
# Machine Learning for Trading — 第三版
This repository hosts the code for [*Machine Learning for Trading, 3rd Edition*](https://amzn.to/4eigy2F)
by [Stefan Jansen](https://www.linkedin.com/in/applied-ai/) — 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](https://www.ml4trading.io/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](https://ml4trading.io) features [112 primers](https://ml4trading.io/primer/),
[56 agent skills](https://ml4trading.io/skills/),
and [six production Python libraries](https://ml4trading.io/libraries/)
that facilitate substantial parts of the workflow.
本仓库托管 [*Machine Learning for Trading, 3rd Edition*](https://amzn.to/4eigy2F) 一书的代码,作者为 [Stefan Jansen](https://www.linkedin.com/in/applied-ai/) ——这是一次从零开始的重构,围绕一条端到端工作流组织:如何将研究构想定义出来,并通过迭代开发成一套能在真实市场中实际运行、并持续运行的策略。
- [九个案例研究](https://www.ml4trading.io/case-studies/) 贯穿全书 27 章展示该工作流,涵盖从原始数据、特征、模型、回测、成本与风险到部署的完整路径。
- 本版新增的 **生成式 AIGenerative AI****自主智能体(autonomous agents** 贯穿该工作流,将检索增强生成(retrieval-augmented generation)、知识图谱与多智能体系统引入金融研究。
- [配套网站](https://ml4trading.io) 提供 [112 篇入门讲解](https://ml4trading.io/primer/), [56 项 agent 技能](https://ml4trading.io/skills/), 以及 [六个可用于生产的 Python 库](https://ml4trading.io/libraries/),可支撑工作流中的多个重要环节。
<p align="center">
<a href="https://amzn.to/4eigy2F"><img src="assets/cover.png" width="45%" alt="Machine Learning for Trading, 3rd Edition"></a>
<a href="https://amzn.to/4eigy2F"><img src="assets/cover.png" width="45%" alt="Machine Learning for Trading, 第三版"></a>
</p>
## 🎓 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](https://maven.com/stefan-jansen) — full schedule on the
[courses page](https://ml4trading.io/courses/).
第三版首次配套 **直播同期班课程**、动手 **工作坊** 以及由 Stefan 在 [Maven](https://maven.com/stefan-jansen) 平台开设的免费 **闪电课** ——完整课表见 [课程页面](https://ml4trading.io/courses/).
- **▶ [Machine Learning for Trading: From Research to Production](https://maven.com/stefan-jansen/research-to-production)**
— the flagship live cohort course: take a research idea all the way to a deployed, monitored strategy, working
through the book's end-to-end workflow with direct feedback. **The first cohort starts Monday, July 6, 2026 —
enrollment closes Friday, July 3.**
- **[Getting Stuff Done with Coding Agents](https://maven.com/p/8394ac/getting-stuff-done-with-coding-agents?utm_medium=ll_share_link&utm_source=instructor)**
— a free lightning lesson on putting coding agents to work.
- **[Building Multi-Agent Forecasting Systems](https://maven.com/stefan-jansen/forecasting-agents)**
— a hands-on workshop on engineering the forecasting-agent loop: building auditable, debate-driven multi-agent
systems for financial research.
- **▶ [Machine Learning for Trading: From Research to Production](https://maven.com/stefan-jansen/research-to-production)** ——旗舰直播同期班课程:将研究构想一路推进到已部署、可监控的策略,在直接反馈下走完书中的端到端工作流。**首期班于 2026 年 7 月 6 日(周一)开课——报名于 7 月 3 日(周五)截止。**
- **[Getting Stuff Done with Coding Agents](https://maven.com/p/8394ac/getting-stuff-done-with-coding-agents?utm_medium=ll_share_link&utm_source=instructor)** ——一节关于如何让 coding agents 投入实战的免费闪电课。
- **[Building Multi-Agent Forecasting Systems](https://maven.com/stefan-jansen/forecasting-agents)** ——动手工作坊,讲授如何工程化预测智能体循环:为金融研究构建可审计、辩论驱动的多智能体系统。
<p align="center">
<a href="https://youtu.be/Ksxv9QVZSOo"><img src="assets/course-trailer.jpg" width="60%" alt="Watch the course overview: Machine Learning for Trading — From Research to Production"></a>
<a href="https://youtu.be/Ksxv9QVZSOo"><img src="assets/course-trailer.jpg" width="60%" alt="观看课程概览:Machine Learning for Trading — From Research to Production"></a>
</p>
---
## 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.
全书遵循一条统一路径:从数据基础设施与策略研究出发,跨越将调优与评估分开的 *证据边界(evidence boundary*,直至部署与监控——并辅以反馈循环,在策略优势衰减时进行再训练、暂停或退役。
<p align="center">
<img src="assets/workflow.png" width="90%" alt="The ML4T workflow: data infrastructure and strategy research, an evidence boundary separating tuning from evaluation, and deployment with a retrain/pause/retire feedback loop">
<img src="assets/workflow.png" width="90%" alt="ML4T 工作流:数据基础设施与策略研究、将调优与评估分开的证据边界,以及带有再训练/暂停/退役反馈循环的部署">
</p>
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 production track**: live trading systems (Interactive Brokers, Alpaca, QuantConnect), MLOps and governance
(drift detection, safe rollout, circuit breakers, feature stores, experiment tracking), and the operational reality
of *running* strategies, not just building them.
- **Generative AI**: retrieval-augmented generation grounded in SEC filings, knowledge graphs and Graph RAG, and
autonomous, multi-agent research systems.
- **Causal machine learning**: Double ML, Bayesian structural time series, and causal discovery for separating real
effects from spurious correlation.
- **Reinforcement learning**: optimal execution, market making with inventory, and deep hedging.
- **Synthetic financial data**: TimeGAN, Tail-GAN, Sig-CWGAN, and diffusion-based generators for validation when
history is short.
- **更丰富的模型工具箱**:从梯度提升(XGBoostLightGBMCatBoost)到深度时间序列架构(PatchTST、iTransformer、TSMixer、TCN、Mamba),再到较新的表格与潜因子模型(TabPFN、TabM、条件自编码器与监督自编码器)。
- **专门的策略设计章节**:交易成本与风险管理现为完整章节(此前均未单独成章),并与组合构建、策略综合衔接,使原始信号一路贯通至经规模调整、成本与风险感知的组合。
- **完整的生产化路径**:实盘交易系统(Interactive Brokers、Alpaca、QuantConnect)、MLOps 与治理(漂移检测、安全发布、熔断机制、特征存储、实验跟踪),以及*运行*策略(而非仅构建策略)的运维现实。
- **生成式 AI**:基于 SEC 申报文件的检索增强生成、知识图谱与 Graph RAG,以及自主多智能体研究系统。
- **因果机器学习(Causal machine learning**Double ML、贝叶斯结构时间序列(Bayesian structural time series)与因果发现,用于区分真实效应与虚假相关。
- **强化学习(Reinforcement learning**:最优执行、带库存的做市,以及深度对冲。
- **合成金融数据**TimeGAN、Tail-GAN、Sig-CWGAN 以及基于扩散的生成器,用于在历史数据较短时进行验证。
Methodological rigor is treated as a first-class topic rather than an afterthought. The book draws an explicit line
between exploration and confirmation — the *evidence boundary* — uses walk-forward cross-validation throughout, and
confronts the multiple-testing and overfitting problems that quietly invalidate most backtests, with tools like the
Deflated Sharpe Ratio, the Rademacher Anti-Serum, and White's Reality Check, plus conformal prediction for honest
uncertainty estimates.
方法论严谨性被作为一等公民主题,而非事后补充。本书明确区分探索与确认——即 *证据边界*——全书采用滚动前向交叉验证(walk-forward cross-validation),并直面悄然使大多数回测失效的多重检验与过拟合问题,借助 Deflated Sharpe Ratio、Rademacher Anti-Serum、White's Reality Check 等工具,以及保形预测(conformal prediction)以获得诚实的 uncertainty 估计。
The data layer moves to **Polars** for fast, expression-based manipulation, and every chapter ships in **reproducible
Docker environments** so results repeat across machines; PyTorch, LightGBM, Optuna, and Plotly round out the modeling
and visualization stack.
数据层迁移至 **Polars**,以实现快速的基于表达式的数据处理;每章均提供 **可复现的 Docker 环境**,确保结果在不同机器上可重复;PyTorch、LightGBM、Optuna 与 Plotly 共同构成建模与可视化技术栈。
### Nine Case Studies
### 九个案例研究
The structural centerpiece of the third edition is **nine case studies** that run the length of the
book. ETFs, crypto
perpetuals, intraday equities, options, FX, futures, and equity factor panels are each carried through the *same*
pipeline — from raw data and labels to features, models, backtests, costs, risk overlays, and a final deployment
assessment. One disciplined process applied to nine very different markets shows where it works, where it breaks, and
why.
第三版的结构核心是 **九个案例研究**,贯穿全书。ETF、加密货币永续合约、日内股票、期权、外汇、期货与股票因子面板均经由*同一*流水线——从原始数据与标签到特征、模型、回测、成本、风险叠加,直至最终部署评估。将一套严谨流程应用于九个截然不同的市场,可展示其适用之处、失效之处及原因。
| Case Study | Asset Class | Frequency | What It Explores |
| 案例研究 | 资产类别 | 频率 | 探索内容 |
|--------------------------|--------------------|-----------|------------------------------------------------------------------------------|
| ETFs | Multi-asset ETFs | Daily | Cross-asset momentum and mean-reversion across 100 ETFs |
| Crypto Perps | Crypto | 8-hourly | Funding-rate arbitrage on perpetual futures |
| NASDAQ-100 | Equities | 15-min | Intraday microstructure signals from order flow and the LOB |
| S&P 500 Equity + Options | Equities + Options | Daily | Equity selection enhanced with implied-volatility features |
| US Firm Characteristics | Equities | Monthly | Firm-level characteristics panel (size, value, momentum, quality) |
| FX Pairs | FX | Daily | Carry and momentum across major currency pairs |
| CME Futures | Futures | Daily | Term-structure and roll-yield signals across commodity and financial futures |
| S&P 500 Options | Options | Daily | Options-only strategies (straddles, delta-hedged positions) |
| US Equities | Equities | Daily | Broad cross-section of US stocks with classic factor exposures |
| ETFs | 多资产 ETF | 日频 | 100 ETF 的跨资产动量与均值回归 |
| Crypto Perps | 加密货币 | 8 小时 | 永续期货的资金费率套利 |
| NASDAQ-100 | 股票 | 15 分钟 | 来自订单流与 LOB 的日内微观结构信号 |
| S&P 500 Equity + Options | 股票 + 期权 | 日频 | 以隐含波动率特征增强的股票筛选 |
| US Firm Characteristics | 股票 | 月频 | 公司层面特征面板(规模、价值、动量、质量) |
| FX Pairs | 外汇 | 日频 | 主要货币对的 carry 与动量 |
| CME Futures | 期货 | 日频 | 商品与金融期货的期限结构与 roll-yield 信号 |
| S&P 500 Options | 期权 | 日频 | 纯期权策略(跨式、delta 对冲头寸) |
| US Equities | 股票 | 日频 | 美国股票广截面及经典因子暴露 |
### 112 Primer Topics
### 112 个入门主题
Free concept explainers for every idea the book relies on. Each part links to its full list; a few topics show the
range:
为书中所依赖的每个概念提供免费讲解。各部分均链接至完整列表;以下若干主题展示其覆盖范围:
- [Foundations](https://ml4trading.io/primer/): 8 topics spanning limit order book mechanics, bitemporal data models,
and the stylized facts a simulator must reproduce.
- [Research Design and Feature Engineering](https://ml4trading.io/primer/): 21 topics, including multiple testing in
factor research, fractional differencing, and path signatures for financial sequences.
- [Model Development](https://ml4trading.io/primer/): 22 topics, among them regularization geometry, conformal
prediction in finance, and the mechanism behind double machine learning.
- [Strategy Implementation](https://ml4trading.io/primer/): 27 topics, from the deflated Sharpe ratio and hierarchical
risk parity to Almgren-Chriss optimal execution.
- [Advanced AI](https://ml4trading.io/primer/): 8 topics such as Markov decision processes, the policy-gradient theorem,
and proper scoring rules for event forecasts.
- [Production](https://ml4trading.io/primer/): 2 topics, champion-challenger evaluation and training-serving skew with
feature stores.
- [Cross-cutting concepts](https://ml4trading.io/primer/): 20 building blocks referenced across chapters, for example
momentum and mean reversion, the bias-variance tradeoff, and walk-forward validation.
- [基础](https://ml4trading.io/primer/): 8 个主题,涵盖限价订单簿机制、双时态数据模型,以及模拟器必须复现的 stylized facts。
- [研究设计与特征工程](https://ml4trading.io/primer/): 21 个主题,包括因子研究中的多重检验、分数差分,以及金融序列的路径签名(path signatures)。
- [模型开发](https://ml4trading.io/primer/): 22 个主题,其中有正则化几何、金融中的保形预测,以及双重机器学习(double machine learning)的机制。
- [策略实现](https://ml4trading.io/primer/): 27 个主题,从 deflated Sharpe ratio 与层次风险平价(hierarchical risk parity),到 Almgren-Chriss 最优执行。
- [高级 AI](https://ml4trading.io/primer/): 8 个主题,如马尔可夫决策过程(Markov decision processes)、策略梯度定理(policy-gradient theorem),以及事件预测的正确评分规则(proper scoring rules)。
- [生产化](https://ml4trading.io/primer/): 2 个主题:冠军-挑战者评估(champion-challenger evaluation),以及特征存储带来的训练-服务偏移(training-serving skew)。
- [跨章节概念](https://ml4trading.io/primer/): 20 个在各章中引用的构建模块,例如动量与均值回归、偏差-方差权衡(bias-variance tradeoff),以及滚动前向验证(walk-forward validation)。
### 56 Agent Skills
Reusable, guard-railed tasks for coding agents, each with built-in defenses against lookahead bias, data leakage, and
multiple-testing errors. Each category links to its full set; a few skills show the range:
面向编码智能体的可复用、带护栏的任务,每项均内置针对前瞻偏差(lookahead bias)、数据泄露(data leakage)和多重检验错误的防护。每个类别链接到其完整技能集;以下列举部分技能以展示范围:
- [Concepts](https://ml4trading.io/skills/): 10 skills, including lookahead bias, data leakage, and the information
coefficient.
- [Data Acquisition](https://ml4trading.io/skills/): 7 skills spanning fetching data, building bars, and data
validation.
- [Feature Engineering](https://ml4trading.io/skills/): 10 skills, among them computing features, triple-barrier labels,
and feature selection.
- [Evaluation & Validation](https://ml4trading.io/skills/): 8 skills, from walk-forward CV and purging-and-embargo to
the deflated Sharpe ratio.
- [Backtesting](https://ml4trading.io/skills/): 5 skills such as running backtests, cost models, and tear sheets.
- [Portfolio Management](https://ml4trading.io/skills/): 5 skills, including position sizing, risk metrics, and kill
switches.
- [Infrastructure](https://ml4trading.io/skills/): 4 skills, for example the canonical schema, the registry system, and
Polars patterns.
- [Workflows](https://ml4trading.io/skills/): 5 skills covering factor research, model validation, and production
readiness.
- [Production](https://ml4trading.io/skills/): 2 skills, live trading and monitoring & alerting.
- [Concepts](https://ml4trading.io/skills/): 10 项技能,涵盖前瞻偏差、数据泄露和信息系数(information coefficient)。
- [Data Acquisition](https://ml4trading.io/skills/): 7 项技能,涵盖数据获取、构建 bars 与数据验证。
- [Feature Engineering](https://ml4trading.io/skills/): 10 项技能,包括特征计算、三重障碍标签(triple-barrier labels)和特征选择。
- [Evaluation & Validation](https://ml4trading.io/skills/): 8 项技能,从步进式交叉验证(walk-forward CV)与清除-禁运(purging-and-embargo)到收缩夏普比率(Deflated Sharpe ratio)。
- [Backtesting](https://ml4trading.io/skills/): 5 项技能,例如运行回测、成本模型和 tear sheets。
- [Portfolio Management](https://ml4trading.io/skills/): 5 项技能,包括仓位管理、风险指标和熔断开关(kill switches)。
- [Infrastructure](https://ml4trading.io/skills/): 4 项技能,例如规范 schema、注册表系统和 Polars 模式。
- [Workflows](https://ml4trading.io/skills/): 5 项技能,涵盖因子研究、模型验证和生产就绪。
- [Production](https://ml4trading.io/skills/): 2 项技能:实盘交易与监控与告警。
---
## The ML4T Libraries
The notebooks are built on six production Python packages, each documented and usable on its own — one per stage of
the workflow:
这些 notebook 基于六个生产级 Python 包构建,每个包均有独立文档且可单独使用——对应工作流的每个阶段:
| Library | Stage | What it does |
|-------------------------------------------------------------|------------|--------------------------------------------------------------------------------|
| [`ml4t-data`](https://ml4trading.io/docs/data/) | Data | Unified market-data acquisition from 19+ providers behind one interface |
| [`ml4t-engineer`](https://ml4trading.io/docs/engineer/) | Signal | Features, labels, alternative bars, and leakage-safe dataset preparation |
| [`ml4t-models`](https://ml4trading.io/docs/models/) | Models | Finance-native latent factors, SDFs, direct prediction, and portfolio learning |
| [`ml4t-diagnostic`](https://ml4trading.io/docs/diagnostic/) | Evaluation | Feature validation, strategy diagnostics, and the Deflated Sharpe Ratio |
| [`ml4t-backtest`](https://ml4trading.io/docs/backtest/) | Strategy | Event-driven backtesting with realistic execution |
| [`ml4t-live`](https://ml4trading.io/docs/live/) | Deployment | Production trading with broker integrations |
| [`ml4t-data`](https://ml4trading.io/docs/data/) | Data | 通过统一接口从 19+ 家数据提供商获取市场数据 |
| [`ml4t-engineer`](https://ml4trading.io/docs/engineer/) | Signal | 特征、标签、替代 bars,以及防泄露的数据集准备 |
| [`ml4t-models`](https://ml4trading.io/docs/models/) | Models | 面向金融的潜因子、SDF、直接预测与组合学习 |
| [`ml4t-diagnostic`](https://ml4trading.io/docs/diagnostic/) | Evaluation | 特征验证、策略诊断与收缩夏普比率(Deflated Sharpe Ratio |
| [`ml4t-backtest`](https://ml4trading.io/docs/backtest/) | Strategy | 具备真实istic 执行的事件驱动回测 |
| [`ml4t-live`](https://ml4trading.io/docs/live/) | Deployment | 对接券商的生产级交易 |
---
An introduction and a closing chapter bookend six workflow-aligned parts. Chapter titles link to their guides as
each part is published; the rest are added part by part over the coming weeks.
导言与收尾章节为六个与工作流对齐的部分作书脊。各章标题链接到对应指南,随各部分陆续发布;其余章节将在未来数周内逐部分添加。
## Introduction
### [1. The Process Is Your Edge](01_process_is_edge/)
Why process discipline beats model sophistication. Introduces the ML4T workflow as a research-to-production system,
regime detection on factor returns and macro indicators, and the evidence boundary that separates exploration from
confirmation.
为何流程纪律胜过模型复杂度。将 ML4T 工作流介绍为从研究到生产的系统,涵盖因子收益与宏观指标上的制度识别(regime detection),以及区分探索与确认的 evidence boundary。
## Part I — Financial Data (Chapters 25)
The markets, instruments, and infrastructure the rest of the book builds on: a taxonomy of sources, raw exchange
messages turned into feature-ready bars, point-in-time fundamentals, and synthetic histories for robust validation.
全书其余部分所依托的市场、工具与基础设施:数据源分类体系、将原始交易所消息转化为可用于特征的 bars、时点(point-in-time)基本面,以及用于稳健验证的合成历史数据。
### [2. The Financial Data Universe](02_financial_data_universe/)
A taxonomy of market, fundamental, and alternative data. Surveys eight asset classes, quantifies survivorship bias,
benchmarks storage formats (Parquet, DuckDB, kdb+, TimescaleDB), and establishes the data-quality framework used
throughout the book.
市场、基本面与另类数据的分类体系。调研八类资产,量化幸存者偏差(survivorship bias),对比存储格式(Parquet、DuckDB、kdb+、TimescaleDB),并建立全书沿用的数据质量框架。
### [3. Market Microstructure](03_market_microstructure/)
From raw exchange messages to feature-ready bars. Parses NASDAQ ITCH, reconstructs limit order books from multiple
data sources, validates Lee-Ready trade classification, and compares bar-sampling methods — dollar bars deliver the
best return normality.
从原始交易所消息到可用于特征的 bars。解析 NASDAQ ITCH,从多数据源重建限价订单簿,验证 Lee-Ready 成交分类,并比较 bar 采样方法——dollar bars 带来最佳的收益正态性。
### [4. Fundamental and Alternative Data](04_fundamental_alternative_data/)
Point-in-time pipelines for SEC EDGAR filings, entity resolution across identifier systems, macro and commodity
fundamentals, and alternative-data evaluation — including on-chain crypto fundamentals and prediction markets
(Kalshi, Polymarket).
面向 SEC EDGAR 申报文件的时点(point-in-time)流水线、跨标识符体系的实体解析、宏观与大宗商品基本面,以及另类数据评估——包括链上加密基本面与预测市场(Kalshi、Polymarket)。
### [5. Synthetic Financial Data](05_synthetic_data/)
Generating alternative market histories for robust validation. Implements TimeGAN, Tail-GAN, Sig-CWGAN,
Diffusion-TS, and LLM-based tabular generation, evaluated through a fidelityutilityprivacy framework.
生成替代市场历史以进行稳健验证。实现 TimeGANTail-GANSig-CWGAN、Diffusion-TS 与基于 LLM 的表格生成,并通过保真度–效用–隐私框架进行评估。
## Part II — Research Design and Feature Engineering (Chapters 610)
Define the trading problem, then turn data into model-ready signals: research design, labels, features, and the
evaluation that determines what any model can learn.
先定义交易问题,再将数据转化为可供模型使用的信号:研究设计、标签、特征,以及决定任何模型能学到什么的评估。
### [6. Strategy Research Framework](06_strategy_definition/)
Defining the trading game before building models: universe rules, decision schedule, cost model, evaluation
protocol, and run logging. Introduces the nine case studies and the walk-forward cross-validation discipline that
anchors Chapters 720.
在建模之前定义交易博弈:标的池规则、决策日程、成本模型、评估协议与运行日志。介绍九个案例研究,以及贯穿第 7–20 章的步进式交叉验证(walk-forward cross-validation)纪律。
### [7. Defining the Learning Task](07_defining_the_learning_task/)
Label engineering (forward returns, triple-barrier, trend scanning), univariate feature evaluation (information
coefficients, quantile analysis, feasibility screens), multiple-testing control (BH-FDR, Deflated Sharpe Ratio),
and causal plausibility checks.
标签工程(前瞻收益、三重障碍、trend scanning)、单变量特征评估(信息系数、分位数分析、可行性筛选)、多重检验控制(BH-FDR、Deflated Sharpe Ratio)与因果合理性检验。
### [8. Financial Feature Engineering](08_financial_features/)
Five feature families from price data (momentum, reversal, volatility, liquidity, microstructure), structural and
cross-instrument features (yield curve, term structure, relative value), contextual features (macro regime, calendar,
sentiment), and feature selection with robustness testing.
来自价格数据的五类特征族(动量、反转、波动率、流动性、微观结构),结构与跨工具特征(收益率曲线、期限结构、相对价值),情境特征(宏观制度、日历、情绪),以及带稳健性检验的特征选择。
### [9. Model-Based Feature Extraction](09_model_based_features/)
Features from fitted models: stationarity diagnostics, Kalman filters, Fourier and wavelet spectral features, GARCH
volatility, and HMM regime probabilities — with point-in-time correctness enforced throughout.
来自拟合模型的特征:平稳性诊断、Kalman 滤波器、傅里叶与小波谱特征、GARCH 波动率与 HMM 制度概率——全程强制时点(point-in-time)正确性。
### [10. Text Feature Engineering](10_text_feature_engineering/)
From bag-of-words through transformers: TF-IDF, Word2Vec and GloVe embeddings, LSTM sequence models, FinBERT
sentiment, financial NER fine-tuning, and news-return signal construction.
从词袋到 TransformerTF-IDFWord2Vec GloVe 嵌入、LSTM 序列模型、FinBERT 情绪、金融 NER 微调,以及新闻–收益信号构建。
## Part III — Model Development (Chapters 1115)
Five model families applied to the same nine case studies, each building on the linear baseline.
五类模型族应用于相同的九个案例研究,均以线性基线为起点。
### 11. The ML Pipeline
Regularized linear models (Ridge, LASSO, Elastic Net) as the baseline every later model must beat. Logistic
regression for direction, SHAP interpretability, conformal prediction for uncertainty, and a cross-dataset
comparison across all nine case studies.
正则化线性模型(RidgeLASSOElastic Net)作为后续所有模型必须超越的基线。用于方向的逻辑回归、SHAP 可解释性、用于不确定性的共形预测(conformal prediction),以及跨九个案例研究的数据集对比。
### 12. Gradient Boosting and Advanced Tabular Models
XGBoost, LightGBM, and CatBoost with Optuna multi-objective tuning, plus deep-learning tabular alternatives (TabPFN,
TabM). TreeSHAP explainability and cross-dataset results, where gradient boosting is the strongest tabular model in
most case studies.
XGBoostLightGBM CatBoost,配合 Optuna 多目标调参,以及深度学习表格替代方案(TabPFN、TabM)。TreeSHAP 可解释性与跨数据集结果;在多数案例研究中,梯度提升是最强的表格模型。
### 13. Deep Learning for Time Series
LSTM, N-BEATS, Transformers (PatchTST, iTransformer, TFT), TSMixer, TCN, and Mamba, set against the LTSF-Linear
debate. A practitioner selection framework and cross-dataset evidence on when deep learning helps and when simpler
models suffice.
LSTMN-BEATSTransformerPatchTSTiTransformerTFT)、TSMixerTCN Mamba,置于 LTSF-Linear 争论背景下。实践者选型框架与跨数据集证据,说明深度学习何时有帮助、何时更简单的模型已足够。
### 14. Latent Factor Models
PCA eigenportfolios, IPCA with time-varying loadings, conditional and supervised autoencoders, adversarial SDF
estimation, and yield-curve decomposition — with cross-dataset results on when latent factors add predictive value.
PCA 特征组合、带时变载荷的 IPCA、条件与监督自编码器、对抗式 SDF 估计与收益率曲线分解——附跨数据集结果,说明潜因子何时增加预测价值。
### 15. Causal Machine Learning
Double Machine Learning for isolating factor treatment effects, Bayesian Structural Time Series for event impact, and
causal discovery (PCMCI, NOTEARS, VAR-LiNGAM), applied across the nine case studies.
双重机器学习(Double Machine Learning)用于隔离因子处理效应,贝叶斯结构时间序列(Bayesian Structural Time Series)用于事件影响,以及因果发现(PCMCI、NOTEARS、VAR-LiNGAM),应用于九个案例研究。
## Part IV — Strategy Implementation (Chapters 1620)
## 第四部分 — 策略实施(第 1620 章)
From predictions to deployable strategies — backtesting, portfolio construction, costs, risk, and synthesis.
从预测到可部署策略 — 回测、组合构建、成本、风险与综合。
### 16. Strategy Simulation
### 16. 策略模拟
Backtesting as falsification: trading-protocol specification, vectorized vs event-driven engines, an ETF baseline
strategy, core metric reporting, regime diagnostics, and strategy-level overfitting control (Deflated Sharpe Ratio,
Rademacher Anti-Serum, White's Reality Check).
将回测视为证伪:交易协议规范、向量化与事件驱动引擎、ETF 基准策略、核心指标报告、市场状态(regime)诊断,以及策略层面的过拟合控制(Deflated Sharpe Ratio、Rademacher Anti-Serum、White's Reality Check)。
### 17. Portfolio Construction
### 17. 组合构建
From scores to portfolios: mean-variance optimization and its pitfalls, Hierarchical Risk Parity, the Kelly
criterion, conformal position sizing, deep portfolio allocation, and a controlled allocator comparison across case
studies.
从得分到组合:均值-方差优化及其陷阱、层次风险平价(Hierarchical Risk Parity)、Kelly 准则、保形(conformal)仓位 sizing、深度组合配置,以及跨案例研究的受控配置器对比。
### 18. Transaction Costs
### 18. 交易成本
Cost taxonomy, spread estimation, market-impact calibration, execution algorithms (VWAP, TWAP, Almgren-Chriss
optimal execution), transaction-cost analysis, and practical guardrails — with breakeven costs that vary widely by
asset class.
成本分类、价差估计、市场冲击校准、执行算法(VWAPTWAPAlmgren-Chriss 最优执行)、交易成本分析,以及实用防护栏 — 盈亏平衡成本因资产类别差异很大。
### 19. Risk Management
### 19. 风险管理
VaR/CVaR tail measurement, drawdown and path-risk controls, factor and sector decomposition, stress testing,
adaptive risk overlays, deep hedging, and kill switches. Overlay effectiveness turns out to be strategy-specific.
VaR/CVaR 尾部度量、回撤与路径风险控制、因子与行业分解、压力测试、自适应风险叠加层、深度对冲(deep hedging)与熔断机制。叠加层的有效性因策略而异。
### 20. Strategy Synthesis
### 20. 策略综合
What nine experiments reveal about translating ML predictions into strategies: ICSharpe decorrelation, Fundamental
Law diagnostics, the model-family cascade, cost-survival analysis, holdout failure modes, and a practitioner's
decision framework.
九项实验揭示的关于将 ML 预测转化为策略的洞见:IC–Sharpe 去相关、基本定律(Fundamental Law)诊断、模型族级联、成本生存分析、留出集(holdout)失效模式,以及面向实践者的决策框架。
## Part V — Advanced AI (Chapters 2124)
## 第五部分 — 高级 AI(第 2124 章)
Reinforcement learning, large language models, knowledge graphs, and autonomous agents for finance.
强化学习、大语言模型、知识图谱,以及面向金融的自主智能体。
### 21. Reinforcement Learning for Execution and Hedging
### 21. 面向执行与对冲的强化学习
MDP formulation for finance, DQN/PPO/SAC algorithms, optimal execution, market making with inventory management, deep
hedging with PFHedge, inverse RL for strategy recovery, and the sim-to-real gap.
金融领域的 MDP 建模、DQN/PPO/SAC 算法、最优执行、带库存管理的市场做市、基于 PFHedge 的深度对冲、用于策略恢复的逆强化学习(inverse RL),以及仿真到现实(sim-to-real)鸿沟。
### 22. RAG for Financial Research
### 22. 面向金融研究的 RAG
Retrieval-augmented generation grounded in SEC filings: ingestion, domain-specific embeddings, hybrid retrieval with
re-ranking, constraint-based prompting, RAG evaluation and failure diagnostics, and the transition to agentic
workflows.
基于 SEC 申报文件的检索增强生成(RAG):摄取、领域专用嵌入、带重排序的混合检索、基于约束的提示、RAG 评估与失效诊断,以及向智能体式工作流的过渡。
### 23. Knowledge Graphs
### 23. 知识图谱
When graphs earn their infrastructure cost: KG construction from SEC filings, Graph RAG for multi-hop reasoning,
graph features for ML (GNN embeddings, centrality, community detection), financial networks, and temporal-leakage
prevention.
图谱何时值得其基础设施成本:从 SEC 申报文件构建知识图谱(KG)、用于多跳推理的 Graph RAG、面向 ML 的图特征(GNN 嵌入、中心性、社区检测)、金融网络,以及时间泄漏(temporal-leakage)防范。
### 24. Autonomous Agents
### 24. 自主智能体
Agent architectures (ReAct, Tree of Thoughts, Reflexion), memory systems, tool contracts, the engineering stack
(LangGraph, Claude SDK), a stateful equity-research agent, multi-agent forecasting with adversarial debate, and
production reliability.
智能体架构(ReActTree of ThoughtsReflexion)、记忆系统、工具契约、工程栈(LangGraph、Claude SDK)、有状态股票研究智能体、带对抗性辩论的多智能体预测,以及生产可靠性。
## Part VI — Production (Chapters 2526)
## 第六部分 — 生产部署(第 2526 章)
Taking strategies live — trading systems and the operational infrastructure that keeps them running.
将策略上线 — 交易系统与保障其运行的运营基础设施。
### 25. Live Trading Systems
### 25. 实盘交易系统
A unified framework bridging research and production: Interactive Brokers and Alpaca integration, managed platforms
(QuantConnect), order-lifecycle management, pipeline verification, and operational readiness.
连接研究与生产的统一框架:Interactive Brokers Alpaca 集成、托管平台(QuantConnect)、订单生命周期管理、流水线验证,以及运营就绪。
### 26. MLOps and Governance
### 26. MLOps 与治理
An ML failure taxonomy (pipeline divergence vs performance decay), drift detection, safe model rollout, circuit
breakers, feature stores, experiment tracking, and the MLOps infrastructure financial ML systems need.
ML 失效分类(流水线漂移 vs 性能衰减)、漂移检测、安全模型发布、熔断器、特征存储、实验跟踪,以及金融 ML 系统所需的 MLOps 基础设施。
## Conclusion
## 结语
### 27. The Systematic Edge
### 27. 系统化优势
The systematic philosophy, quant career paths, learning resources, research frontiers, and how to build your own
edge. The closing bookend to Chapter 1: the process is the edge.
系统化理念、量化职业路径、学习资源、研究前沿,以及如何构建你自己的优势。与第 1 章首尾呼应:流程即优势。
---
## Quick Start
## 快速入门
These commands are typed into a terminal on your own computer, not into GitHub. New to the command
line? Start with **[Before You Begin](docs/installation.md#before-you-begin)**.
以下命令需在你自己电脑的终端中输入,而非在 GitHub 中输入。不熟悉命令行?请从 **[开始之前](docs/installation.md#before-you-begin)** 读起。
Run everything **from the repository root**. Clone and set up with Docker or a local `uv` environment:
**从仓库根目录运行一切。** 克隆并使用 Docker 或本地 `uv` 环境完成设置:
```bash
git clone https://github.com/stefan-jansen/machine-learning-for-trading.git
@@ -366,70 +268,63 @@ docker compose pull ml4t # Option A — Docker (recommended)
pip install uv && uv sync # Option B — local with uv
```
See the **[installation guide](docs/installation.md)** for platform-specific setup (Linux, Windows WSL2, macOS) and GPU
instructions. Windows readers: WSL2 must be working *before* Docker Desktop is installed, and the
reboot is not optional.
平台相关设置(Linux、Windows WSL2、macOS)及 GPU 说明见 **[安装指南](docs/installation.md)**。Windows 读者:必须先让 WSL2 正常工作,*再*安装 Docker Desktop,且重启不可省略。
**Download data.** Most notebooks need datasets; start with the free ones (no API keys):
**下载数据。** 大多数 notebook 需要数据集;先从免费数据集开始(无需 API 密钥):
```bash
uv run python data/download_all.py --free-only
```
The **[data guide](data/README.md)** documents every dataset, API-key setup, the loaders, and storage tiers (≈70 MB
free tier up to ≈7 GB full).
**[数据指南](data/README.md)** 记录了每个数据集、API 密钥配置、加载器及存储层级(约 70 MB 免费层至约 7 GB 完整版)。
**Run notebooks.** Notebooks are paired [Jupytext](https://jupytext.readthedocs.io/) files (`.py` source + generated
`.ipynb`). Run a quick smoke test, or open Jupyter Lab:
**运行 notebook** Notebook [Jupytext](https://jupytext.readthedocs.io/) 文件成对(`.py` 源文件 + 生成的 `.ipynb`)。运行快速冒烟测试,或打开 Jupyter Lab
```bash
uv run python 01_process_is_edge/factor_regimes.py
docker compose up -d ml4t # then open http://localhost:8888
```
See the guide to **[running notebooks](docs/running-notebooks.md)** for Papermill parameters and the experiment
workflow.
Papermill 参数与实验工作流见 **[运行 notebook 指南](docs/running-notebooks.md)**
### Docker images
### Docker 镜像
Most notebooks run on the default **ml4t** image; a few need a specialized one, and each such notebook says so in its
preamble. Full details in the **[Docker environments guide](envs/README.md)**.
大多数 notebook 在默认 **ml4t** 镜像上运行;少数需要专用镜像,各 notebook 会在前言中说明。完整说明见 **[Docker 环境指南](envs/README.md)**。
| Image | Covers | When you need it |
|--------------|------------------------------------------------------------------|-------------------------|
| `ml4t` | All 27 chapters + 9 case studies (CPU) | Default for everything |
| `ml4t-gpu` | Same `ml4t` image, run with the NVIDIA runtime (`--profile gpu`) | Deep-learning chapters |
| `ml4t-py312` | Python 3.12 for signatory, esig, gensim, pfhedge, tfcausalimpact | ~10 notebooks |
| `benchmark` | Database clients (TimescaleDB, ClickHouse, QuestDB, InfluxDB) | Ch02 storage benchmarks |
| `rapids` | RAPIDS cuML + LightGBM CUDA (build locally) | One Ch12 GPU benchmark |
| `ml4t` | 全部 27 章 + 9 个案例研究(CPU | 一切内容的默认选择 |
| `ml4t-gpu` | 同一 `ml4t` 镜像,使用 NVIDIA runtime`--profile gpu`)运行 | 深度学习章节 |
| `ml4t-py312` | Python 3.12,用于 signatoryesiggensimpfhedgetfcausalimpact | 约 10 个 notebook |
| `benchmark` | 数据库客户端(TimescaleDBClickHouseQuestDBInfluxDB | 02 章存储基准测试 |
| `rapids` | RAPIDS cuML + LightGBM CUDA(本地构建) | 第 12 章一项 GPU 基准测试 |
---
## Releases
## 版本发布
New chapters and notebooks are added over the coming weeks. ⭐ Watch or star the repo to follow along, and subscribe to
the twice-weekly [**Insights** newsletter](https://insights.ml4trading.io/).
新章节与 notebook 将在未来数周内陆续添加。⭐ 关注或 star 本仓库以跟进进展,并订阅每两周一期的 [**Insights** 通讯](https://insights.ml4trading.io/).
**Looking for the second edition?** It is complete and stable on the `second-edition` branch
`git checkout second-edition`, and everything is exactly where the book describes it.
**在找第二版?** 它已在 `second-edition` 分支上完整且稳定
`git checkout second-edition`,一切内容与书中描述完全一致。
---
## Contributing and Feedback
## 贡献与反馈
Found an error, a broken link, or have a suggestion? Early feedback is especially valuable before the book launches.
发现错误、失效链接或有建议?在本书正式发布前,早期反馈尤为宝贵。
- **Issues**: [open a GitHub issue](https://github.com/stefan-jansen/machine-learning-for-trading/issues)
- **Website and contact**: [ml4trading.io](https://ml4trading.io)
- **Issues**[提交 GitHub issue](https://github.com/stefan-jansen/machine-learning-for-trading/issues)
- **网站与联系**[ml4trading.io](https://ml4trading.io)
---
## License
## 许可证
Code: [MIT License](LICENSE) · Book content: © 2026 Stefan Jansen. All rights reserved.
代码:[MIT License](LICENSE) · 书籍内容:© 2026 Stefan Jansen. All rights reserved.
<p align="center">
<a href="https://amzn.to/4eigy2F">Get the book</a> •
<a href="https://amzn.to/4eigy2F">获取本书</a> •
<a href="https://ml4trading.io">ml4trading.io</a> •
<a href="https://github.com/stefan-jansen/machine-learning-for-trading">GitHub</a>
</p>