# damanish/financial_analysis architecture

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

- Interactive diagram: https://gitdiagram.com/damanish/financial_analysis
- Repository: https://github.com/damanish/financial_analysis

## Overview

##### Project Type and Purpose
- This is a full-stack data science pipeline + minimal front end.
- Purpose: Ingest OHLC time series and news headlines, run multiple regressors/classifiers, fuse their outputs via a neural net, and expose results in an HTML page.

##### File Structure
- data/All_new.csv → Raw dataset (OHLC + news headlines).
- ohlc_regression/ → Polynomial Regression on numerical data.
- KNN_regressor/, Random_Forest_Regressor/, weighted_knn/ → Various regression algorithms.
- SVM_classifier/, SentimentAnalysis/, ANN_classifier/ → Classification models on textual or time‐series data.
- late_fusion_model/ → Multimodal neural network that fuses numerical + textual features; includes app.py for serving.
- Project_Page/Page.html → Front-end UI.

##### README Highlights
- 3 model stages: Regression, Classification, Fusion.
- Custom implementations (gradient descent, random forest).
- Fusion network built in a Jupyter notebook and served via app.py.

##### Main Components & Their Relationships
a. Data Layer
– Component: Raw Data Store
– Files: data/All_new.csv, ohlc_regression/ohlc.csv
b. Preprocessing Modules
– Numerical Preprocessor (rolling averages, polynomial features)
– Text Preprocessor (tokenization, lemmatization, TF-IDF)
c. Modeling Modules
– Regression Services
- Polynomial Regression (ohlc_regression/regression.py)
- K-NN Regression (KNN_regressor/price_predict.py)
- Random Forest Regression (Random_Forest_Regressor/price_predictor.py)
- Weighted K-NN (weighted_knn/weighted_knn.py)
– Classification Services
- SVM (SVM_classifier/svm_classifier.py)
- Random Forest Classifier (SentimentAnalysis/sentiment_analysis.py)
- ANN Classifier (ANN_classifier/monthly prediction.py)
d. Fusion Module
– late_fusion_model/final_fusion.ipynb & app.py
– Takes concatenated numerical + text feature vectors → feeds into neural net → outputs final price prediction
e. Serving & Visualization
– Backend API: late_fusion_model/app.py (Flask or similar)
– Frontend: Project_Page/Page.html

##### Architectural Patterns & Design Principles
- Modular “each-model-in-its-own-folder” structure (loosely a micro-pipeline).
- ETL‐style flow: Extract raw data → Transform (feature engineering) → Load into models → Fuse → Serve.
- Separation of concerns: preprocessing vs modeling vs serving vs UI.
- Manual gradient descent & backprop to show custom ML pipeline.

##### Technologies & Frameworks
- Python (core)
- pandas, numpy (data handling)
- scikit-learn (KNN, Random Forest, SVM)
- Custom Python scripts (regression.py, sentiment_analysis.py)
- Jupyter notebook for fusion prototyping
- Flask (or FastAPI) in app.py
- HTML/CSS for front end

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        RawData["Raw Data Store"]:::data
        SecondaryData["OHLC Raw Data"]:::data
    end

    %% Preprocessing Modules
    subgraph "Preprocessing"
        NumPre["Numerical Preprocessor"]:::pre
        TextPre["Text Preprocessor"]:::pre
    end

    %% Modeling Modules
    subgraph "Modeling"
        subgraph "Regression Models"
            PolyReg["Polynomial Regression"]:::model
            KNNReg["K-NN Regression"]:::model
            RFReg["Random Forest Regression"]:::model
            WKNN["Weighted K-NN Regression"]:::model
        end
        subgraph "Classification Models"
            SVM["SVM Classifier"]:::model
            RFClass["Random Forest Classifier"]:::model
            ANNClass["ANN Classifier"]:::model
        end
    end

    %% Fusion Module
    Fusion["Fusion Neural Net"]:::fusion

    %% Serving & Visualization
    API["API / Serving"]:::api
    UI["Frontend UI"]:::frontend

    %% Data Flows
    RawData -->|"numerical data"| NumPre
    SecondaryData -->|"raw OHLC"| NumPre
    RawData -->|"news headlines"| TextPre

    NumPre -->|"numerical features"| PolyReg
    NumPre --> KNNReg
    NumPre --> RFReg
    NumPre --> WKNN

    TextPre -->|"TF-IDF vectors"| SVM
    TextPre --> RFClass
    TextPre --> ANNClass

    PolyReg -->|"model predictions"| Fusion
    KNNReg --> Fusion
    RFReg --> Fusion
    WKNN --> Fusion
    SVM --> Fusion
    RFClass --> Fusion
    ANNClass --> Fusion

    Fusion -->|"fused vector"| API
    API --> UI

    %% Click Events
    click RawData "https://github.com/damanish/financial_analysis/blob/main/data/All_new.csv"
    click SecondaryData "https://github.com/damanish/financial_analysis/blob/main/ohlc_regression/ohlc.csv"
    click NumPre "https://github.com/damanish/financial_analysis/blob/main/ohlc_regression/regression.py"
    click TextPre "https://github.com/damanish/financial_analysis/blob/main/SentimentAnalysis/sentiment_analysis.py"
    click PolyReg "https://github.com/damanish/financial_analysis/blob/main/ohlc_regression/regression.py"
    click KNNReg "https://github.com/damanish/financial_analysis/blob/main/KNN_regressor/price_predict.py"
    click RFReg "https://github.com/damanish/financial_analysis/blob/main/Random_Forest_Regressor/price_predictor.py"
    click WKNN "https://github.com/damanish/financial_analysis/blob/main/weighted_knn/weighted_knn.py"
    click SVM "https://github.com/damanish/financial_analysis/blob/main/SVM_classifier/svm_classifier.py"
    click RFClass "https://github.com/damanish/financial_analysis/blob/main/SentimentAnalysis/sentiment_analysis.py"
    click ANNClass "https://github.com/damanish/financial_analysis/blob/main/ANN_classifier/monthly prediction.py"
    click Fusion "https://github.com/damanish/financial_analysis/blob/main/late_fusion_model/final_fusion.ipynb"
    click API "https://github.com/damanish/financial_analysis/blob/main/late_fusion_model/app.py"
    click UI "https://github.com/damanish/financial_analysis/blob/main/Project_Page/Page.html"

    %% Styles
    classDef data fill:#AEDFF7,stroke:#000,stroke-width:1px
    classDef pre fill:#CFF7C7,stroke:#000,stroke-width:1px
    classDef model fill:#F7D6A3,stroke:#000,stroke-width:1px
    classDef fusion fill:#E1C7F7,stroke:#000,stroke-width:1px
    classDef api fill:#F7A3A3,stroke:#000,stroke-width:1px
    classDef frontend fill:#DDDDDD,stroke:#000,stroke-width:1px
```
