# kittencn/stock_prediction architecture

> Architecture diagram of the GitHub repository kittencn/stock_prediction, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kittencn/stock_prediction
- Repository: https://github.com/kittencn/stock_prediction

## Overview

This is a PyTorch stock time-series research project. Its principal workflow is to acquire market data, prepare features, train a selected forecasting model, and run predictions for evaluation. The README also documents a broad model menu and configuration/normalization artifacts, which are represented as capabilities rather than as a fully specified internal call graph. Source excerpts are partial, so uncertain wiring between package modules is omitted.

Main entry points: [`src/stock_prediction/train.py`](https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/train.py) (Training workflow), [`src/stock_prediction/predict.py`](https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/predict.py) (Inference workflow), [`src/stock_prediction/getdata.py`](https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/getdata.py) (Market data loading), [`src/stock_prediction/data_preprocess.py`](https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/data_preprocess.py) (Data preprocessing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_getdata_cmd["Data acquisition command<br/>[getdata.py]"]
  node_getdata["Market data loading<br/>[getdata.py]"]
  node_preprocess_cmd["Preprocessing command<br/>[data_preprocess.py]"]
  node_preprocess["Data preprocessing<br/>[data_preprocess.py]"]
  node_features["Feature engineering"]
end

subgraph group_forecast["Forecasting"]
  node_train_cmd["Training command<br/>[train.py]"]
  node_training["Training workflow<br/>[train.py]"]
  node_trainer["Training engine<br/>[trainer.py]"]
  node_models["Forecast model families"]
  node_predict_cmd["Prediction command<br/>[predict.py]"]
  node_predict["Inference workflow<br/>[predict.py]"]
  node_target["Target definition<br/>[target.py]"]
end

subgraph group_ops["Configuration and evaluation"]
  node_config["Application configuration<br/>[app_config.py]"]
  node_diagnostics["Diagnostics and metrics<br/>[diagnostics.py]"]
  node_metrics["Forecast metrics<br/>[metrics.py]"]
  node_common["Shared runtime utilities<br/>[common.py]"]
end

subgraph group_text["Text classification"]
  node_bert_preprocess["Text data preparation"]
  node_bert_train["BERT sentiment training<br/>[bert_train.py]"]
end

node_researcher(("Researcher"))
node_market["Market data APIs"]
node_artifacts["Data and model artifacts"]

node_researcher -->|"requests data"| node_getdata_cmd
node_getdata_cmd -->|"runs acquisition"| node_getdata
node_getdata -->|"fetches quotes"| node_market
node_getdata -->|"saves data"| node_artifacts
node_researcher -->|"prepares data"| node_preprocess_cmd
node_preprocess_cmd -->|"runs preprocessing"| node_preprocess
node_preprocess -->|"engineers features"| node_features
node_preprocess -->|"writes processed data"| node_artifacts
node_researcher -->|"starts training"| node_train_cmd
node_train_cmd -->|"runs training"| node_training
node_training -->|"delegates training"| node_trainer
node_training -->|"selects model"| node_models
node_training -->|"saves weights and normalization"| node_artifacts
node_researcher -->|"requests forecast"| node_predict_cmd
node_predict_cmd -->|"runs inference"| node_predict
node_predict -->|"loads model"| node_models
node_predict -->|"reads data and weights"| node_artifacts
node_predict -->|"uses target definition"| node_target
node_training -->|"uses settings"| node_config
node_predict -->|"uses settings"| node_config
node_training -->|"checks training"| node_diagnostics
node_diagnostics -->|"uses metrics"| node_metrics
node_researcher -->|"prepares text data"| node_bert_preprocess
node_bert_preprocess -->|"provides prepared data"| node_bert_train
node_bert_train -->|"saves model"| node_artifacts
node_getdata -->|"uses shared utilities"| node_common
node_predict -->|"uses shared utilities"| node_common

click node_getdata_cmd "https://github.com/kittencn/stock_prediction/blob/master/scripts/getdata.py"
click node_getdata "https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/getdata.py"
click node_preprocess_cmd "https://github.com/kittencn/stock_prediction/blob/master/scripts/data_preprocess.py"
click node_preprocess "https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/data_preprocess.py"
click node_features "https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/feature_engineering.py"
click node_train_cmd "https://github.com/kittencn/stock_prediction/blob/master/scripts/train.py"
click node_training "https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/train.py"
click node_trainer "https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/trainer.py"
click node_models "https://github.com/kittencn/stock_prediction/tree/master/src/stock_prediction/models"
click node_predict_cmd "https://github.com/kittencn/stock_prediction/blob/master/scripts/predict.py"
click node_predict "https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/predict.py"
click node_target "https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/target.py"
click node_config "https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/app_config.py"
click node_diagnostics "https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/diagnostics.py"
click node_metrics "https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/metrics.py"
click node_bert_preprocess "https://github.com/kittencn/stock_prediction/blob/master/src/bert/bert_data_preprocess.py"
click node_bert_train "https://github.com/kittencn/stock_prediction/blob/master/src/bert/bert_train.py"
click node_common "https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/common.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_getdata_cmd,node_getdata,node_preprocess_cmd,node_preprocess,node_features toneBlue
class node_train_cmd,node_training,node_trainer,node_models,node_predict_cmd,node_predict,node_target toneAmber
class node_config,node_diagnostics,node_metrics,node_common,node_market toneMint
class node_bert_preprocess,node_bert_train toneRose
class node_researcher,node_artifacts toneIndigo
```

## Components

### Data preparation

- [Data acquisition command](https://github.com/kittencn/stock_prediction/blob/master/scripts/getdata.py): `scripts/getdata.py`
- [Market data loading](https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/getdata.py): `src/stock_prediction/getdata.py`
- [Preprocessing command](https://github.com/kittencn/stock_prediction/blob/master/scripts/data_preprocess.py): `scripts/data_preprocess.py`
- [Data preprocessing](https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/data_preprocess.py): `src/stock_prediction/data_preprocess.py`
- [Feature engineering](https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/feature_engineering.py): `src/stock_prediction/feature_engineering.py`

### Forecasting

- [Training command](https://github.com/kittencn/stock_prediction/blob/master/scripts/train.py): `scripts/train.py`
- [Training workflow](https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/train.py): `src/stock_prediction/train.py`
- [Training engine](https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/trainer.py): `src/stock_prediction/trainer.py`
- [Forecast model families](https://github.com/kittencn/stock_prediction/tree/master/src/stock_prediction/models): `src/stock_prediction/models`
- [Prediction command](https://github.com/kittencn/stock_prediction/blob/master/scripts/predict.py): `scripts/predict.py`
- [Inference workflow](https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/predict.py): `src/stock_prediction/predict.py`
- [Target definition](https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/target.py): `src/stock_prediction/target.py`

### Configuration and evaluation

- [Application configuration](https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/app_config.py): `src/stock_prediction/app_config.py`
- [Diagnostics and metrics](https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/diagnostics.py): `src/stock_prediction/diagnostics.py`
- [Forecast metrics](https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/metrics.py): `src/stock_prediction/metrics.py`
- [Shared runtime utilities](https://github.com/kittencn/stock_prediction/blob/master/src/stock_prediction/common.py): `src/stock_prediction/common.py`

### Text classification

- [Text data preparation](https://github.com/kittencn/stock_prediction/blob/master/src/bert/bert_data_preprocess.py): `src/bert/bert_data_preprocess.py`
- [BERT sentiment training](https://github.com/kittencn/stock_prediction/blob/master/src/bert/bert_train.py): `src/bert/bert_train.py`

### Other components

- **Researcher**
- **Market data APIs**
- **Data and model artifacts**

## Connections

- Researcher → Data acquisition command: requests data
- Data acquisition command → Market data loading: runs acquisition
- Market data loading → Market data APIs: fetches quotes
- Market data loading → Data and model artifacts: saves data
- Researcher → Preprocessing command: prepares data
- Preprocessing command → Data preprocessing: runs preprocessing
- Data preprocessing → Feature engineering: engineers features
- Data preprocessing → Data and model artifacts: writes processed data
- Researcher → Training command: starts training
- Training command → Training workflow: runs training
- Training workflow → Training engine: delegates training
- Training workflow → Forecast model families: selects model
- Training workflow → Data and model artifacts: saves weights and normalization
- Researcher → Prediction command: requests forecast
- Prediction command → Inference workflow: runs inference
- Inference workflow → Forecast model families: loads model
- Inference workflow → Data and model artifacts: reads data and weights
- Inference workflow → Target definition: uses target definition
- Training workflow → Application configuration: uses settings
- Inference workflow → Application configuration: uses settings
- Training workflow → Diagnostics and metrics: checks training
- Diagnostics and metrics → Forecast metrics: uses metrics
- Researcher → Text data preparation: prepares text data
- Text data preparation → BERT sentiment training: provides prepared data
- BERT sentiment training → Data and model artifacts: saves model
- Market data loading → Shared runtime utilities: uses shared utilities
- Inference workflow → Shared runtime utilities: uses shared utilities
