# olehlohvyn/vbt-backtesting-engine architecture

> Architecture diagram of the GitHub repository olehlohvyn/vbt-backtesting-engine, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/olehlohvyn/vbt-backtesting-engine
- Repository: https://github.com/olehlohvyn/vbt-backtesting-engine

## Overview

##### Major Components
- Data Loader: Under core/data_loader, this module is composed of a generic “base_loader” as well as a Binance-specific loader (binance_loader) to fetch trading data.
- Data Processor: Located in core/data_processor, responsible for processing, validating, and building datasets from the loaded data.
- Backtester: Found in core/backtester, this component takes processed data, applies trading strategies, and evaluates their performance.
- Pairs Fetcher: Within core/pairs_fetcher, designed to obtain the 100 most liquid BTC trading pairs.
- Trading Strategies: In the strategies directory, containing the base strategy interface and specific implementations (e.g., sma_crossover), to be executed by the backtester.
- Configuration & Settings: Provided by files such as settings.py and the README description, which sets up the parameters for data range (e.g., February 2025) and exchange selections.
- Results: The results directory where outputs are stored, indicating the persistence or visualization layer.
- Utility Modules: The utils directory (with submodules for exceptions and logging) supports error management and log configuration across the system.
- Entry Point: The main.py script acts as the system’s primary execution flow which ties all the components together.

##### Relationships and Data Flow
- Data loading flows from the Data Loader to the Data Processor, which then validates and organizes the data.
- The Data Processor feeds the processed data into the Backtester that runs selected trading strategies.
- The Strategies module supplies the trading rules (like SMA crossover) that are applied on the processed data.
- Once backtesting is complete, results are stored/output in the Results module.
- The utility modules (logging and exceptions) are cross-cutting concerns used by all other components to ensure clean error handling and proper logging.

##### Architectural Patterns & Design Principles
- Modular Design: The separation into core modules (data_loader, data_processor, backtester, pairs_fetcher) highlights a clean separation of concerns.
- Extensibility through Strategies: The strategies folder indicates that new strategies can be added without major changes to the overall system, following the Open/Closed Principle.
- Layered Data Flow: Data moves through layers – from loading to processing to analysis – which can be visualized clearly.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Layer
    subgraph "Input Layer"
        BINANCE_API["Binance API"]:::external
        PAIRS_FETCHER["Pairs Fetcher"]:::core
        DATA_LOADER["Binance Data Loader"]:::core
    end

    %% Processing Layer
    subgraph "Processing Layer"
        DATA_PROCESSOR["Data Processor"]:::core
    end

    %% Analysis Layer
    subgraph "Analysis Layer"
        BACKTESTER["Backtester"]:::core
        STRATEGIES["Trading Strategies"]:::core
    end

    %% Output Layer
    subgraph "Output Layer"
        RESULTS["Results"]:::core
    end

    %% Configuration and Utilities
    subgraph "Configuration & Utilities"
        CONFIG["Configuration & Settings"]:::config
        UTIL["Utility Modules"]:::utility
        MAIN["Entry Point"]:::core
    end

    %% Data Flow Connections
    BINANCE_API -->|"fetches_data"| DATA_LOADER
    PAIRS_FETCHER -->|"provides_pairs"| DATA_LOADER
    DATA_LOADER -->|"sends_data"| DATA_PROCESSOR
    DATA_PROCESSOR -->|"processed_data"| BACKTESTER
    BACKTESTER -->|"triggers_strategy"| STRATEGIES
    BACKTESTER -->|"stores_results"| RESULTS

    %% Main Entrypoint Connections
    MAIN -->|"runs"| PAIRS_FETCHER
    MAIN -->|"runs"| DATA_LOADER
    MAIN -->|"runs"| DATA_PROCESSOR
    MAIN -->|"runs"| BACKTESTER
    MAIN -->|"runs"| STRATEGIES
    MAIN -->|"handles"| RESULTS
    MAIN -->|"loads"| CONFIG
    MAIN -->|"utilizes"| UTIL

    %% Configuration and Utility Support
    CONFIG -.->|"configures"| DATA_LOADER
    CONFIG -.->|"configures"| DATA_PROCESSOR
    CONFIG -.->|"configures"| BACKTESTER

    UTIL -.->|"supports"| DATA_LOADER
    UTIL -.->|"supports"| DATA_PROCESSOR
    UTIL -.->|"supports"| BACKTESTER
    UTIL -.->|"supports"| STRATEGIES

    %% Click Events
    click DATA_LOADER "https://github.com/olehlohvyn/vbt-backtesting-engine/tree/main/core/data_loader/"
    click DATA_PROCESSOR "https://github.com/olehlohvyn/vbt-backtesting-engine/blob/main/core/data_processor/data_processor.py"
    click BACKTESTER "https://github.com/olehlohvyn/vbt-backtesting-engine/blob/main/core/backtester/backtester.py"
    click PAIRS_FETCHER "https://github.com/olehlohvyn/vbt-backtesting-engine/blob/main/core/pairs_fetcher/pairs_fetcher.py"
    click STRATEGIES "https://github.com/olehlohvyn/vbt-backtesting-engine/tree/main/strategies/"
    click CONFIG "https://github.com/olehlohvyn/vbt-backtesting-engine/blob/main/settings.py"
    click RESULTS "https://github.com/olehlohvyn/vbt-backtesting-engine/tree/main/results/"
    click UTIL "https://github.com/olehlohvyn/vbt-backtesting-engine/tree/main/utils/"
    click MAIN "https://github.com/olehlohvyn/vbt-backtesting-engine/blob/main/main.py"

    %% Class Definitions
    classDef external fill:#FFC107,stroke:#000,stroke-width:1px;
    classDef core fill:#4CAF50,stroke:#000,stroke-width:1px;
    classDef config fill:#9C27B0,stroke:#000,stroke-width:1px;
    classDef utility fill:#03A9F4,stroke:#000,stroke-width:1px;
```
