# akfamily/akquant architecture

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

- Interactive diagram: https://gitdiagram.com/akfamily/akquant
- Repository: https://github.com/akfamily/akquant

## Overview

AKQuant is a hybrid Rust/Python quantitative research and trading framework. Its principal workflow is to prepare market data, run a Python strategy through the backtest interface and Rust engine, apply risk and execution rules, then inspect results and reports. The repository also exposes live trading and broker integrations, streaming events, complex orders, walk-forward ML, factor expressions, TA-Lib indicators, and parameter optimization. The README documents user-facing capabilities; sampled source and the SOURCE INDEX support selected internal relationships, so uncertain runtime wiring is omitted.

Main entry points: [`src/engine/core.rs`](https://github.com/akfamily/akquant/blob/main/src/engine/core.rs) (Rust Engine), [`python/akquant/backtest/engine.py`](https://github.com/akfamily/akquant/blob/main/python/akquant/backtest/engine.py) (Backtest Runner), [`src/risk/manager.rs`](https://github.com/akfamily/akquant/blob/main/src/risk/manager.rs) (Risk Controls), [`src/order_manager.rs`](https://github.com/akfamily/akquant/blob/main/src/order_manager.rs) (Order Management)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Python Interface"]
  node_api["AKQuant API<br/>[__init__.py]"]
  node_data["Data Preparation<br/>[data.py]"]
  node_strategy["Strategy API<br/>[strategy.py]"]
  node_backtest["Backtest Runner<br/>[engine.py]"]
end

subgraph group_runtime["Trading Runtime"]
  node_engine["Rust Engine<br/>[core.rs]"]
  node_models["Market Models<br/>[instrument.rs]"]
  node_events["Event Types<br/>[event.rs]"]
  node_history["Market History<br/>[history.rs]"]
  node_risk["Risk Controls<br/>[manager.rs]"]
  node_orders["Order Management<br/>[order_manager.rs]"]
  node_execution["Execution Models<br/>[mod.rs]"]
  node_portfolio["Portfolio State<br/>[portfolio.rs]"]
  node_market["Market Rules<br/>[manager.rs]"]
end

subgraph group_research["Research Tools"]
  node_factor["Factor Engine<br/>[engine.py]"]
  node_indicators["TA-Lib Indicators<br/>[funcs.py]"]
  node_ml["Walk-forward ML<br/>[model.py]"]
  node_optimizer["Parameter Search<br/>[optimize.py]"]
end

subgraph group_connectivity["Live Connectivity"]
  node_live["Live Runner<br/>[_runner.py]"]
  node_gateway["Broker Gateway<br/>[factory.py]"]
end

subgraph group_results["Results"]
  node_analysis["Trade Analysis<br/>[tracker.rs]"]
  node_report["Result Reports<br/>[result.py]"]
  node_stream["Event Streaming<br/>[trade_stream.py]"]
end

node_user(("Quant Developer"))
node_marketdata(("Market Data Provider"))

node_user -->|"calls"| node_api
node_marketdata -->|"provides data"| node_data
node_api -->|"runs backtest"| node_backtest
node_data -->|"supplies input"| node_backtest
node_backtest -->|"loads strategy"| node_strategy
node_backtest -.->|"invokes engine"| node_engine
node_engine -.->|"emits events"| node_events
node_engine -->|"uses history"| node_history
node_engine -->|"uses orders"| node_orders
node_engine -->|"uses portfolio"| node_portfolio
node_engine -->|"uses models"| node_models
node_engine -.->|"checks orders"| node_risk
node_engine -.->|"dispatches execution"| node_execution
node_engine -.->|"applies rules"| node_market
node_orders -->|"updates positions"| node_portfolio
node_orders -->|"calculates fees"| node_market
node_risk -->|"checks exposure"| node_portfolio
node_risk -->|"checks market"| node_market
node_engine -.->|"tracks trades"| node_analysis
node_backtest -->|"returns results"| node_report
node_backtest -->|"emits progress"| node_stream
node_user -->|"computes factors"| node_factor
node_user -->|"uses indicators"| node_indicators
node_user -->|"trains models"| node_ml
node_user -->|"optimizes parameters"| node_optimizer
node_user -.->|"starts trading"| node_live
node_live -.->|"configures broker"| node_gateway
node_gateway -.->|"connects broker"| node_marketdata

click node_api "https://github.com/akfamily/akquant/blob/main/python/akquant/__init__.py"
click node_data "https://github.com/akfamily/akquant/blob/main/python/akquant/data.py"
click node_strategy "https://github.com/akfamily/akquant/blob/main/python/akquant/strategy.py"
click node_backtest "https://github.com/akfamily/akquant/blob/main/python/akquant/backtest/engine.py"
click node_engine "https://github.com/akfamily/akquant/blob/main/src/engine/core.rs"
click node_models "https://github.com/akfamily/akquant/blob/main/src/model/instrument.rs"
click node_events "https://github.com/akfamily/akquant/blob/main/src/event.rs"
click node_history "https://github.com/akfamily/akquant/blob/main/src/history.rs"
click node_risk "https://github.com/akfamily/akquant/blob/main/src/risk/manager.rs"
click node_orders "https://github.com/akfamily/akquant/blob/main/src/order_manager.rs"
click node_execution "https://github.com/akfamily/akquant/blob/main/src/execution/mod.rs"
click node_portfolio "https://github.com/akfamily/akquant/blob/main/src/portfolio.rs"
click node_market "https://github.com/akfamily/akquant/blob/main/src/market/manager.rs"
click node_analysis "https://github.com/akfamily/akquant/blob/main/src/analysis/tracker.rs"
click node_report "https://github.com/akfamily/akquant/blob/main/python/akquant/backtest/result.py"
click node_stream "https://github.com/akfamily/akquant/blob/main/python/akquant/trade_stream.py"
click node_factor "https://github.com/akfamily/akquant/blob/main/python/akquant/factor/engine.py"
click node_indicators "https://github.com/akfamily/akquant/blob/main/python/akquant/talib/funcs.py"
click node_ml "https://github.com/akfamily/akquant/blob/main/python/akquant/ml/model.py"
click node_optimizer "https://github.com/akfamily/akquant/blob/main/python/akquant/optimize.py"
click node_live "https://github.com/akfamily/akquant/blob/main/python/akquant/live/_runner.py"
click node_gateway "https://github.com/akfamily/akquant/blob/main/python/akquant/gateway/factory.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_api,node_data,node_strategy,node_backtest toneBlue
class node_engine,node_models,node_events,node_history,node_risk,node_orders,node_execution,node_portfolio,node_market toneAmber
class node_factor,node_indicators,node_ml,node_optimizer toneMint
class node_live,node_gateway toneRose
class node_analysis,node_report,node_stream,node_user,node_marketdata toneIndigo
```

## Components

### Python Interface

- [AKQuant API](https://github.com/akfamily/akquant/blob/main/python/akquant/__init__.py): `python/akquant/__init__.py`
- [Data Preparation](https://github.com/akfamily/akquant/blob/main/python/akquant/data.py): `python/akquant/data.py`
- [Strategy API](https://github.com/akfamily/akquant/blob/main/python/akquant/strategy.py): `python/akquant/strategy.py`
- [Backtest Runner](https://github.com/akfamily/akquant/blob/main/python/akquant/backtest/engine.py): `python/akquant/backtest/engine.py`

### Trading Runtime

- [Rust Engine](https://github.com/akfamily/akquant/blob/main/src/engine/core.rs): `src/engine/core.rs`
- [Market Models](https://github.com/akfamily/akquant/blob/main/src/model/instrument.rs): `src/model/instrument.rs`
- [Event Types](https://github.com/akfamily/akquant/blob/main/src/event.rs): `src/event.rs`
- [Market History](https://github.com/akfamily/akquant/blob/main/src/history.rs): `src/history.rs`
- [Risk Controls](https://github.com/akfamily/akquant/blob/main/src/risk/manager.rs): `src/risk/manager.rs`
- [Order Management](https://github.com/akfamily/akquant/blob/main/src/order_manager.rs): `src/order_manager.rs`
- [Execution Models](https://github.com/akfamily/akquant/blob/main/src/execution/mod.rs): `src/execution/mod.rs`
- [Portfolio State](https://github.com/akfamily/akquant/blob/main/src/portfolio.rs): `src/portfolio.rs`
- [Market Rules](https://github.com/akfamily/akquant/blob/main/src/market/manager.rs): `src/market/manager.rs`

### Research Tools

- [Factor Engine](https://github.com/akfamily/akquant/blob/main/python/akquant/factor/engine.py): `python/akquant/factor/engine.py`
- [TA-Lib Indicators](https://github.com/akfamily/akquant/blob/main/python/akquant/talib/funcs.py): `python/akquant/talib/funcs.py`
- [Walk-forward ML](https://github.com/akfamily/akquant/blob/main/python/akquant/ml/model.py): `python/akquant/ml/model.py`
- [Parameter Search](https://github.com/akfamily/akquant/blob/main/python/akquant/optimize.py): `python/akquant/optimize.py`

### Live Connectivity

- [Live Runner](https://github.com/akfamily/akquant/blob/main/python/akquant/live/_runner.py): `python/akquant/live/_runner.py`
- [Broker Gateway](https://github.com/akfamily/akquant/blob/main/python/akquant/gateway/factory.py): `python/akquant/gateway/factory.py`

### Results

- [Trade Analysis](https://github.com/akfamily/akquant/blob/main/src/analysis/tracker.rs): `src/analysis/tracker.rs`
- [Result Reports](https://github.com/akfamily/akquant/blob/main/python/akquant/backtest/result.py): `python/akquant/backtest/result.py`
- [Event Streaming](https://github.com/akfamily/akquant/blob/main/python/akquant/trade_stream.py): `python/akquant/trade_stream.py`

### Other components

- **Quant Developer**
- **Market Data Provider**

## Connections

- Quant Developer → AKQuant API: calls
- Market Data Provider → Data Preparation: provides data
- AKQuant API → Backtest Runner: runs backtest (evidence: `python/akquant/__init__.py`)
- Data Preparation → Backtest Runner: supplies input (evidence: `python/akquant/backtest/engine.py`)
- Backtest Runner → Strategy API: loads strategy (evidence: `python/akquant/backtest/engine.py`)
- Backtest Runner → Rust Engine: invokes engine
- Rust Engine → Event Types: emits events
- Rust Engine → Market History: uses history (evidence: `src/engine/mod.rs`)
- Rust Engine → Order Management: uses orders (evidence: `src/engine/mod.rs`)
- Rust Engine → Portfolio State: uses portfolio (evidence: `src/engine/mod.rs`)
- Rust Engine → Market Models: uses models (evidence: `src/engine/mod.rs`)
- Rust Engine → Risk Controls: checks orders
- Rust Engine → Execution Models: dispatches execution
- Rust Engine → Market Rules: applies rules
- Order Management → Portfolio State: updates positions (evidence: `src/order_manager.rs`)
- Order Management → Market Rules: calculates fees (evidence: `src/order_manager.rs`)
- Risk Controls → Portfolio State: checks exposure (evidence: `src/risk/manager.rs`)
- Risk Controls → Market Rules: checks market (evidence: `src/risk/manager.rs`)
- Rust Engine → Trade Analysis: tracks trades
- Backtest Runner → Result Reports: returns results (evidence: `python/akquant/backtest/engine.py`)
- Backtest Runner → Event Streaming: emits progress
- Quant Developer → Factor Engine: computes factors
- Quant Developer → TA-Lib Indicators: uses indicators
- Quant Developer → Walk-forward ML: trains models
- Quant Developer → Parameter Search: optimizes parameters
- Quant Developer → Live Runner: starts trading
- Live Runner → Broker Gateway: configures broker
- Broker Gateway → Market Data Provider: connects broker
