# michaelinzo/trading-agent- architecture

> Architecture diagram of the GitHub repository michaelinzo/trading-agent-, 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/michaelinzo/trading-agent-
- Repository: https://github.com/michaelinzo/trading-agent-

## Overview

##### Main Components
- Data Input Layer:
- Includes the CSV files under the "data" directory. These files serve as the source of historical stock data.
- Training Component:
- The training is handled by the "train.py" script. This module reads stock data, processes the market state (n-day window) and uses the deep Q-learning strategy (Vanilla DQN, Fixed Target DQN, and Double DQN are implemented; others are marked as pending).
- Reinforcement Learning Agent:
- Found in the "trading_bot" directory. The agent’s behavior and decision-making logic can be found in "agent.py", with supporting modules in "methods.py", "ops.py", and "utils.py". This component encapsulates the RL algorithm and integrates the environment interactions.
- Model Storage and Evaluation:
- The “models” directory contains pre-trained models. The evaluation of these models against a test dataset is managed by "eval.py".
- Visualization and Analysis:

##### Establish Relationships and Interactions
- Data Flow:
- Within the Training Component, illustrate the RL loop: the agent observes the state, takes an action (buy/sell/hold), receives a reward, and performs a learning update.
- Modular Interaction:
- The “trading_bot” modules interact as building blocks that together form the agent’s logic.
- How the “train.py” script orchestrates calls to these modules to update network weights.
- Evaluation & Model Deployment:
- Annotation that once the model is trained, it is saved in the "models" directory.
- Visualization:

##### Architectural Patterns and Principles
- Reinforcement Learning Loop:
- Clearly denote the cycle: State acquisition → Action decision → Reward computation → Update learning policy.
- Modularity and Separation of Concerns:
- The separation among training, evaluation, and the trading agent itself is explicitly organized by having distinct files and directories.
- Extensibility:
- The code supports different variants of DQN (Vanilla, Fixed Target, Double) and has placeholders for integrating Prioritized Experience Replay and Dueling Networks, indicating an architecture designed to easily incorporate additional RL improvements.

##### Relevant Technologies and Libraries
- Python Ecosystem:
- That dependencies are managed via "requirements.txt" and "pyproject.toml".
- Deep Learning Framework:
- Although the specific framework isn’t directly named in the file tree, typical frameworks for such projects include TensorFlow or PyTorch; you may note that the agent logic involves neural network calculations.
- Data Processing:
- CSV manipulation for stock data, along with possible use of libraries such as pandas for data processing (implied by the CSV data format).

##### Elements
- Use clear labels for each component (Data Input, RL Agent, Training Module, Evaluation Module, Visualization).
- Rectangles for modules/scripts (train.py, eval.py)

##### Detailed Integration
- Boundaries are clear – for example, indicate that "trading_bot" is a library/module used by both training and evaluation scripts.
- Do not forget to include the "extra" directory as a repository for supplemental resources such as the performance visualization image.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Data Input Layer
    subgraph "Data Input Layer"
        CSV["CSV Files"]:::data
    end

    %% Training Component
    subgraph "Training Component"
        TRAIN["train.py"]:::training
    end

    %% Reinforcement Learning Agent
    subgraph "Trading Bot (RL Agent)"
        LOOP["RL Loop (State→Action→Reward→Policy Update)"]:::loop
        AGENT["agent.py"]:::agent
        METHODS["methods.py"]:::agent
        OPS["ops.py"]:::agent
        UTILS["utils.py"]:::agent
    end

    %% Model Storage and Evaluation
    subgraph "Model Storage and Evaluation"
        MODELS["models/"]:::models
        EVAL["eval.py"]:::evaluation
    end

    %% Visualization and Analysis
    subgraph "Visualization and Analysis"
        VISUAL["visualize.ipynb"]:::visual
        EXTRA["extra/"]:::visual
    end

    %% Data Flow Connections
    CSV -->|"LoadData"| TRAIN
    TRAIN -->|"InitiatesRL"| LOOP
    LOOP -->|"UtilizesAgent"| AGENT
    AGENT -->|"calls"| METHODS
    METHODS -->|"uses"| OPS
    OPS -->|"assists"| UTILS
    LOOP -->|"UpdatesModel"| MODELS
    MODELS -->|"DeployedForEval"| EVAL
    TRAIN -->|"ProvidesMetrics"| VISUAL
    EVAL -->|"SendsResults"| VISUAL

    %% Click Events
    click CSV "https://github.com/michaelinzo/trading-agent-/tree/main/data/"
    click TRAIN "https://github.com/michaelinzo/trading-agent-/blob/main/train.py"
    click AGENT "https://github.com/michaelinzo/trading-agent-/blob/main/trading_bot/agent.py"
    click METHODS "https://github.com/michaelinzo/trading-agent-/blob/main/trading_bot/methods.py"
    click OPS "https://github.com/michaelinzo/trading-agent-/blob/main/trading_bot/ops.py"
    click UTILS "https://github.com/michaelinzo/trading-agent-/blob/main/trading_bot/utils.py"
    click MODELS "https://github.com/michaelinzo/trading-agent-/tree/main/models/"
    click EVAL "https://github.com/michaelinzo/trading-agent-/blob/main/eval.py"
    click VISUAL "https://github.com/michaelinzo/trading-agent-/blob/main/visualize.ipynb"
    click EXTRA "https://github.com/michaelinzo/trading-agent-/tree/main/extra/"

    %% Styles
    classDef data fill:#BBE6F9,stroke:#333,stroke-width:2px;
    classDef training fill:#F9D5BB,stroke:#333,stroke-width:2px;
    classDef agent fill:#CFF9BB,stroke:#333,stroke-width:2px;
    classDef loop fill:#F9F3BB,stroke:#333,stroke-width:2px;
    classDef models fill:#F9BBF9,stroke:#333,stroke-width:2px;
    classDef evaluation fill:#BBF9F3,stroke:#333,stroke-width:2px;
    classDef visual fill:#D5BBF9,stroke:#333,stroke-width:2px;
```
