# stefan-jansen/machine-learning-for-trading architecture

> Architecture diagram of the GitHub repository stefan-jansen/machine-learning-for-trading, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/stefan-jansen/machine-learning-for-trading
- Repository: https://github.com/stefan-jansen/machine-learning-for-trading

## Overview

This repository is the code companion to *Machine Learning for Trading, 3rd Edition*: a broad set of chapter examples and nine case studies organized around taking a trading idea from data and research through evaluation, strategy design, and deployment. The graph emphasizes that documented workflow while retaining major capabilities such as causal methods, generative AI, reinforcement learning, and live-trading governance. Several connections come from the README or SOURCE INDEX; unsampled modules are represented only at supported paths, and their internal wiring is not inferred.

Main entry points: [`case_studies/cme_futures/research_workflow.py`](https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/case_studies/cme_futures/research_workflow.py) (Case-study workflows), [`17_portfolio_construction`](https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/17_portfolio_construction) (Portfolio construction), [`case_studies/utils/backtest_runner.py`](https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/case_studies/utils/backtest_runner.py) (Backtest runner), [`24_autonomous_agents/agent_schemas.py`](https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/24_autonomous_agents/agent_schemas.py) (Agent schemas)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data infrastructure"]
  node_data_loaders["Market data loaders<br/>[__init__.py]"]
  node_data_pipeline["Data preparation"]
  node_data_quality["Data quality"]
  node_market_microstructure["Market microstructure"]
  node_alternative_data["Alternative data"]
end

subgraph group_research["Research and evidence"]
  node_case_workflows["Case-study workflows"]
  node_learning_task["Learning task"]
  node_feature_engineering["Feature engineering"]
  node_case_strategy["Research strategy<br/>[strategy.py]"]
end

subgraph group_models["Models and methods"]
  node_modeling["Modeling utilities<br/>[modeling.py]"]
  node_model_families["Model families"]
  node_deep_models["Deep time-series models"]
  node_causal_methods["Causal methods"]
  node_synthetic_data["Synthetic data"]
end

subgraph group_strategy["Strategy design"]
  node_deepm_features["DeepM features<br/>[features.py]"]
  node_portfolio_construction["Portfolio construction"]
  node_costs_and_risk["Costs and risk"]
  node_backtest_runner["Backtest runner<br/>[backtest_runner.py]"]
  node_analytics["Case analytics<br/>[analytics.py]"]
end

subgraph group_production["Deployment and operations"]
  node_live_trading["Live trading"]
  node_mlops["MLOps governance"]
  node_paths["Artifact paths<br/>[paths.py]"]
  node_reproducibility["Reproducibility<br/>[reproducibility.py]"]
end

subgraph group_ai["AI research systems"]
  node_agent_pipeline["Agent pipeline<br/>[agent_pipeline.py]"]
  node_agent_providers["Agent providers<br/>[agent_providers.py]"]
  node_agent_schemas["Agent schemas<br/>[agent_schemas.py]"]
  node_agent_tools["Agent tools<br/>[agent_tools.py]"]
  node_rag_research["Financial RAG"]
  node_knowledge_graphs["Knowledge graphs"]
end

node_researcher(("Researcher"))

node_researcher -->|"sources data"| node_data_loaders
node_data_loaders -->|"prepares data"| node_data_pipeline
node_data_pipeline -->|"supports research"| node_case_workflows
node_case_workflows -->|"defines task"| node_learning_task
node_learning_task -->|"builds features"| node_feature_engineering
node_feature_engineering -->|"enables modeling"| node_modeling
node_modeling -->|"evaluates strategy"| node_backtest_runner
node_backtest_runner -->|"informs design"| node_portfolio_construction
node_portfolio_construction -->|"adds constraints"| node_costs_and_risk
node_costs_and_risk -->|"deploys strategy"| node_live_trading
node_live_trading -->|"monitors operation"| node_mlops
node_mlops -->|"feeds retraining"| node_case_workflows
node_case_workflows -->|"uses strategy"| node_case_strategy
node_case_workflows -->|"uses runner"| node_backtest_runner
node_case_workflows -->|"uses analytics"| node_analytics
node_deepm_features -.->|"supports allocation"| node_portfolio_construction
node_agent_pipeline -->|"uses schemas"| node_agent_schemas
node_agent_providers -->|"uses schemas"| node_agent_schemas
node_agent_tools -->|"uses schemas"| node_agent_schemas
node_rag_research -.->|"related capability"| node_knowledge_graphs

click node_data_loaders "https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/data/__init__.py"
click node_data_pipeline "https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/02_financial_data_universe/17_complete_pipeline.py"
click node_data_quality "https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/02_financial_data_universe/13_data_quality_framework.py"
click node_market_microstructure "https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/03_market_microstructure"
click node_alternative_data "https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/04_fundamental_alternative_data"
click node_case_workflows "https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/case_studies/cme_futures/research_workflow.py"
click node_learning_task "https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/07_defining_the_learning_task"
click node_feature_engineering "https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/case_studies/utils/feature_engineering.py"
click node_case_strategy "https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/case_studies/research/strategy.py"
click node_modeling "https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/utils/modeling.py"
click node_model_families "https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/12_gradient_boosting"
click node_deep_models "https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/13_dl_time_series"
click node_causal_methods "https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/15_causal_estimation"
click node_synthetic_data "https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/05_synthetic_data"
click node_deepm_features "https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/17_portfolio_construction/deepm/features.py"
click node_portfolio_construction "https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/17_portfolio_construction"
click node_costs_and_risk "https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/18_transaction_costs"
click node_backtest_runner "https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/case_studies/utils/backtest_runner.py"
click node_analytics "https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/case_studies/utils/analytics.py"
click node_agent_pipeline "https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/24_autonomous_agents/agent_pipeline.py"
click node_agent_providers "https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/24_autonomous_agents/agent_providers.py"
click node_agent_schemas "https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/24_autonomous_agents/agent_schemas.py"
click node_agent_tools "https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/24_autonomous_agents/agent_tools.py"
click node_rag_research "https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/22_rag_financial_research"
click node_knowledge_graphs "https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/23_knowledge_graphs"
click node_live_trading "https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/25_live_trading"
click node_mlops "https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/26_mlops_governance"
click node_paths "https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/utils/paths.py"
click node_reproducibility "https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/utils/reproducibility.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_data_loaders,node_data_pipeline,node_data_quality,node_market_microstructure,node_alternative_data toneBlue
class node_case_workflows,node_learning_task,node_feature_engineering,node_case_strategy toneAmber
class node_modeling,node_model_families,node_deep_models,node_causal_methods,node_synthetic_data toneMint
class node_deepm_features,node_portfolio_construction,node_costs_and_risk,node_backtest_runner,node_analytics toneRose
class node_live_trading,node_mlops,node_paths,node_reproducibility,node_researcher toneIndigo
class node_agent_pipeline,node_agent_providers,node_agent_schemas,node_agent_tools,node_rag_research,node_knowledge_graphs toneTeal
```

## Components

### Data infrastructure

- [Market data loaders](https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/data/__init__.py): `data/__init__.py`
- [Data preparation](https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/02_financial_data_universe/17_complete_pipeline.py): `02_financial_data_universe/17_complete_pipeline.py`
- [Data quality](https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/02_financial_data_universe/13_data_quality_framework.py): `02_financial_data_universe/13_data_quality_framework.py`
- [Market microstructure](https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/03_market_microstructure): `03_market_microstructure`
- [Alternative data](https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/04_fundamental_alternative_data): `04_fundamental_alternative_data`

### Research and evidence

- [Case-study workflows](https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/case_studies/cme_futures/research_workflow.py): `case_studies/cme_futures/research_workflow.py`
- [Learning task](https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/07_defining_the_learning_task): `07_defining_the_learning_task`
- [Feature engineering](https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/case_studies/utils/feature_engineering.py): `case_studies/utils/feature_engineering.py`
- [Research strategy](https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/case_studies/research/strategy.py): `case_studies/research/strategy.py`

### Models and methods

- [Modeling utilities](https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/utils/modeling.py): `utils/modeling.py`
- [Model families](https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/12_gradient_boosting): `12_gradient_boosting`
- [Deep time-series models](https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/13_dl_time_series): `13_dl_time_series`
- [Causal methods](https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/15_causal_estimation): `15_causal_estimation`
- [Synthetic data](https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/05_synthetic_data): `05_synthetic_data`

### Strategy design

- [DeepM features](https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/17_portfolio_construction/deepm/features.py): `17_portfolio_construction/deepm/features.py`
- [Portfolio construction](https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/17_portfolio_construction): `17_portfolio_construction`
- [Costs and risk](https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/18_transaction_costs): `18_transaction_costs`
- [Backtest runner](https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/case_studies/utils/backtest_runner.py): `case_studies/utils/backtest_runner.py`
- [Case analytics](https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/case_studies/utils/analytics.py): `case_studies/utils/analytics.py`

### Deployment and operations

- [Live trading](https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/25_live_trading): `25_live_trading`
- [MLOps governance](https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/26_mlops_governance): `26_mlops_governance`
- [Artifact paths](https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/utils/paths.py): `utils/paths.py`
- [Reproducibility](https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/utils/reproducibility.py): `utils/reproducibility.py`

### AI research systems

- [Agent pipeline](https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/24_autonomous_agents/agent_pipeline.py): `24_autonomous_agents/agent_pipeline.py`
- [Agent providers](https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/24_autonomous_agents/agent_providers.py): `24_autonomous_agents/agent_providers.py`
- [Agent schemas](https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/24_autonomous_agents/agent_schemas.py): `24_autonomous_agents/agent_schemas.py`
- [Agent tools](https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/24_autonomous_agents/agent_tools.py): `24_autonomous_agents/agent_tools.py`
- [Financial RAG](https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/22_rag_financial_research): `22_rag_financial_research`
- [Knowledge graphs](https://github.com/stefan-jansen/machine-learning-for-trading/tree/main/23_knowledge_graphs): `23_knowledge_graphs`

### Other components

- **Researcher**

## Connections

- Researcher → Market data loaders: sources data (evidence: `README.md`)
- Market data loaders → Data preparation: prepares data (evidence: `README.md`)
- Data preparation → Case-study workflows: supports research (evidence: `README.md`)
- Case-study workflows → Learning task: defines task (evidence: `README.md`)
- Learning task → Feature engineering: builds features (evidence: `README.md`)
- Feature engineering → Modeling utilities: enables modeling (evidence: `README.md`)
- Modeling utilities → Backtest runner: evaluates strategy (evidence: `README.md`)
- Backtest runner → Portfolio construction: informs design (evidence: `README.md`)
- Portfolio construction → Costs and risk: adds constraints (evidence: `README.md`)
- Costs and risk → Live trading: deploys strategy (evidence: `README.md`)
- Live trading → MLOps governance: monitors operation (evidence: `README.md`)
- MLOps governance → Case-study workflows: feeds retraining (evidence: `README.md`)
- Case-study workflows → Research strategy: uses strategy (evidence: `case_studies/cme_futures/research_workflow.py`)
- Case-study workflows → Backtest runner: uses runner (evidence: `case_studies/cme_futures/research_workflow.py`)
- Case-study workflows → Case analytics: uses analytics (evidence: `case_studies/cme_futures/research_workflow.py`)
- DeepM features → Portfolio construction: supports allocation (evidence: `17_portfolio_construction/deepm/features.py`)
- Agent pipeline → Agent schemas: uses schemas (evidence: `24_autonomous_agents/agent_pipeline.py`)
- Agent providers → Agent schemas: uses schemas (evidence: `24_autonomous_agents/agent_providers.py`)
- Agent tools → Agent schemas: uses schemas (evidence: `24_autonomous_agents/agent_tools.py`)
- Financial RAG → Knowledge graphs: related capability
