# charliedream1/ai_quant_trade architecture

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

- Interactive diagram: https://gitdiagram.com/charliedream1/ai_quant_trade
- Repository: https://github.com/charliedream1/ai_quant_trade

## Overview

##### Main Components
- Data Ingestion & Processing: “egs_data” (submodules such as wind, tushare, baostock, etc.) plus the “quant_brain/data_io” components. These connect to external data sources (e.g., Wind, Tushare, JoinQuant) and serve as the data feeds.
- Core Algorithm & Quantitative Modules: “quant_brain” as the heart of the system with submodules for backtesting, risk indicators, portfolio management, and trading control.
- Trading Strategies / Modules:
- “egs_trade” contains both paper_trade (simulated real-time trading), “rl” for reinforcement learning strategies, and “vanilla” for traditional rule-based strategies.
- “egs_alpha” houses the factor libraries and automated alpha/factor mining components.
- Advanced Analysis Modules:
- “egs_fin_nlp” for text analysis and sentiment detection.
- “egs_llm” for large model-based financial analysis and strategy.
- Auxiliary & Deployment Tools:
- “egs_aide” for auxiliary trading tools (“看盘神器”) – supporting real-time market monitoring.
- “runtime” for deployment-related setup (covering CPU/GPU environments, live deployment scripts).
- “tools” for utility functions (date/time, file I/O, logging, plotting, etc.).
- “unit_test” for testing components.

##### Relationships and Interactions
- Data flows from external financial data providers (Wind, Tushare, etc.) into the Data Ingestion modules (“egs_data” and quant_brain/data_io).
- Processed market data then feeds into both the core algorithm library (“quant_brain”) and various trading strategy modules (egs_trade, egs_alpha).
- The strategy modules might further interact with advanced analysis modules: for example, outputs from “egs_fin_nlp” or “egs_llm” (sentiment or large model analyses) are incorporated into decision-making for the strategies.
- There is a feedback loop from backtesting and simulation (under “quant_brain/back_test” and “egs_trade/paper_trade”) to strategy refinement.
- Deployment via “runtime” connects the developed strategies and algorithms to a live or simulated trading environment.
- “tools” support operations (configuration management, logging, visualization) across the entire system.
- Documentation and training resources (“ai_notes” and “docs”) support user onboarding and knowledge transfer.

##### Architectural Patterns & Design Principles
- Modular Design: Each high-level folder encapsulates a distinct domain (data, strategy, analysis, deployment), making it easier to maintain and extend.
- Separation of Concerns: Data ingestion, algorithmic execution, strategy backtesting, and auxiliary tooling are kept separate.
- Integration via Core Library: “quant_brain” acts as a bridge between data inputs and strategy executions.
- Flexibility and Extensibility: With submodules for various strategies (RL, traditional, deep learning, etc.) and external resource integration, the design leverages plug-in points for future enhancements.

##### Incorporate Relevant Technologies
- Python (the predominant language for all modules, as indicated by requirements.txt, flake8, pylint configuration, etc.).
- Financial data APIs (Wind, Baostock, Tushare, etc.).
- Machine Learning / Reinforcement Learning libraries (likely frameworks such as Stable-Baselines3 or custom RL recipes in “egs_trade/rl”).
- Large Language Model (LLM) frameworks and deep learning libraries (possibly PyTorch or TensorFlow in the “egs_llm” modules).
- Supporting tools for configuration, logging, plotting, etc. (in “tools”).

- Review the README’s architecture outline (especially the “目录” and explained folder organization) to verify that all major paths are covered.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Data Source
    ExternalFinancialData["Financial Data Providers"]  

    %% Documentation & Knowledge Base
    subgraph "Documentation & Knowledge Base"
        AI_notes["ai_notes"]
        Docs["docs"]
    end

    %% Data Ingestion & Processing
    subgraph "Data Ingestion & Processing"
        EGS_data["egs_data"]
        Data_io["quant_brain/data_io"]
    end

    %% Core Quantitative Engine
    subgraph "Core Quantitative Engine"
        QuantBrain["quant_brain"]
    end

    %% Trading Strategies / Modules
    subgraph "Trading Strategies / Modules"
        EGS_trade["egs_trade"]
        EGS_alpha["egs_alpha"]
    end

    %% Advanced Analysis Modules
    subgraph "Advanced Analysis Modules"
        EGS_fin_nlp["egs_fin_nlp"]
        EGS_llm["egs_llm"]
    end

    %% Auxiliary & Deployment Tools
    subgraph "Auxiliary & Deployment Tools"
        EGS_aide["egs_aide"]
        Runtime["runtime"]
        Tools["tools"]
        UnitTest["unit_test"]
    end

    %% Data Flow Connections
    ExternalFinancialData -->|"feeds"| EGS_data
    ExternalFinancialData -->|"feeds"| Data_io

    EGS_data -->|"provides_data"| QuantBrain
    Data_io -->|"provides_data"| QuantBrain

    QuantBrain -->|"drives"| EGS_trade
    QuantBrain -->|"drives"| EGS_alpha

    EGS_fin_nlp -->|"informs"| EGS_trade
    EGS_llm -->|"informs"| EGS_trade
    EGS_fin_nlp -->|"informs"| EGS_alpha
    EGS_llm -->|"informs"| EGS_alpha

    EGS_trade -->|"feedback"| QuantBrain

    EGS_trade -->|"deploys_to"| Runtime
    EGS_alpha -->|"deploys_to"| Runtime
    QuantBrain -->|"deploys_to"| Runtime

    EGS_aide -->|"monitors"| Runtime

    Tools -->|"supports"| QuantBrain
    Tools -->|"supports"| EGS_trade
    Tools -->|"supports"| EGS_alpha
    Tools -->|"supports"| EGS_fin_nlp
    Tools -->|"supports"| EGS_llm

    UnitTest -->|"tests"| QuantBrain

    %% Style Classes
    classDef documentation fill:#DAF7A6,stroke:#333,stroke-width:2px;
    classDef data fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef core fill:#F5B7B1,stroke:#333,stroke-width:2px;
    classDef strategy fill:#F9E79F,stroke:#333,stroke-width:2px;
    classDef analysis fill:#D7BDE2,stroke:#333,stroke-width:2px;
    classDef auxiliary fill:#FADBD8,stroke:#333,stroke-width:2px;
    classDef external fill:#D5F5E3,stroke:#333,stroke-width:2px;

    class AI_notes,Docs documentation;
    class EGS_data,Data_io data;
    class QuantBrain core;
    class EGS_trade,EGS_alpha strategy;
    class EGS_fin_nlp,EGS_llm analysis;
    class EGS_aide,Runtime,Tools,UnitTest auxiliary;
    class ExternalFinancialData external;

    %% Click Events
    click AI_notes "https://github.com/charliedream1/ai_quant_trade/tree/master/ai_notes"
    click Docs "https://github.com/charliedream1/ai_quant_trade/tree/master/docs"
    click EGS_data "https://github.com/charliedream1/ai_quant_trade/tree/master/egs_data"
    click Data_io "https://github.com/charliedream1/ai_quant_trade/tree/master/quant_brain/data_io"
    click QuantBrain "https://github.com/charliedream1/ai_quant_trade/tree/master/quant_brain"
    click EGS_trade "https://github.com/charliedream1/ai_quant_trade/tree/master/egs_trade"
    click EGS_alpha "https://github.com/charliedream1/ai_quant_trade/tree/master/egs_alpha"
    click EGS_fin_nlp "https://github.com/charliedream1/ai_quant_trade/tree/master/egs_fin_nlp"
    click EGS_llm "https://github.com/charliedream1/ai_quant_trade/tree/master/egs_llm"
    click EGS_aide "https://github.com/charliedream1/ai_quant_trade/tree/master/egs_aide"
    click Runtime "https://github.com/charliedream1/ai_quant_trade/tree/master/runtime"
    click Tools "https://github.com/charliedream1/ai_quant_trade/tree/master/tools"
    click UnitTest "https://github.com/charliedream1/ai_quant_trade/tree/master/unit_test"
```
