# walids35/capstone-stock-prediction architecture

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

- Interactive diagram: https://gitdiagram.com/walids35/capstone-stock-prediction
- Repository: https://github.com/walids35/capstone-stock-prediction
- Video tour (about a minute): https://gitdiagram.com/walids35/capstone-stock-prediction/video

## Overview

This framework turns market/news data into sentiment-enriched stock forecasts, then supports model evaluation, visualization, and trading analysis. The documented workflow spans data preparation, sentiment scoring, feature engineering, model training/inference, and result analysis. The graph preserves the four model families and their shared transformer/TimesNet building blocks. Several links rely on the SOURCE INDEX import references or README workflow; unsampled implementation details and data-source wiring are not inferred.

Main entry points: [`stock_prediction/dataset_pipeline.py`](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/dataset_pipeline.py) (Sequence Pipeline), [`stock_prediction/modeling/PatchTST.py`](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/PatchTST.py) (PatchTST Model), [`sentiment_analysis/main.py`](https://github.com/walids35/capstone-stock-prediction/blob/master/sentiment_analysis/main.py) (Sentiment Workflow), [`stock_prediction/trading_simulation.py`](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/trading_simulation.py) (Trading Simulation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data Preparation"]
  node_dataset["Data Collection<br/>[dataset.py]"]
  node_pipeline["Sequence Pipeline"]
  node_features["Feature Engineering<br/>[features.py]"]
end

subgraph group_sentiment["News Sentiment"]
  node_sentiment_main["Sentiment Workflow<br/>[main.py]"]
  node_sentiment_base["Model Comparison<br/>[base.py]"]
  node_bert["Transformer Classifier<br/>[bert_model.py]"]
  node_financial_compare["Financial News Comparison<br/>[financial.py]"]
  node_stock_compare["Stock News Comparison<br/>[stock.py]"]
  node_trainer["Sentiment Trainer<br/>[model_trainer.py]"]
end

subgraph group_forecast["Forecasting"]
  node_lstm["LSTM Model<br/>[LSTM.py]"]
  node_patchtst["PatchTST Model<br/>[PatchTST.py]"]
  node_timesnet["TimesNet Model<br/>[TimesNet.py]"]
  node_tpatchgnn["tPatchGNN Model<br/>[tPatchGNN.py]"]
  node_training["Model Training<br/>[train.py]"]
  node_train_patch["PatchTST Training<br/>[train_patchtst.py]"]
  node_train_times["TimesNet Training<br/>[train_timesnet.py]"]
  node_train_graph["tPatchGNN Training<br/>[train_tpatchgnn.py]"]
  node_predict["LSTM Inference<br/>[predict.py]"]
  node_predict_patch["PatchTST Inference"]
  node_predict_times["TimesNet Inference"]
  node_predict_graph["tPatchGNN Inference"]
end

subgraph group_analysis["Analysis &amp; Trading"]
  node_plots["Visualization<br/>[plots.py]"]
  node_simulation["Trading Simulation"]
end

subgraph group_shared["Shared Components"]
  node_config["Project Configuration<br/>[config.py]"]
  node_exp_config["Experiment Settings<br/>[ExpConfigs.py]"]
  node_cli_config["Run Configuration<br/>[configs.py]"]
  node_metrics["Forecast Metrics<br/>[metrics.py]"]
  node_tools["Training Utilities<br/>[tools.py]"]
  node_former_embed["Transformer Embeddings<br/>[Embed.py]"]
  node_former_attention["Attention Layers"]
  node_former_encoder["Transformer Encoder"]
  node_times_conv["TimesNet Convolutions<br/>[Conv_Blocks.py]"]
end

node_market_sources(("Market Data Sources"))
node_news_sources(("News Data Sources"))

node_market_sources -.->|"provides prices"| node_dataset
node_news_sources -.->|"provides news"| node_dataset
node_dataset -.->|"prepare sequences"| node_pipeline
node_pipeline -.->|"feeds features"| node_features
node_sentiment_main -->|"runs analysis"| node_financial_compare
node_sentiment_main -->|"runs analysis"| node_stock_compare
node_sentiment_main -->|"trains classifier"| node_trainer
node_financial_compare -->|"inherits comparison"| node_sentiment_base
node_stock_compare -->|"inherits comparison"| node_sentiment_base
node_sentiment_base -->|"wraps classifiers"| node_bert
node_pipeline -.->|"supplies sequences"| node_training
node_pipeline -->|"supplies sequences"| node_train_patch
node_pipeline -->|"supplies sequences"| node_train_times
node_pipeline -->|"supplies sequences"| node_train_graph
node_train_patch -->|"trains model"| node_patchtst
node_train_times -->|"trains model"| node_timesnet
node_train_graph -->|"trains model"| node_tpatchgnn
node_training -.->|"trains model"| node_lstm
node_predict_patch -->|"loads model"| node_patchtst
node_predict_times -->|"loads model"| node_timesnet
node_predict_graph -->|"loads model"| node_tpatchgnn
node_predict -.->|"runs inference"| node_lstm
node_patchtst -->|"uses embeddings"| node_former_embed
node_patchtst -->|"uses attention"| node_former_attention
node_patchtst -->|"uses encoder"| node_former_encoder
node_timesnet -->|"uses embeddings"| node_former_embed
node_timesnet -->|"uses convolutions"| node_times_conv
node_train_patch -->|"uses settings"| node_exp_config
node_train_times -->|"uses settings"| node_exp_config
node_train_graph -->|"uses settings"| node_exp_config
node_predict_patch -->|"computes scores"| node_metrics
node_predict_times -->|"computes scores"| node_metrics
node_predict_graph -->|"computes scores"| node_metrics
node_train_patch -->|"uses utilities"| node_tools
node_train_times -->|"uses utilities"| node_tools
node_train_graph -->|"uses utilities"| node_tools
node_cli_config -->|"constructs settings"| node_exp_config
node_simulation -->|"prepares sequences"| node_pipeline
node_simulation -->|"supports model"| node_patchtst
node_simulation -->|"supports model"| node_timesnet
node_simulation -->|"supports model"| node_tpatchgnn
node_simulation -->|"supports model"| node_lstm
node_plots -->|"uses paths"| node_config
node_sentiment_main -->|"uses project paths"| node_config
node_dataset -->|"uses paths"| node_config
node_sentiment_main -->|"builds comparison tables"| node_stock_compare
node_predict_patch -->|"uses run settings"| node_cli_config
node_predict_times -->|"uses run settings"| node_cli_config

click node_dataset "https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/dataset.py"
click node_pipeline "https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/dataset_pipeline.py"
click node_features "https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/features.py"
click node_sentiment_main "https://github.com/walids35/capstone-stock-prediction/blob/master/sentiment_analysis/main.py"
click node_sentiment_base "https://github.com/walids35/capstone-stock-prediction/blob/master/sentiment_analysis/models/base.py"
click node_bert "https://github.com/walids35/capstone-stock-prediction/blob/master/sentiment_analysis/models/bert_model.py"
click node_financial_compare "https://github.com/walids35/capstone-stock-prediction/blob/master/sentiment_analysis/comparison/financial.py"
click node_stock_compare "https://github.com/walids35/capstone-stock-prediction/blob/master/sentiment_analysis/comparison/stock.py"
click node_trainer "https://github.com/walids35/capstone-stock-prediction/blob/master/sentiment_analysis/trainers/model_trainer.py"
click node_lstm "https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/LSTM.py"
click node_patchtst "https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/PatchTST.py"
click node_timesnet "https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/TimesNet.py"
click node_tpatchgnn "https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/tPatchGNN.py"
click node_training "https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/train.py"
click node_train_patch "https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/train_patchtst.py"
click node_train_times "https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/train_timesnet.py"
click node_train_graph "https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/train_tpatchgnn.py"
click node_predict "https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/predict.py"
click node_predict_patch "https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/predict_patchtst.py"
click node_predict_times "https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/predict_timesnet.py"
click node_predict_graph "https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/predict_tpatchgnn.py"
click node_plots "https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/plots.py"
click node_simulation "https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/trading_simulation.py"
click node_config "https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/config.py"
click node_exp_config "https://github.com/walids35/capstone-stock-prediction/blob/master/utils/ExpConfigs.py"
click node_cli_config "https://github.com/walids35/capstone-stock-prediction/blob/master/utils/configs.py"
click node_metrics "https://github.com/walids35/capstone-stock-prediction/blob/master/utils/metrics.py"
click node_tools "https://github.com/walids35/capstone-stock-prediction/blob/master/utils/tools.py"
click node_former_embed "https://github.com/walids35/capstone-stock-prediction/blob/master/layers/Formers/Embed.py"
click node_former_attention "https://github.com/walids35/capstone-stock-prediction/blob/master/layers/Formers/SelfAttention_Family.py"
click node_former_encoder "https://github.com/walids35/capstone-stock-prediction/blob/master/layers/Formers/Transformer_EncDec.py"
click node_times_conv "https://github.com/walids35/capstone-stock-prediction/blob/master/layers/TimesNet/Conv_Blocks.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_dataset,node_pipeline,node_features toneBlue
class node_sentiment_main,node_sentiment_base,node_bert,node_financial_compare,node_stock_compare,node_trainer toneAmber
class node_lstm,node_patchtst,node_timesnet,node_tpatchgnn,node_training,node_train_patch,node_train_times,node_train_graph,node_predict,node_predict_patch,node_predict_times,node_predict_graph toneMint
class node_plots,node_simulation toneRose
class node_config,node_exp_config,node_cli_config,node_metrics,node_tools,node_former_embed,node_former_attention,node_former_encoder,node_times_conv,node_market_sources,node_news_sources toneIndigo
```

## Components

### Data Preparation

- [Data Collection](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/dataset.py): `stock_prediction/dataset.py`
- [Sequence Pipeline](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/dataset_pipeline.py): `stock_prediction/dataset_pipeline.py`
- [Feature Engineering](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/features.py): `stock_prediction/features.py`

### News Sentiment

- [Sentiment Workflow](https://github.com/walids35/capstone-stock-prediction/blob/master/sentiment_analysis/main.py): `sentiment_analysis/main.py`
- [Model Comparison](https://github.com/walids35/capstone-stock-prediction/blob/master/sentiment_analysis/models/base.py): `sentiment_analysis/models/base.py`
- [Transformer Classifier](https://github.com/walids35/capstone-stock-prediction/blob/master/sentiment_analysis/models/bert_model.py): `sentiment_analysis/models/bert_model.py`
- [Financial News Comparison](https://github.com/walids35/capstone-stock-prediction/blob/master/sentiment_analysis/comparison/financial.py): `sentiment_analysis/comparison/financial.py`
- [Stock News Comparison](https://github.com/walids35/capstone-stock-prediction/blob/master/sentiment_analysis/comparison/stock.py): `sentiment_analysis/comparison/stock.py`
- [Sentiment Trainer](https://github.com/walids35/capstone-stock-prediction/blob/master/sentiment_analysis/trainers/model_trainer.py): `sentiment_analysis/trainers/model_trainer.py`

### Forecasting

- [LSTM Model](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/LSTM.py): `stock_prediction/modeling/LSTM.py`
- [PatchTST Model](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/PatchTST.py): `stock_prediction/modeling/PatchTST.py`
- [TimesNet Model](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/TimesNet.py): `stock_prediction/modeling/TimesNet.py`
- [tPatchGNN Model](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/tPatchGNN.py): `stock_prediction/modeling/tPatchGNN.py`
- [Model Training](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/train.py): `stock_prediction/modeling/train.py`
- [PatchTST Training](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/train_patchtst.py): `stock_prediction/modeling/train_patchtst.py`
- [TimesNet Training](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/train_timesnet.py): `stock_prediction/modeling/train_timesnet.py`
- [tPatchGNN Training](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/train_tpatchgnn.py): `stock_prediction/modeling/train_tpatchgnn.py`
- [LSTM Inference](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/predict.py): `stock_prediction/modeling/predict.py`
- [PatchTST Inference](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/predict_patchtst.py): `stock_prediction/modeling/predict_patchtst.py`
- [TimesNet Inference](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/predict_timesnet.py): `stock_prediction/modeling/predict_timesnet.py`
- [tPatchGNN Inference](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/modeling/predict_tpatchgnn.py): `stock_prediction/modeling/predict_tpatchgnn.py`

### Analysis & Trading

- [Visualization](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/plots.py): `stock_prediction/plots.py`
- [Trading Simulation](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/trading_simulation.py): `stock_prediction/trading_simulation.py`

### Shared Components

- [Project Configuration](https://github.com/walids35/capstone-stock-prediction/blob/master/stock_prediction/config.py): `stock_prediction/config.py`
- [Experiment Settings](https://github.com/walids35/capstone-stock-prediction/blob/master/utils/ExpConfigs.py): `utils/ExpConfigs.py`
- [Run Configuration](https://github.com/walids35/capstone-stock-prediction/blob/master/utils/configs.py): `utils/configs.py`
- [Forecast Metrics](https://github.com/walids35/capstone-stock-prediction/blob/master/utils/metrics.py): `utils/metrics.py`
- [Training Utilities](https://github.com/walids35/capstone-stock-prediction/blob/master/utils/tools.py): `utils/tools.py`
- [Transformer Embeddings](https://github.com/walids35/capstone-stock-prediction/blob/master/layers/Formers/Embed.py): `layers/Formers/Embed.py`
- [Attention Layers](https://github.com/walids35/capstone-stock-prediction/blob/master/layers/Formers/SelfAttention_Family.py): `layers/Formers/SelfAttention_Family.py`
- [Transformer Encoder](https://github.com/walids35/capstone-stock-prediction/blob/master/layers/Formers/Transformer_EncDec.py): `layers/Formers/Transformer_EncDec.py`
- [TimesNet Convolutions](https://github.com/walids35/capstone-stock-prediction/blob/master/layers/TimesNet/Conv_Blocks.py): `layers/TimesNet/Conv_Blocks.py`

### Other components

- **Market Data Sources**
- **News Data Sources**

## Connections

- Market Data Sources → Data Collection: provides prices (evidence: `README.md`)
- News Data Sources → Data Collection: provides news (evidence: `README.md`)
- Data Collection → Sequence Pipeline: prepare sequences (evidence: `README.md`)
- Sequence Pipeline → Feature Engineering: feeds features (evidence: `README.md`)
- Sentiment Workflow → Financial News Comparison: runs analysis (evidence: `sentiment_analysis/main.py`)
- Sentiment Workflow → Stock News Comparison: runs analysis (evidence: `sentiment_analysis/main.py`)
- Sentiment Workflow → Sentiment Trainer: trains classifier (evidence: `sentiment_analysis/main.py`)
- Financial News Comparison → Model Comparison: inherits comparison (evidence: `sentiment_analysis/comparison/financial.py`)
- Stock News Comparison → Model Comparison: inherits comparison (evidence: `sentiment_analysis/comparison/stock.py`)
- Model Comparison → Transformer Classifier: wraps classifiers (evidence: `sentiment_analysis/models/base.py`)
- Sequence Pipeline → Model Training: supplies sequences (evidence: `README.md`)
- Sequence Pipeline → PatchTST Training: supplies sequences (evidence: `stock_prediction/modeling/train_patchtst.py`)
- Sequence Pipeline → TimesNet Training: supplies sequences (evidence: `stock_prediction/modeling/train_timesnet.py`)
- Sequence Pipeline → tPatchGNN Training: supplies sequences (evidence: `stock_prediction/modeling/train_tpatchgnn.py`)
- PatchTST Training → PatchTST Model: trains model (evidence: `stock_prediction/modeling/train_patchtst.py`)
- TimesNet Training → TimesNet Model: trains model (evidence: `stock_prediction/modeling/train_timesnet.py`)
- tPatchGNN Training → tPatchGNN Model: trains model (evidence: `stock_prediction/modeling/train_tpatchgnn.py`)
- Model Training → LSTM Model: trains model (evidence: `README.md`)
- PatchTST Inference → PatchTST Model: loads model (evidence: `stock_prediction/modeling/predict_patchtst.py`)
- TimesNet Inference → TimesNet Model: loads model (evidence: `stock_prediction/modeling/predict_timesnet.py`)
- tPatchGNN Inference → tPatchGNN Model: loads model (evidence: `stock_prediction/modeling/predict_tpatchgnn.py`)
- LSTM Inference → LSTM Model: runs inference (evidence: `README.md`)
- PatchTST Model → Transformer Embeddings: uses embeddings (evidence: `stock_prediction/modeling/PatchTST.py`)
- PatchTST Model → Attention Layers: uses attention (evidence: `stock_prediction/modeling/PatchTST.py`)
- PatchTST Model → Transformer Encoder: uses encoder (evidence: `stock_prediction/modeling/PatchTST.py`)
- TimesNet Model → Transformer Embeddings: uses embeddings (evidence: `stock_prediction/modeling/TimesNet.py`)
- TimesNet Model → TimesNet Convolutions: uses convolutions (evidence: `stock_prediction/modeling/TimesNet.py`)
- PatchTST Training → Experiment Settings: uses settings (evidence: `stock_prediction/modeling/train_patchtst.py`)
- TimesNet Training → Experiment Settings: uses settings (evidence: `stock_prediction/modeling/train_timesnet.py`)
- tPatchGNN Training → Experiment Settings: uses settings (evidence: `stock_prediction/modeling/train_tpatchgnn.py`)
- PatchTST Inference → Forecast Metrics: computes scores (evidence: `stock_prediction/modeling/predict_patchtst.py`)
- TimesNet Inference → Forecast Metrics: computes scores (evidence: `stock_prediction/modeling/predict_timesnet.py`)
- tPatchGNN Inference → Forecast Metrics: computes scores (evidence: `stock_prediction/modeling/predict_tpatchgnn.py`)
- PatchTST Training → Training Utilities: uses utilities (evidence: `stock_prediction/modeling/train_patchtst.py`)
- TimesNet Training → Training Utilities: uses utilities (evidence: `stock_prediction/modeling/train_timesnet.py`)
- tPatchGNN Training → Training Utilities: uses utilities (evidence: `stock_prediction/modeling/train_tpatchgnn.py`)
- Run Configuration → Experiment Settings: constructs settings (evidence: `utils/configs.py`)
- Trading Simulation → Sequence Pipeline: prepares sequences (evidence: `stock_prediction/trading_simulation.py`)
- Trading Simulation → PatchTST Model: supports model (evidence: `stock_prediction/trading_simulation.py`)
- Trading Simulation → TimesNet Model: supports model (evidence: `stock_prediction/trading_simulation.py`)
- Trading Simulation → tPatchGNN Model: supports model (evidence: `stock_prediction/trading_simulation.py`)
- Trading Simulation → LSTM Model: supports model (evidence: `stock_prediction/trading_simulation.py`)
- Visualization → Project Configuration: uses paths (evidence: `stock_prediction/plots.py`)
- Sentiment Workflow → Project Configuration: uses project paths (evidence: `sentiment_analysis/main.py`)
- Data Collection → Project Configuration: uses paths (evidence: `stock_prediction/dataset.py`)
- Sentiment Workflow → Stock News Comparison: builds comparison tables (evidence: `sentiment_analysis/main.py`)
- PatchTST Inference → Run Configuration: uses run settings (evidence: `stock_prediction/modeling/predict_patchtst.py`)
- TimesNet Inference → Run Configuration: uses run settings (evidence: `stock_prediction/modeling/predict_timesnet.py`)
