# unasthana/portfolioallocationdeeprl architecture

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

- Interactive diagram: https://gitdiagram.com/unasthana/portfolioallocationdeeprl
- Repository: https://github.com/unasthana/portfolioallocationdeeprl

## Overview

##### Project Type and Purpose
- From the README and file structure, this is a machine-learning/data-science project focused on portfolio allocation using a latency-optimized deep reinforcement learning (A2C) algorithm in a simulated OpenAI Gym environment.
- It spans a data pipeline (scraping → cleaning → preprocessing), model training/evaluation (Main.ipynb), and successive code optimizations (pure Python → Cython → Numba → multiprocessing/multithreading).

##### File Structure
Top-level directories:
- Data/ – input asset list (stock_tickers.xlsx)
- RawCode/ – initial versions of three scripts plus install_packages.py
- OptimizedCode/ – optimized versions of the same scripts, plus Main.ipynb for orchestration
Configuration/build files:
- install_packages.py (dependency installer)
- README.md (project description & methodology)

##### README for Additional Insights
- Detailed methodology: custom Gym environment, state/action spaces, reward logic.
- A2C architecture: actor & critic networks, policy/value updates.
- Optimization stages: Python-level refactoring, Cython compilation, Numba JIT, parallel execution.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Pipeline
    subgraph "Data Pipeline"
        A_stock[(stock_tickers.xlsx)]:::storage
        A_api["yfinance API"]:::external

        A_stock -->|"tickers"| raw_scrape["data_scraping.py (Raw)"]:::script
        raw_scrape --> raw_csv[(Raw CSV)]:::storage
        raw_csv --> raw_clean["data_cleaning.py (Raw)"]:::script

        A_stock -->|"tickers"| opt_scrape["data_scraping.py (Optimized)"]:::script
        opt_scrape --> opt_csv[(Raw CSV)]:::storage
        opt_csv --> opt_clean["data_cleaning.py (Optimized)"]:::script

        opt_clean --> opt_preproc["data_preprocessing.py"]:::script
        opt_preproc --> features[(Feature Dataset)]:::storage
    end

    %% Reinforcement Learning Engine
    subgraph "RL Engine"
        gym["SimulatedTradingEnv"]:::env
        actor["Actor Network"]:::network
        critic["Critic Network"]:::network

        features --> gym
        gym -->|"state"| actor
        gym -->|"state"| critic
        actor -->|"action"| gym
        critic -->|"value"| actor
        gym -->|"reward"| critic
    end

    %% Orchestration & Evaluation
    subgraph "Orchestration & Evaluation"
        notebook["Main.ipynb"]:::notebook
        features --> notebook
        notebook --> gym
        notebook -->|"metrics"| metrics[(Performance Logs)]:::storage
        notebook -->|"model"| model[(Trained Model)]:::storage
    end

    %% Optimization Layers
    subgraph "Optimization Layers"
        opt_py["Python Optimizations"]:::optimization
        opt_cy["Cython Modules"]:::optimization
        opt_nb["Numba JIT"]:::optimization
        opt_par["Multiprocessing/Threading"]:::optimization

        raw_scrape <--> opt_py
        raw_clean <--> opt_py
        opt_preproc <--> opt_py

        raw_scrape <--> opt_cy
        raw_clean <--> opt_cy
        opt_preproc <--> opt_cy

        opt_preproc <--> opt_nb
        raw_scrape <--> opt_par
        raw_clean <--> opt_par
    end

    %% Project Setup
    subgraph "Project Setup"
        install_raw["install_packages.py (Raw)"]:::script
        install_opt["install_packages.py (Optimized)"]:::script
        readme["README.md"]:::doc

        install_raw --> install_opt
    end

    %% Click Events
    click raw_scrape "https://github.com/unasthana/portfolioallocationdeeprl/blob/main/RawCode/data_scraping.py"
    click opt_scrape "https://github.com/unasthana/portfolioallocationdeeprl/blob/main/OptimizedCode/data_scraping.py"
    click raw_clean "https://github.com/unasthana/portfolioallocationdeeprl/blob/main/RawCode/data_cleaning.py"
    click opt_clean "https://github.com/unasthana/portfolioallocationdeeprl/blob/main/OptimizedCode/data_cleaning.py"
    click opt_preproc "https://github.com/unasthana/portfolioallocationdeeprl/blob/main/OptimizedCode/data_preprocessing.py"
    click notebook "https://github.com/unasthana/portfolioallocationdeeprl/blob/main/OptimizedCode/Main.ipynb"
    click install_raw "https://github.com/unasthana/portfolioallocationdeeprl/blob/main/RawCode/install_packages.py"
    click install_opt "https://github.com/unasthana/portfolioallocationdeeprl/blob/main/OptimizedCode/install_packages.py"
    click A_stock "https://github.com/unasthana/portfolioallocationdeeprl/blob/main/Data/stock_tickers.xlsx"
    click readme "https://github.com/unasthana/portfolioallocationdeeprl/blob/main/README.md"

    %% Styles
    classDef storage fill:#f9f,stroke:#333,stroke-width:1px;
    classDef external fill:#ccf,stroke:#333,stroke-width:1px;
    classDef script fill:#cfc,stroke:#333,stroke-width:1px;
    classDef notebook fill:#fcf,stroke:#333,stroke-width:1px;
    classDef env fill:#ff9,stroke:#333,stroke-width:1px;
    classDef network fill:#9ff,stroke:#333,stroke-width:1px;
    classDef optimization fill:#fcc,stroke:#333,stroke-width:1px;
    classDef doc fill:#eef,stroke:#333,stroke-width:1px;
```
