# sohaibelkarmi/high-frequency-trading-simulator architecture

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

- Interactive diagram: https://gitdiagram.com/sohaibelkarmi/high-frequency-trading-simulator
- Repository: https://github.com/sohaibelkarmi/high-frequency-trading-simulator

## Overview

This repository is a high-frequency trading research simulator. Its central workflow generates Hawkes order events, applies latency and deterministic matching, records execution costs, and exposes results through a Python backtester and analytics/UI. The README also documents recorded-feed ingestion and research diagnostics. Arrows are limited to relationships explicit in the README or shown in indexed source references and excerpts; unsampled subsystems are retained where their paths are supported, without asserting unverified wiring.

Main entry points: [`python/backtester/backtester.py`](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/backtester/backtester.py) (Replay Orchestrator), [`src/matching_engine.cpp`](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/src/matching_engine.cpp) (Matching Engine), [`python/timeline_dashboard.py`](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/timeline_dashboard.py) (Timeline Dashboard), [`python/kernels.py`](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/kernels.py) (Python Hawkes Kernels)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_flow["Order Flow"]
  node_hawkes_cpp["Hawkes Sampler<br/>[hawkes_engine.cpp]"]
  node_hawkes_py["Python Hawkes Kernels<br/>[kernels.py]"]
  node_orderflow_fit["Order-Flow Calibration<br/>[calibration.py]"]
  node_feed_ingest["Feed Ingestion<br/>[itch.py]"]
end

subgraph group_engine["Simulation Engine"]
  node_event_engine["Event Producer<br/>[event_engine.cpp]"]
  node_runtime["Engine Runtime<br/>[engine_runtime.cpp]"]
  node_matching["Matching Engine"]
  node_orderbook[("Order Book<br/>[OrderBook.hpp]")]
  node_latency["Latency Model<br/>[latency_model.hpp]"]
  node_execution["Execution Costs<br/>[execution_cost.hpp]"]
  node_simcore["Simulator Core<br/>[simulator_core.hpp]"]
end

subgraph group_backtest["Python Backtesting"]
  node_py_book["Python Book Adapter<br/>[order_book.py]"]
  node_backtester["Replay Orchestrator<br/>[backtester.py]"]
  node_strategy["Trading Strategy<br/>[strategy.py]"]
  node_risk["Risk and PnL<br/>[risk.py]"]
  node_metrics[("Metrics Logging<br/>[logging.py]")]
  node_dashboard["Risk Dashboard<br/>[dashboard.py]"]
end

subgraph group_research["Analytics and UI"]
  node_analysis_io["Analytics I/O<br/>[io.py]"]
  node_plots["Diagnostics Plots<br/>[plots.py]"]
  node_timeline["Timeline Dashboard"]
  node_streamlit["Hawkes Streamlit<br/>[streamlit_app.py]"]
  node_simulator["Simulation API<br/>[simulate.py]"]
end

node_researcher(("Researcher"))
node_results["Researcher Results"]

node_researcher -->|"configures simulations"| node_streamlit
node_researcher -->|"runs replay"| node_backtester
node_hawkes_cpp -->|"samples events"| node_event_engine
node_runtime -->|"starts and joins"| node_event_engine
node_event_engine -->|"queues events"| node_matching
node_runtime -->|"starts and joins"| node_matching
node_matching -->|"samples delays"| node_latency
node_matching -->|"matches orders"| node_orderbook
node_matching -->|"records executions"| node_execution
node_simcore -->|"uses process"| node_hawkes_cpp
node_simcore -->|"seeds book"| node_orderbook
node_simcore -->|"tracks costs"| node_execution
node_backtester -->|"applies replay"| node_py_book
node_backtester -->|"invokes strategy"| node_strategy
node_backtester -->|"updates risk"| node_risk
node_backtester -->|"logs metrics"| node_metrics
node_backtester -->|"renders dashboard"| node_dashboard
node_feed_ingest -.->|"supplies events"| node_backtester
node_py_book -.->|"uses native bridge"| node_orderbook
node_dashboard -->|"reads metrics"| node_metrics
node_streamlit -->|"configures kernels"| node_hawkes_py
node_streamlit -->|"uses dashboard"| node_timeline
node_timeline -->|"uses kernels"| node_hawkes_py
node_timeline -->|"simulates events"| node_simulator
node_timeline -->|"presents timelines"| node_results
node_simulator -->|"uses kernels"| node_hawkes_py
node_orderflow_fit -.->|"produces calibration"| node_results
node_analysis_io -.->|"exports artefacts"| node_results
node_plots -->|"visualizes diagnostics"| node_results
node_backtester -->|"reports replay metrics"| node_results
node_hawkes_py -->|"generates order flow"| node_results

click node_hawkes_cpp "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/src/hawkes_engine.cpp"
click node_hawkes_py "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/kernels.py"
click node_orderflow_fit "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/order_flow/calibration.py"
click node_feed_ingest "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/backtester/itch.py"
click node_event_engine "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/src/event_engine.cpp"
click node_runtime "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/src/engine_runtime.cpp"
click node_matching "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/src/matching_engine.cpp"
click node_orderbook "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/src/OrderBook.hpp"
click node_latency "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/src/latency_model.hpp"
click node_execution "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/src/execution_cost.hpp"
click node_simcore "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/src/simulator_core.hpp"
click node_py_book "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/backtester/order_book.py"
click node_backtester "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/backtester/backtester.py"
click node_strategy "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/backtester/strategy.py"
click node_risk "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/backtester/risk.py"
click node_metrics "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/backtester/logging.py"
click node_dashboard "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/backtester/dashboard.py"
click node_analysis_io "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/analysis/io.py"
click node_plots "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/analysis/plots.py"
click node_timeline "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/timeline_dashboard.py"
click node_streamlit "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/streamlit_app.py"
click node_simulator "https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/simulate.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_hawkes_cpp,node_hawkes_py,node_orderflow_fit,node_feed_ingest toneBlue
class node_event_engine,node_runtime,node_matching,node_orderbook,node_latency,node_execution,node_simcore toneAmber
class node_py_book,node_backtester,node_strategy,node_risk,node_metrics,node_dashboard toneMint
class node_analysis_io,node_plots,node_timeline,node_streamlit,node_simulator toneRose
class node_researcher,node_results toneIndigo
```

## Components

### Order Flow

- [Hawkes Sampler](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/src/hawkes_engine.cpp): `src/hawkes_engine.cpp`
- [Python Hawkes Kernels](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/kernels.py): `python/kernels.py`
- [Order-Flow Calibration](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/order_flow/calibration.py): `python/order_flow/calibration.py`
- [Feed Ingestion](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/backtester/itch.py): `python/backtester/itch.py`

### Simulation Engine

- [Event Producer](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/src/event_engine.cpp): `src/event_engine.cpp`
- [Engine Runtime](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/src/engine_runtime.cpp): `src/engine_runtime.cpp`
- [Matching Engine](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/src/matching_engine.cpp): `src/matching_engine.cpp`
- [Order Book](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/src/OrderBook.hpp): `src/OrderBook.hpp`
- [Latency Model](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/src/latency_model.hpp): `src/latency_model.hpp`
- [Execution Costs](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/src/execution_cost.hpp): `src/execution_cost.hpp`
- [Simulator Core](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/src/simulator_core.hpp): `src/simulator_core.hpp`

### Python Backtesting

- [Python Book Adapter](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/backtester/order_book.py): `python/backtester/order_book.py`
- [Replay Orchestrator](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/backtester/backtester.py): `python/backtester/backtester.py`
- [Trading Strategy](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/backtester/strategy.py): `python/backtester/strategy.py`
- [Risk and PnL](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/backtester/risk.py): `python/backtester/risk.py`
- [Metrics Logging](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/backtester/logging.py): `python/backtester/logging.py`
- [Risk Dashboard](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/backtester/dashboard.py): `python/backtester/dashboard.py`

### Analytics and UI

- [Analytics I/O](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/analysis/io.py): `python/analysis/io.py`
- [Diagnostics Plots](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/analysis/plots.py): `python/analysis/plots.py`
- [Timeline Dashboard](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/timeline_dashboard.py): `python/timeline_dashboard.py`
- [Hawkes Streamlit](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/streamlit_app.py): `python/streamlit_app.py`
- [Simulation API](https://github.com/sohaibelkarmi/high-frequency-trading-simulator/blob/main/python/simulate.py): `python/simulate.py`

### Other components

- **Researcher**
- **Researcher Results**

## Connections

- Researcher → Hawkes Streamlit: configures simulations
- Researcher → Replay Orchestrator: runs replay
- Hawkes Sampler → Event Producer: samples events (evidence: `src/event_engine.cpp`)
- Engine Runtime → Event Producer: starts and joins (evidence: `src/engine_runtime.cpp`)
- Event Producer → Matching Engine: queues events (evidence: `src/event_engine.cpp`)
- Engine Runtime → Matching Engine: starts and joins (evidence: `src/engine_runtime.cpp`)
- Matching Engine → Latency Model: samples delays
- Matching Engine → Order Book: matches orders (evidence: `src/matching_engine.cpp`)
- Matching Engine → Execution Costs: records executions
- Simulator Core → Hawkes Sampler: uses process (evidence: `src/simulator_core.hpp`)
- Simulator Core → Order Book: seeds book (evidence: `src/simulator_core.hpp`)
- Simulator Core → Execution Costs: tracks costs (evidence: `src/simulator_core.hpp`)
- Replay Orchestrator → Python Book Adapter: applies replay (evidence: `python/backtester/backtester.py`)
- Replay Orchestrator → Trading Strategy: invokes strategy (evidence: `python/backtester/backtester.py`)
- Replay Orchestrator → Risk and PnL: updates risk (evidence: `python/backtester/backtester.py`)
- Replay Orchestrator → Metrics Logging: logs metrics (evidence: `python/backtester/backtester.py`)
- Replay Orchestrator → Risk Dashboard: renders dashboard (evidence: `python/backtester/backtester.py`)
- Feed Ingestion → Replay Orchestrator: supplies events
- Python Book Adapter → Order Book: uses native bridge (evidence: `python/backtester/order_book.py`)
- Risk Dashboard → Metrics Logging: reads metrics (evidence: `python/backtester/dashboard.py`)
- Hawkes Streamlit → Python Hawkes Kernels: configures kernels (evidence: `python/streamlit_app.py`)
- Hawkes Streamlit → Timeline Dashboard: uses dashboard (evidence: `python/streamlit_app.py`)
- Timeline Dashboard → Python Hawkes Kernels: uses kernels (evidence: `python/timeline_dashboard.py`)
- Timeline Dashboard → Simulation API: simulates events (evidence: `python/timeline_dashboard.py`)
- Timeline Dashboard → Researcher Results: presents timelines
- Simulation API → Python Hawkes Kernels: uses kernels (evidence: `python/simulate.py`)
- Order-Flow Calibration → Researcher Results: produces calibration
- Analytics I/O → Researcher Results: exports artefacts
- Diagnostics Plots → Researcher Results: visualizes diagnostics
- Replay Orchestrator → Researcher Results: reports replay metrics
- Python Hawkes Kernels → Researcher Results: generates order flow
