# stevenzhang070302/reinforcement-trading architecture

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

- Interactive diagram: https://gitdiagram.com/stevenzhang070302/reinforcement-trading
- Repository: https://github.com/stevenzhang070302/reinforcement-trading

## Overview

##### Component Relationships

**Market Data Sources → Data Ingestion → Data Preprocessing → Feature Engineering**
- ↓
- RL Training ← Model Storage
- ↓
- Trading Environment
- ↓
- Trade Execution → Broker API

##### Detailed Component Breakdown

- Market data input (AAPL_day.csv)
- To feature engineering (feature_engineering.py)
- Preprocessed data output (AAPL_day_features.csv)

- PPO Model Architecture
- Training Pipeline (rl_training.py)
- Custom Gym Environment (trading_env.py)
- Model Checkpoints Storage

- Broker API Integration (broker_api.py)
- Trade Executor (trade_executor.py)
- Real-time Data Flow

##### Technical Stack Indicators

Technology labels:
- Python (Primary language)
- Gym (RL Environment)
- PPO (RL Algorithm)
- Alpaca Markets API
- TensorBoard (Monitoring)

##### Additional Elements

- RAG Integration (Future)
- Sentiment Analysis (Future)
- Online Learning Pipeline (Future)
- Dashboard UI (Planned)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef data fill:#3498db,stroke:#2980b9,color:white
    classDef ml fill:#2ecc71,stroke:#27ae60,color:white
    classDef execution fill:#e67e22,stroke:#d35400,color:white
    classDef monitoring fill:#9b59b6,stroke:#8e44ad,color:white
    classDef future fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef storage fill:#f1c40f,stroke:#f39c12,color:black

    %% Data Layer
    subgraph DataLayer
        MarketData["Market Data Sources"]
        DataIngestion["Data Ingestion Module"]
        DataPreprocessing["Data Preprocessing"]
        FeatureEng["Feature Engineering"]
        RawData["Raw Data Storage"]
        ProcessedData["Processed Data Storage"]
    end

    %% ML Layer
    subgraph MLLayer
        RLAgent["RL Agent (PPO)"]
        ModelTraining["Model Training Pipeline"]
        TradingEnv["Trading Environment"]
        ModelStorage["Model Storage"]
        Backtest["Backtesting System"]
    end

    %% Execution Layer
    subgraph ExecutionLayer
        TradeExec["Trade Execution System"]
        BrokerInt["Broker Integration"]
        BrokerAPI["Alpaca Markets API"]
    end

    %% Monitoring Layer
    subgraph MonitoringLayer
        TensorBoard["TensorBoard"]
        Logging["Logging System"]
        Metrics["Performance Metrics"]
    end

    %% Future Features
    subgraph FutureFeatures
        RAG["RAG Integration"]:::future
        Sentiment["Sentiment Analysis"]:::future
        OnlineLearning["Online Learning"]:::future
        Dashboard["Dashboard UI"]:::future
    end

    %% Relationships
    MarketData --> DataIngestion
    DataIngestion --> DataPreprocessing
    DataPreprocessing --> FeatureEng
    DataIngestion --> RawData
    FeatureEng --> ProcessedData
    ProcessedData --> ModelTraining
    ModelTraining --> RLAgent
    RLAgent --> ModelStorage
    ModelStorage --> TradingEnv
    TradingEnv --> TradeExec
    TradeExec --> BrokerInt
    BrokerInt --> BrokerAPI
    
    %% Monitoring Connections
    ModelTraining --> TensorBoard
    TradeExec --> Logging
    RLAgent --> Metrics
    TradingEnv --> Backtest

    %% Click Events
    click DataIngestion "https://github.com/stevenzhang070302/reinforcement-trading/blob/main/data_ingestion/market_data.py"
    click FeatureEng "https://github.com/stevenzhang070302/reinforcement-trading/blob/main/data_preprocessing/feature_engineering.py"
    click ModelTraining "https://github.com/stevenzhang070302/reinforcement-trading/blob/main/rl_agent/rl_training.py"
    click TradingEnv "https://github.com/stevenzhang070302/reinforcement-trading/blob/main/rl_agent/trading_env.py"
    click ModelStorage "https://github.com/stevenzhang070302/reinforcement-trading/tree/main/rl_agent/rl_agent/models/"
    click BrokerInt "https://github.com/stevenzhang070302/reinforcement-trading/blob/main/trade_execution/broker_api.py"
    click TradeExec "https://github.com/stevenzhang070302/reinforcement-trading/blob/main/trade_execution/trade_executor.py"
    click TensorBoard "https://github.com/stevenzhang070302/reinforcement-trading/tree/main/rl_agent/logs/tensorboard/"
    click RawData "https://github.com/stevenzhang070302/reinforcement-trading/blob/main/data_ingestion/data_preprocessed/AAPL_day.csv"
    click ProcessedData "https://github.com/stevenzhang070302/reinforcement-trading/blob/main/data_preprocessing/AAPL_day_features.csv"
    click Logging "https://github.com/stevenzhang070302/reinforcement-trading/blob/main/trade_execution/logs/trade_execution.log"
    click Backtest "https://github.com/stevenzhang070302/reinforcement-trading/blob/main/rl_agent/backtest.py"

    %% Style Applications
    class DataIngestion,DataPreprocessing,FeatureEng,RawData,ProcessedData data
    class RLAgent,ModelTraining,TradingEnv,ModelStorage,Backtest ml
    class TradeExec,BrokerInt,BrokerAPI execution
    class TensorBoard,Logging,Metrics monitoring
    class RAG,Sentiment,OnlineLearning,Dashboard future
```
