# jmerle/imc-prosperity-3-backtester architecture

> Architecture diagram of the GitHub repository jmerle/imc-prosperity-3-backtester, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jmerle/imc-prosperity-3-backtester
- Repository: https://github.com/jmerle/imc-prosperity-3-backtester

## Overview

– The algorithm file (e.g., user’s trading code) and other runtime arguments (round and day selections, merge options, etc.)
▪ Data Loader reads CSVs from the Resources component.
▪ The Order Matching module processes orders against order depths and market trades using the logic provided in several modules.
▪ Intermediate objects/data models (from “datamodel.py” and “models.py”) represent trading state.
- Output paths:
- A side panel for the Environment and Configuration layer, indicating how runtime variables and configuration files affect the system.

##### Architectural Patterns and Design Principles
- Modular Design: The project is broken into dedicated modules for data handling, simulation logic, and I/O which lends itself to a clean separation of concerns.
- Extensibility: The use of resource directories with CSV files and various command-line options demonstrates that the system is designed to be easily updated for new rounds/days or extended with additional data sets.
- CLI Application Structure: The __main__.py file points to a pattern where the application is modular, allowing both pip-based installation and local development (noting the development instructions in the README).

##### Technologies, Frameworks, and Libraries
- Python as the primary programming language.
- Standard modules for file I/O and CSV reading.
- GitHub Actions (via .github/workflows) for CI/CD.
- Environment management using uv (as mentioned for development).
- Integration with external applications like the Prosperity 3 Visualizer.

##### Specific Elements
- Component Labels:
– The CLI / Runner
– Core Backtesting Engine (with submodules: Data Processing, Order Matching)
– Data Loader / Resource Manager
– Configuration & Environment Variables (pointing to PROSPERITY3BT_ROUND, PROSPERITY3BT_DAY)
– Output / Logging (with optional Visualizer integration)
– Show the flow from input → processing → output.
- Visual Distinctions:
- Annotations:
– Brief notes on how the order matching works (priority of order depths over market trades, configuration options from the README).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    User("User (CLI_Input)"):::external

    %% CLI Layer
    subgraph "CLI Layer"
        CLI("CLI/Runner"):::frontend
    end

    %% Core Backtesting Engine Layer
    subgraph "Core Backtesting Engine"
        DP("Data Loader"):::core
        OM("Order Matching & Simulation"):::core
        DM("Trading Data Models"):::core
    end

    %% Data and Resource Management
    Resources("CSV Data (Resources Folder)"):::data

    %% Output & Integration Layer
    subgraph "Output & Integration"
        Out("Logging/Output"):::output
        Vis("Prosperity3 Visualizer (Optional)"):::output
    end

    %% Environment & Configuration
    Env("Environment & Configuration"):::env

    %% Connections / Data Flow
    User -->|"AlgorithmInput"| CLI
    CLI -->|"Initiates"| DP
    DP -->|"LoadsMarketData"| Resources
    DP -->|"FeedsData"| OM
    OM -->|"UsesModels"| DM
    OM -->|"GeneratesResults"| Out
    Out -->|"OptionalData"| Vis

    %% Environment influences components
    Env -.->|"SetsVariables"| CLI
    Env -.->|"Configures"| DP
    Env -.->|"Configures"| OM

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef core fill:#87CEFA,stroke:#000,stroke-width:2px;
    classDef data fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef output fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef external fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef env fill:#D3D3D3,stroke:#000,stroke-width:2px;

    %% Click Events for Component Mapping
    click CLI "https://github.com/jmerle/imc-prosperity-3-backtester/blob/master/prosperity3bt/__main__.py"
    click CLI "https://github.com/jmerle/imc-prosperity-3-backtester/blob/master/prosperity3bt/runner.py"
    click DP "https://github.com/jmerle/imc-prosperity-3-backtester/blob/master/prosperity3bt/data.py"
    click DP "https://github.com/jmerle/imc-prosperity-3-backtester/blob/master/prosperity3bt/file_reader.py"
    click DM "https://github.com/jmerle/imc-prosperity-3-backtester/blob/master/prosperity3bt/datamodel.py"
    click DM "https://github.com/jmerle/imc-prosperity-3-backtester/blob/master/prosperity3bt/models.py"
    click OM "https://github.com/jmerle/imc-prosperity-3-backtester/blob/master/prosperity3bt/open.py"
    click OM "https://github.com/jmerle/imc-prosperity-3-backtester/blob/master/prosperity3bt/parse_submission_logs.py"
    click Resources "https://github.com/jmerle/imc-prosperity-3-backtester/tree/master/prosperity3bt/resources"
    click Env "https://github.com/jmerle/imc-prosperity-3-backtester/blob/master/.editorconfig"
    click Env "https://github.com/jmerle/imc-prosperity-3-backtester/blob/master/pyproject.toml"
    click Env "https://github.com/jmerle/imc-prosperity-3-backtester/tree/master/.github/workflows"
```
