# edtechre/pybroker architecture

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

- Interactive diagram: https://gitdiagram.com/edtechre/pybroker
- Repository: https://github.com/edtechre/pybroker

## Overview

PyBroker is a Python algorithmic-trading framework. A user configures a Strategy with a data source, symbols, and trading rules or models; Strategy loads historical bars, prepares indicators and model predictions, invokes execution callbacks through a per-bar context, and records simulated orders and portfolio results. Walkforward analysis and parameter optimization extend that workflow, while evaluation, caching, parallel execution, and multi-interval data support it. Relationships below rely on README statements and SOURCE INDEX references; unsampled implementation details are not inferred.

Main entry points: [`src/pybroker/strategy.py`](https://github.com/edtechre/pybroker/blob/master/src/pybroker/strategy.py) (Strategy engine), [`src/pybroker/indicator.py`](https://github.com/edtechre/pybroker/blob/master/src/pybroker/indicator.py) (Indicators), [`src/pybroker/model.py`](https://github.com/edtechre/pybroker/blob/master/src/pybroker/model.py) (Model training), [`src/pybroker/data.py`](https://github.com/edtechre/pybroker/blob/master/src/pybroker/data.py) (Historical data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_market_data["Market data"]
  node_data["Historical data<br/>[data.py]"]
  node_providers["Provider adapters<br/>[data.py]"]
  node_interval["Interval compression<br/>[interval.py]"]
end

subgraph group_strategy_runtime["Strategy runtime"]
  node_strategy["Strategy engine<br/>[strategy.py]"]
  node_indicator["Indicators<br/>[indicator.py]"]
  node_vector["Vectorized functions<br/>[vect.py]"]
  node_model["Model training<br/>[model.py]"]
  node_context["Execution context<br/>[context.py]"]
  node_portfolio["Orders and portfolio<br/>[portfolio.py]"]
  node_slippage["Slippage models<br/>[slippage.py]"]
end

subgraph group_analysis_tools["Analysis and tuning"]
  node_evaluation["Performance evaluation<br/>[eval.py]"]
  node_optimization["Parameter optimization<br/>[optimize.py]"]
  node_agent_skills["AI agent skills"]
end

subgraph group_runtime_support["Runtime support"]
  node_scope["Runtime data scopes<br/>[scope.py]"]
  node_cache[("Data and model cache<br/>[cache.py]")]
  node_parallel["Parallel execution<br/>[parallel.py]"]
  node_config["Strategy configuration<br/>[config.py]"]
  node_common["Shared data types<br/>[common.py]"]
end

node_trader(("Strategy author"))

node_trader -->|"configures"| node_strategy
node_strategy -->|"loads bars"| node_data
node_providers -->|"provides data"| node_data
node_strategy -->|"prepares intervals"| node_interval
node_strategy -->|"computes indicators"| node_indicator
node_indicator -->|"uses functions"| node_vector
node_strategy -->|"trains models"| node_model
node_strategy -->|"invokes callbacks"| node_context
node_context -->|"accesses positions"| node_portfolio
node_strategy -->|"simulates orders"| node_portfolio
node_strategy -->|"adjusts fills"| node_slippage
node_strategy -->|"evaluates results"| node_evaluation
node_strategy -->|"optimizes parameters"| node_optimization
node_strategy -->|"uses runtime scopes"| node_scope
node_data -->|"caches data"| node_cache
node_indicator -->|"caches indicators"| node_cache
node_model -->|"caches models"| node_cache
node_indicator -->|"dispatches work"| node_parallel
node_model -->|"dispatches work"| node_parallel
node_strategy -->|"uses settings"| node_config
node_strategy -->|"uses shared types"| node_common
node_trader -->|"gets guidance"| node_agent_skills

click node_strategy "https://github.com/edtechre/pybroker/blob/master/src/pybroker/strategy.py"
click node_data "https://github.com/edtechre/pybroker/blob/master/src/pybroker/data.py"
click node_providers "https://github.com/edtechre/pybroker/blob/master/src/pybroker/ext/data.py"
click node_interval "https://github.com/edtechre/pybroker/blob/master/src/pybroker/interval.py"
click node_indicator "https://github.com/edtechre/pybroker/blob/master/src/pybroker/indicator.py"
click node_vector "https://github.com/edtechre/pybroker/blob/master/src/pybroker/vect.py"
click node_model "https://github.com/edtechre/pybroker/blob/master/src/pybroker/model.py"
click node_context "https://github.com/edtechre/pybroker/blob/master/src/pybroker/context.py"
click node_portfolio "https://github.com/edtechre/pybroker/blob/master/src/pybroker/portfolio.py"
click node_slippage "https://github.com/edtechre/pybroker/blob/master/src/pybroker/slippage.py"
click node_evaluation "https://github.com/edtechre/pybroker/blob/master/src/pybroker/eval.py"
click node_optimization "https://github.com/edtechre/pybroker/blob/master/src/pybroker/optimize.py"
click node_scope "https://github.com/edtechre/pybroker/blob/master/src/pybroker/scope.py"
click node_cache "https://github.com/edtechre/pybroker/blob/master/src/pybroker/cache.py"
click node_parallel "https://github.com/edtechre/pybroker/blob/master/src/pybroker/parallel.py"
click node_config "https://github.com/edtechre/pybroker/blob/master/src/pybroker/config.py"
click node_common "https://github.com/edtechre/pybroker/blob/master/src/pybroker/common.py"
click node_agent_skills "https://github.com/edtechre/pybroker/tree/master/skills"

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,node_providers,node_interval toneBlue
class node_strategy,node_indicator,node_vector,node_model,node_context,node_portfolio,node_slippage toneAmber
class node_evaluation,node_optimization,node_agent_skills toneMint
class node_scope,node_cache,node_parallel,node_config,node_common toneRose
class node_trader toneIndigo
```

## Components

### Market data

- [Historical data](https://github.com/edtechre/pybroker/blob/master/src/pybroker/data.py): `src/pybroker/data.py`
- [Provider adapters](https://github.com/edtechre/pybroker/blob/master/src/pybroker/ext/data.py): `src/pybroker/ext/data.py`
- [Interval compression](https://github.com/edtechre/pybroker/blob/master/src/pybroker/interval.py): `src/pybroker/interval.py`

### Strategy runtime

- [Strategy engine](https://github.com/edtechre/pybroker/blob/master/src/pybroker/strategy.py): `src/pybroker/strategy.py`
- [Indicators](https://github.com/edtechre/pybroker/blob/master/src/pybroker/indicator.py): `src/pybroker/indicator.py`
- [Vectorized functions](https://github.com/edtechre/pybroker/blob/master/src/pybroker/vect.py): `src/pybroker/vect.py`
- [Model training](https://github.com/edtechre/pybroker/blob/master/src/pybroker/model.py): `src/pybroker/model.py`
- [Execution context](https://github.com/edtechre/pybroker/blob/master/src/pybroker/context.py): `src/pybroker/context.py`
- [Orders and portfolio](https://github.com/edtechre/pybroker/blob/master/src/pybroker/portfolio.py): `src/pybroker/portfolio.py`
- [Slippage models](https://github.com/edtechre/pybroker/blob/master/src/pybroker/slippage.py): `src/pybroker/slippage.py`

### Analysis and tuning

- [Performance evaluation](https://github.com/edtechre/pybroker/blob/master/src/pybroker/eval.py): `src/pybroker/eval.py`
- [Parameter optimization](https://github.com/edtechre/pybroker/blob/master/src/pybroker/optimize.py): `src/pybroker/optimize.py`
- [AI agent skills](https://github.com/edtechre/pybroker/tree/master/skills): `skills`

### Runtime support

- [Runtime data scopes](https://github.com/edtechre/pybroker/blob/master/src/pybroker/scope.py): `src/pybroker/scope.py`
- [Data and model cache](https://github.com/edtechre/pybroker/blob/master/src/pybroker/cache.py): `src/pybroker/cache.py`
- [Parallel execution](https://github.com/edtechre/pybroker/blob/master/src/pybroker/parallel.py): `src/pybroker/parallel.py`
- [Strategy configuration](https://github.com/edtechre/pybroker/blob/master/src/pybroker/config.py): `src/pybroker/config.py`
- [Shared data types](https://github.com/edtechre/pybroker/blob/master/src/pybroker/common.py): `src/pybroker/common.py`

### Other components

- **Strategy author**

## Connections

- Strategy author → Strategy engine: configures (evidence: `README.md`)
- Strategy engine → Historical data: loads bars (evidence: `src/pybroker/strategy.py`)
- Provider adapters → Historical data: provides data (evidence: `src/pybroker/ext/data.py`)
- Strategy engine → Interval compression: prepares intervals (evidence: `src/pybroker/strategy.py`)
- Strategy engine → Indicators: computes indicators (evidence: `src/pybroker/strategy.py`)
- Indicators → Vectorized functions: uses functions (evidence: `src/pybroker/indicator.py`)
- Strategy engine → Model training: trains models (evidence: `src/pybroker/strategy.py`)
- Strategy engine → Execution context: invokes callbacks (evidence: `src/pybroker/strategy.py`)
- Execution context → Orders and portfolio: accesses positions (evidence: `src/pybroker/context.py`)
- Strategy engine → Orders and portfolio: simulates orders (evidence: `src/pybroker/strategy.py`)
- Strategy engine → Slippage models: adjusts fills (evidence: `src/pybroker/strategy.py`)
- Strategy engine → Performance evaluation: evaluates results (evidence: `src/pybroker/strategy.py`)
- Strategy engine → Parameter optimization: optimizes parameters (evidence: `src/pybroker/strategy.py`)
- Strategy engine → Runtime data scopes: uses runtime scopes (evidence: `src/pybroker/strategy.py`)
- Historical data → Data and model cache: caches data (evidence: `src/pybroker/data.py`)
- Indicators → Data and model cache: caches indicators (evidence: `src/pybroker/indicator.py`)
- Model training → Data and model cache: caches models (evidence: `src/pybroker/model.py`)
- Indicators → Parallel execution: dispatches work (evidence: `src/pybroker/indicator.py`)
- Model training → Parallel execution: dispatches work (evidence: `src/pybroker/model.py`)
- Strategy engine → Strategy configuration: uses settings (evidence: `src/pybroker/strategy.py`)
- Strategy engine → Shared data types: uses shared types (evidence: `src/pybroker/strategy.py`)
- Strategy author → AI agent skills: gets guidance (evidence: `README.md`)
