# surajjayakumar2004/stock_prediction_options architecture

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

- Interactive diagram: https://gitdiagram.com/surajjayakumar2004/stock_prediction_options
- Repository: https://github.com/surajjayakumar2004/stock_prediction_options

## Overview

##### Project Type and Purpose
- This project is a machine-learning-based stock prediction and options recommendation system.
- Its goal is to use pre-trained models (stored as .joblib files) to forecast stock trends, compute option pricing, and offer stock recommendations. It also incorporates data ingestion and processing, along with supporting scripts for tasks like sentiment analysis and technical recommendations.

##### Main Components
a. Data Layer:
- Database Module (within the "database" directory) – This component is responsible for downloading and possibly managing stock data.
- Data Sources/Feeds – Although not directly visible, the "download_data.py" suggests that external data sources are used.
b. Model & Analytics Layer:
- Models Module (the "models" directory) – Contains multiple functionalities:
- lstm_model.py for time series predictions.
- stock_recommendation_model.py for suggesting stocks.
- option_pricing.py that handles pricing options.
- model_utils.py possibly includes helper functions.
- Pre-Trained Models (the "JobLib" directory) – Storage of serialized models for multiple stocks (e.g., HDFCBANK, RELIANCE), likely used by the models module.
c. Application / Presentation Layer:
- App Module (the "app" directory) – Comprises main.py and display.py, which likely serve as the user interface (whether via a web app, CLI, or another medium) to present predictions and recommendations.
d. Scripts / Orchestration Layer:
- Scripts Module (the "scripts" directory) – Contains various scripts for:
- Data processing (data_processing.py)
- Analyzing multiple stocks (analyze_all_stocks.py)
- Sentiment Analysis (sentiment_analysis.py)
- Technical options recommendations (technical_options_recommendations.py)
- This layer appears to support periodic data analysis, updates, and even potentially triggering batch tasks.

##### Relationships and Data Flows
- The Database Module is where data ingestion begins. Data gathered here is then fed into the Models Module.
- The Models Module accesses pre-trained models from the JobLib directory when running predictions.
- The Application Layer pulls results from the Models Layer (or directly from processed data) to display predictions, recommendations, and analyses.
- The Scripts Module can be seen as an orchestration layer that may trigger the whole pipeline (from data fetching to running models) and update the system’s outputs.
- There is a clear separation of concerns: data acquisition, model inference, and presentation, which lends itself to a modular architecture.

- Drill down by adding sub-components and detailing the interactions as described.
- Use annotations if possible to clarify key technologies (like indicating that .joblib files represent pre-trained ML models and that “lstm_model.py” handles time-series prediction).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        DB["Database Module"]:::data
    end

    %% Models & Analytics Layer
    subgraph "Models & Analytics Layer"
        LSTM["LSTM Prediction"]:::model
        REC["Stock Recommendation"]:::model
        OPT["Option Pricing"]:::model
        UTIL["Model Utilities"]:::model
        JOBLIB["Pre-Trained Models"]:::model
    end

    %% Application / Presentation Layer
    subgraph "Application / Presentation Layer"
        MAIN["Main"]:::app
        DISP["Display"]:::app
    end

    %% Scripts / Orchestration Layer
    subgraph "Scripts / Orchestration Layer"
        DP["Data Processing"]:::scripts
        ANALYZE["Analyze All Stocks"]:::scripts
        SENT["Sentiment Analysis"]:::scripts
        TECHOPT["Technical Options Recommendations"]:::scripts
    end

    %% Data Flow Connections
    DB -->|"stock_data"| LSTM
    DB -->|"stock_data"| REC
    DB -->|"stock_data"| OPT

    LSTM -->|"load_model"| JOBLIB
    REC -->|"load_model"| JOBLIB
    OPT -->|"load_model"| JOBLIB

    LSTM -->|"predictions"| MAIN
    REC -->|"recommendations"| DISP
    OPT -->|"option_pricing"| MAIN

    %% Scripts triggering interactions with other layers
    DP -->|"initiate_download"| DB
    ANALYZE -->|"trigger_model_run"| LSTM
    ANALYZE -->|"trigger_model_run"| REC
    ANALYZE -->|"trigger_model_run"| OPT
    SENT -->|"analyze_sentiment"| DB
    TECHOPT -->|"compute_technicals"| OPT

    %% Click Events
    click DB "https://github.com/surajjayakumar2004/stock_prediction_options/blob/main/database/download_data.py"
    click LSTM "https://github.com/surajjayakumar2004/stock_prediction_options/blob/main/models/lstm_model.py"
    click REC "https://github.com/surajjayakumar2004/stock_prediction_options/blob/main/models/stock_recommendation_model.py"
    click OPT "https://github.com/surajjayakumar2004/stock_prediction_options/blob/main/models/option_pricing.py"
    click UTIL "https://github.com/surajjayakumar2004/stock_prediction_options/blob/main/models/model_utils.py"
    click JOBLIB "https://github.com/surajjayakumar2004/stock_prediction_options/tree/main/JobLib/"
    click MAIN "https://github.com/surajjayakumar2004/stock_prediction_options/blob/main/app/main.py"
    click DISP "https://github.com/surajjayakumar2004/stock_prediction_options/blob/main/app/display.py"
    click DP "https://github.com/surajjayakumar2004/stock_prediction_options/blob/main/scripts/data_processing.py"
    click ANALYZE "https://github.com/surajjayakumar2004/stock_prediction_options/blob/main/scripts/analyze_all_stocks.py"
    click SENT "https://github.com/surajjayakumar2004/stock_prediction_options/blob/main/scripts/sentiment_analysis.py"
    click TECHOPT "https://github.com/surajjayakumar2004/stock_prediction_options/blob/main/scripts/technical_options_recommendations.py"

    %% Styles
    classDef data fill:#A2D9CE,stroke:#1E8449,stroke-width:2px;
    classDef model fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef app fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef scripts fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
```
