# glacode/quantproject architecture

> Architecture diagram of the GitHub repository glacode/quantproject, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/glacode/quantproject
- Repository: https://github.com/glacode/quantproject

## Overview

##### Project type and purpose
- QuantProject is a full-stack, multi-library C# framework for quantitative finance: it provides data ingestion (QuantDownloader), core data structures (ADT), data access, data providers/streams, strategy backtesting and live trading support, plus optional UI/reporting.

##### File structure
- Top-level solutions: QuantProject.sln and QuantDownloader.sln
- Layers in QuantProject under directories b1_… through b5_:
- b1_ADT: core abstract data types and math utilities
- b2_DataAccess: ADO.NET/database-level data access
- b3_Data (Model): wrappers around raw data (caching, streaming, domain models)
- b4_Business: strategy definitions, backtester, live-execution interfaces, validation
- b5_Presentation: console/WinForms/Excel reporting and visual charts
- QuantDownloader: standalone executable/library fetching historical data and populating the database
- mdb folder: offline Access database, configuration files under each project, Visual Studio solution files

##### README for additional insights
- Layers described as “b1_Environment”, “b2_DataAccess”, “b3_Model”, “b4_Business”, “b5_View” and “QuantDownloader”
- Features: plugin strategy framework, backtesting engine, live trading interfaces, modular design
- Dependencies: .NET Framework 4+, Visual Studio, ADO.NET, OpenTick (in QuantDownloader)

##### Main components
a. Components
1. QuantDownloader Tool
- OpenTickDownloader subsystem (downloaders, selectors, requesters)
- DatabaseImporter/DataBaseWriter → writes to the project’s relational DB (MDB or SQL)
2. Database (Relational store)
- Stores raw ticks, OHLC bars, validated quotes, ticker metadata
3. DataAccess Layer (b2_DataAccess)
- Repository/SQLBuilder/SqlExecutor
- Tables abstractions for Bars, Quotes, Tickers
4. Model/Data Layer (b3_Data)
- IDataStreamer and data providers (HistoricalBarProvider, QuoteProvider)
- Caching subsystems
5. Core ADT Utilities (b1_ADT)
- Math, statistics, linear algebra, optimization engines, history interpolation
6. Business Logic (b4_Business)
- Timing management, validation, financial instruments, accounting, order execution
- Strategy plugin framework (IStrategy, backtester, live handler)
- Optimization subsystems (BruteForce, Genetic)
7. Presentation/Reporting (b5_Presentation)
- Console, Windows Forms, Excel reporting, charts
8. External dependencies/services
- OpenTick market data API
- Configuration files (app.config)
- External trading API for live execution (stub/interface)

b. Relationships and interactions
- QuantDownloader fetches data from OpenTick → writes to Database
- DataAccess layer connects to Database → exposes domain tables to Data Layer
- Data Layer requests historical quotes/bars → may cache → supplies streams to Business Logic
- Business Logic uses ADT utilities for computation → drives Strategy instances (Backtester or Live)
- Backtester simulates orders via the Business “Ordering” sub-module → writes logs
- Presentation reads logs or live results → renders charts/reports

c. Architectural patterns and design principles
- Layered (N-tier) architecture separating persistence, domain, business, presentation
- Plugin architecture for strategies and data providers (interfaces + DI)
- Observer/Event-driven for download progress, data streaming, order events
- Repository/Unit-of-Work for data access
- Factory and Strategy patterns for extensible algorithm selection and optimization

d. Key technologies/frameworks
- .NET Framework 4.x, C#
- ADO.NET / OleDb / SQLBuilder
- WinForms and Excel Interop (for reporting)
- OpenTick API for market data
- Genetic and BruteForce optimization engines in b1_ADT

##### Detail
- Sub-components for critical modules (e.g., OpenTickDownloader inside QuantDownloader; TimingManagement in Business)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Infrastructure Layer
    subgraph "Infrastructure (Blue)"
        direction TB
        QD["QuantDownloader Tool"]:::infra
        OT["OpenTickDownloader Subsystem"]:::infra
        DBImp["DatabaseImporter"]:::infra
        DBW["DatabaseWriter"]:::infra
        QD --> OT
        QD --> DBImp
        OT --> DBW
    end

    %% Database
    RelDB["Relational Database (Access MDB)"]:::infra

    %% Data Access Layer
    subgraph "Data Access Layer (Green)"
        direction TB
        Repo["Repository"]:::data
        SQLB["SQLBuilder"]:::data
        SQLE["SqlExecutor"]:::data
        Tables["Table Abstractions"]:::data
        Repo --> SQLB
        Repo --> SQLE
        Repo --> Tables
    end

    %% Model / Data Layer
    subgraph "Model/Data Layer (Green)"
        direction TB
        IData["IDataStreamer & Interfaces"]:::data
        Providers["DataProviders"]:::data
        Caching["Caching Subsystems"]:::data
        DataTables["Domain DataTables"]:::data
        IData --> Providers
        Providers --> Caching
        Providers --> DataTables
    end

    %% Core ADT Utilities
    subgraph "Core ADT Utilities (Green)"
        direction TB
        LA["Linear Algebra"]:::data
        Stats["Statistics"]:::data
        OptEng["Optimizing Engines"]:::data
        Hist["Histories & Interpolation"]:::data
        LA --> Stats
        Stats --> OptEng
        OptEng --> Hist
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer (Yellow)"
        direction TB
        Timing["Timing Management"]:::business
        Validation["Business Validation"]:::business
        Instruments["Financial Instruments & Accounting"]:::business
        Ordering["Order Execution Interfaces"]:::business
        Strategies["Strategy Plugin Framework"]:::business
        Testing["Backtester & Testing"]:::business
        Timing --> Validation
        Validation --> Instruments
        Instruments --> Ordering
        Instruments --> Strategies
        Strategies --> Testing
    end

    %% Presentation Layer
    subgraph "Presentation/Reporting Layer (Orange)"
        direction TB
        Chart["Charting"]:::presentation
        Console["Console Reporting"]:::presentation
        Excel["Excel Reporting"]:::presentation
        WinForms["Windows Forms Reporting"]:::presentation
        Chart --> Console
        Chart --> Excel
        Chart --> WinForms
    end

    %% External Services
    subgraph "External Dependencies"
        direction TB
        OTAPI["OpenTick Market Data API"]
        ExecAPI["External Trading API"]
        Config["Configuration Files (app.config)"]
    end

    %% Connections
    OT -->|fetch data| OTAPI
    DBImp -->|write| RelDB
    DBW -->|write| RelDB
    RelDB -->|read| Repo
    Repo -->|expose| IData
    IData -->|stream| Timing
    Hist -->|utilities| Timing
    Testing -->|logs/results| Chart
    Testing -->|logs/results| Console
    Testing -->|logs/results| Excel
    Testing -->|logs/results| WinForms
    Ordering -->|live orders| ExecAPI

    %% Click Events
    click QD "https://github.com/glacode/quantproject/tree/master/QuantDownloader/Downloader"
    click OT "https://github.com/glacode/quantproject/tree/master/QuantDownloader/Downloader/OpenTickDownloader"
    click DBImp "https://github.com/glacode/quantproject/blob/master/QuantDownloader/Downloader/DataBaseImporter.cs"
    click DBW "https://github.com/glacode/quantproject/blob/master/QuantDownloader/Downloader/OpenTickDownloader/DatabaseManagement/DataBaseWriter.cs"
    click RelDB "https://github.com/glacode/quantproject/blob/master/mdb/QuantProject.mdb"
    click SQLB "https://github.com/glacode/quantproject/blob/master/QuantProject/b2_DataAccess/SQLBuilder.cs"
    click SQLE "https://github.com/glacode/quantproject/blob/master/QuantProject/b2_DataAccess/SqlExecutor.cs"
    click Tables "https://github.com/glacode/quantproject/tree/master/QuantProject/b2_DataAccess/Tables"
    click LA "https://github.com/glacode/quantproject/tree/master/QuantProject/b1_ADT/LinearAlgebra"
    click Stats "https://github.com/glacode/quantproject/tree/master/QuantProject/b1_ADT/Statistics"
    click OptEng "https://github.com/glacode/quantproject/tree/master/QuantProject/b1_ADT/Optimizing"
    click Hist "https://github.com/glacode/quantproject/tree/master/QuantProject/b1_ADT/Histories"
    click Providers "https://github.com/glacode/quantproject/tree/master/QuantProject/b3_Data/DataProviders"
    click Caching "https://github.com/glacode/quantproject/tree/master/QuantProject/b3_Data/DataProviders/Caching"
    click DataTables "https://github.com/glacode/quantproject/tree/master/QuantProject/b3_Data/DataTables"
    click Timing "https://github.com/glacode/quantproject/tree/master/QuantProject/b4_Business/a05_Timing"
    click Validation "https://github.com/glacode/quantproject/tree/master/QuantProject/b4_Business/a0_Validation"
    click Instruments "https://github.com/glacode/quantproject/tree/master/QuantProject/b4_Business/a1_Financial"
    click Ordering "https://github.com/glacode/quantproject/tree/master/QuantProject/b4_Business/a1_Financial/a3_Ordering"
    click Strategies "https://github.com/glacode/quantproject/tree/master/QuantProject/b4_Business/a2_Strategies"
    click Testing "https://github.com/glacode/quantproject/tree/master/QuantProject/b4_Business/a3_Testing"
    click Chart "https://github.com/glacode/quantproject/tree/master/QuantProject/b5_Presentation/Charting"
    click Console "https://github.com/glacode/quantproject/tree/master/QuantProject/b5_Presentation/Reporting/Console"
    click Excel "https://github.com/glacode/quantproject/tree/master/QuantProject/b5_Presentation/Reporting/MicrosoftExcel"
    click WinForms "https://github.com/glacode/quantproject/tree/master/QuantProject/b5_Presentation/Reporting/WindowsForm"
    click Config "https://github.com/glacode/quantproject/blob/master/QuantDownloader/Downloader/app.config"

    %% Styles
    classDef infra fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef data fill:#90EE90,stroke:#333,stroke-width:1px;
    classDef business fill:#FFD700,stroke:#333,stroke-width:1px;
    classDef presentation fill:#FFA500,stroke:#333,stroke-width:1px;
```
