# xsjk/stock-prediction architecture

> Architecture diagram of the GitHub repository xsjk/stock-prediction, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/xsjk/stock-prediction
- Repository: https://github.com/xsjk/stock-prediction

## Overview

##### Main Components

A. Data Layer:
- Raw Data Sources (CSV files)
- Stock data (Apple, Amazon, Google, Microsoft)
- Market indices (NYSE, NASDAQ, RUSSELL2000)
- Economic indicators (Treasury yields, USD/YUAN, VIX)
- News data (Apple News)
- Processed Data Storage (processed_dataset.pkl)

B. Processing Layer:
- Preprocessing Components
- Technical Indicators Processor
- Fourier Components Processor
- News Features Processor
- Data Transformation Pipeline

C. Model Layer:
- Training Module
- Inference Module
- Model Checkpointing System
- PyTorch Lightning Framework

D. Monitoring & Visualization:
- TensorBoard Integration
- Logging System

##### Component Relationships

**[Raw Data Sources] → [Preprocessing Pipeline] → [Processed Dataset]**
- ↓
**[Training Module] ← → [Model Checkpoints] → [Inference Module]**
- ↓
**[TensorBoard Logging]**

##### Specific Design Elements

- Rectangles: Data storage components
- Hexagons: Processing components
- Circles: Model components
- Diamonds: Monitoring components

- Blue: Data-related components
- Green: Processing components
- Red: Model components
- Yellow: Monitoring components

##### Implementation Details to Highlight

- Three main preprocessing features (technical_indicators, fourier_components, news_features)
- PyTorch Lightning integration
- Model versioning system (as evidenced by the lightning_logs structure)
- Checkpoint saving/loading mechanism
- Hyperparameter management system (visible in hparams.yaml files)

##### Key Architectural Patterns

- Modular design (separate utils modules)
- Pipeline architecture (preprocessing → training → inference)
- Experiment tracking architecture (TensorBoard + Lightning)

##### Technical Stack Indicators

- Python 3.10+
- PyTorch Lightning
- TensorBoard
- Data processing libraries (implied by the preprocessing capabilities)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Data_Sources
        RawStock["Stock Data (AAPL, AMZN, GOOG, MSFT)"]:::data
        RawMarket["Market Indices (NYSE, NASDAQ, RUSSELL)"]:::data
        RawEcon["Economic Indicators (Treasury, USD/YUAN, VIX)"]:::data
        RawNews["News Data (Apple News)"]:::data
    end

    subgraph Processing_Layer
        PreProc["Preprocessing Components"]:::process
        DataUtil["Data Utilities"]:::process
        TechInd["Technical Indicators"]:::process
        Fourier["Fourier Components"]:::process
        NewsProc["News Features"]:::process
    end

    subgraph Model_Layer
        ModelDef["Model Definition"]:::model
        TrainMod["Training Module"]:::model
        TestMod["Testing/Inference Module"]:::model
    end

    subgraph Monitoring
        TBoard["TensorBoard"]:::monitor
        CheckP["Model Checkpoints"]:::monitor
        HParams["Hyperparameters"]:::monitor
    end

    ProcessedData["Processed Dataset"]:::data

    RawStock & RawMarket & RawEcon & RawNews --> PreProc
    PreProc --> |Transform| TechInd & Fourier & NewsProc
    TechInd & Fourier & NewsProc --> ProcessedData
    DataUtil --> PreProc
    
    ProcessedData --> TrainMod
    ModelDef --> TrainMod
    TrainMod --> CheckP
    CheckP --> TestMod
    TrainMod --> TBoard
    HParams --> TrainMod

    %% Click Events
    click RawStock "https://github.com/xsjk/Stock-Prediction/tree/master/data/"
    click RawMarket "https://github.com/xsjk/Stock-Prediction/tree/master/data/"
    click RawEcon "https://github.com/xsjk/Stock-Prediction/tree/master/data/"
    click RawNews "https://github.com/xsjk/Stock-Prediction/blob/master/data/Apple News.csv"
    click ProcessedData "https://github.com/xsjk/Stock-Prediction/blob/master/data/processed_dataset.pkl"
    click PreProc "https://github.com/xsjk/Stock-Prediction/blob/master/utils/preprocess.py"
    click DataUtil "https://github.com/xsjk/Stock-Prediction/blob/master/utils/data.py"
    click ModelDef "https://github.com/xsjk/Stock-Prediction/blob/master/utils/model.py"
    click TrainMod "https://github.com/xsjk/Stock-Prediction/blob/master/utils/train.py"
    click TestMod "https://github.com/xsjk/Stock-Prediction/blob/master/utils/test.py"
    click TBoard "https://github.com/xsjk/Stock-Prediction/tree/master/lightning_logs/"
    click CheckP "https://github.com/xsjk/Stock-Prediction/tree/master/lightning_logs/"
    click HParams "https://github.com/xsjk/Stock-Prediction/blob/master/lightning_logs/version_0/hparams.yaml"

    %% Styles
    classDef data fill:#3498db,stroke:#2980b9,color:white
    classDef process fill:#2ecc71,stroke:#27ae60,color:white
    classDef model fill:#e74c3c,stroke:#c0392b,color:white
    classDef monitor fill:#f1c40f,stroke:#f39c12,color:black

    %% Legend
    subgraph Legend
        L1["Data Component"]:::data
        L2["Processing Component"]:::process
        L3["Model Component"]:::model
        L4["Monitoring Component"]:::monitor
    end
```
