# gregzanotti/dlsa-public architecture

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

- Interactive diagram: https://gitdiagram.com/gregzanotti/dlsa-public
- Repository: https://github.com/gregzanotti/dlsa-public

## Overview

a. Data Generation Flow:
- Raw Data → Factor Models → Residuals Storage

b. Training Flow:
- Residuals → Preprocessing → Model Training → Model Evaluation

c. Trading Flow:
- Trained Model → Trading Simulation → Performance Results

##### Component Details

a. Factor Models Subsystem:
- Three implementations: FamaFrench, IPCA, PCA
- Connections to residuals storage

b. Model Architecture Subsystem:
- Four model variants
- Shared interfaces/inheritance

c. Configuration Management:
- Link different config files to respective models
- Parameter flow

##### Important Interactions

- How run_train_test.py orchestrates the entire process
- Config file usage across components
- Demonstrate how utils.py supports various components

##### Technical Details to Highlight

- Python-based implementation
- NumPy data handling (shown by .npy.gz files)
- YAML configuration system
- Modular model architecture

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Define styles
    classDef data fill:#3498db,stroke:#2980b9,color:white
    classDef model fill:#2ecc71,stroke:#27ae60,color:white
    classDef process fill:#e67e22,stroke:#d35400,color:white
    classDef config fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef storage fill:#8e44ad,stroke:#703688,color:white

    %% Data Processing Layer
    subgraph DataProcessing
        RawData["Raw Data Input"]:::data
        DataHandler["Data Handler"]:::data
        PreProcess["Preprocessing Pipeline"]:::data
    end

    %% Factor Models Layer
    subgraph FactorModels
        FF["FamaFrench"]:::model
        IPCA["IPCA"]:::model
        PCA["PCA"]:::model
    end

    %% Model Layer
    subgraph Models
        CNNT["CNNTransformer"]:::model
        FFFN["FourierFFN"]:::model
        OUFFN["OUFFN"]:::model
        RFFN["RawFFN"]:::model
    end

    %% Configuration Layer
    subgraph Configs
        CNNTConfig["CNNTransformer Config"]:::config
        FFFNConfig["FourierFFN Config"]:::config
        OUFFNConfig["OUFFN Config"]:::config
        RFFNConfig["RawFFN Config"]:::config
    end

    %% Storage Layer
    subgraph Storage
        ResStorage["Residuals Storage"]:::storage
        FFRes["FamaFrench Residuals"]:::storage
        IPCARes["IPCA Residuals"]:::storage
        PCARes["PCA Residuals"]:::storage
    end

    %% Training & Testing Layer
    subgraph TrainingTesting
        Train["Training Pipeline"]:::process
        Test["Testing Pipeline"]:::process
        Trading["Trading Simulation"]:::process
    end

    %% Utility Layer
    Utils["Utility Functions"]:::config

    %% Connections
    RawData --> DataHandler
    DataHandler --> PreProcess
    PreProcess --> |Data| FactorModels

    FF --> FFRes
    IPCA --> IPCARes
    PCA --> PCARes

    FFRes --> Train
    IPCARes --> Train
    PCARes --> Train

    CNNTConfig --> CNNT
    FFFNConfig --> FFFN
    OUFFNConfig --> OUFFN
    RFFNConfig --> RFFN

    CNNT & FFFN & OUFFN & RFFN --> Train
    Train --> Test
    Test --> Trading

    Utils --> DataProcessing
    Utils --> TrainingTesting
    Utils --> Models

    %% Click events
    click DataHandler "https://github.com/gregzanotti/dlsa-public/blob/main/data.py"
    click PreProcess "https://github.com/gregzanotti/dlsa-public/blob/main/preprocess.py"
    click CNNT "https://github.com/gregzanotti/dlsa-public/blob/main/models/CNNTransformer.py"
    click FFFN "https://github.com/gregzanotti/dlsa-public/blob/main/models/FourierFFN.py"
    click OUFFN "https://github.com/gregzanotti/dlsa-public/blob/main/models/OUFFN.py"
    click RFFN "https://github.com/gregzanotti/dlsa-public/blob/main/models/RawFFN.py"
    click FF "https://github.com/gregzanotti/dlsa-public/blob/main/factor_models/famafrench.py"
    click IPCA "https://github.com/gregzanotti/dlsa-public/blob/main/factor_models/ipca.py"
    click PCA "https://github.com/gregzanotti/dlsa-public/blob/main/factor_models/pca.py"
    click CNNTConfig "https://github.com/gregzanotti/dlsa-public/blob/main/configs/cnntransformer-full.yaml"
    click FFFNConfig "https://github.com/gregzanotti/dlsa-public/blob/main/configs/fourierffn-full.yaml"
    click OUFFNConfig "https://github.com/gregzanotti/dlsa-public/blob/main/configs/ouffn-full.yaml"
    click RFFNConfig "https://github.com/gregzanotti/dlsa-public/blob/main/configs/rawffn-full.yaml"
    click Train "https://github.com/gregzanotti/dlsa-public/blob/main/train_test.py"
    click ResStorage "https://github.com/gregzanotti/dlsa-public/tree/main/residuals/"
    click FFRes "https://github.com/gregzanotti/dlsa-public/tree/main/residuals/famafrench/"
    click IPCARes "https://github.com/gregzanotti/dlsa-public/tree/main/residuals/ipca_normalized/"
    click PCARes "https://github.com/gregzanotti/dlsa-public/tree/main/residuals/pca/"
    click Utils "https://github.com/gregzanotti/dlsa-public/blob/main/utils.py"

    %% Legend
    subgraph Legend
        L1["Data Component"]:::data
        L2["Model Component"]:::model
        L3["Process Component"]:::process
        L4["Config Component"]:::config
        L5["Storage Component"]:::storage
    end
```
