# yacoubb/stock-trading-ml architecture

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

- Interactive diagram: https://gitdiagram.com/yacoubb/stock-trading-ml
- Repository: https://github.com/yacoubb/stock-trading-ml

## Overview

This repository is a stock-price prediction and trading prototype. Its main workflow downloads price history, transforms it into training examples, trains and evaluates either an OHLCV-only or technical-indicator model, then loads the saved technical model to generate buy/sell signals and estimate earnings. The README documents this sequence. The excerpts show the model and data-processing calls; the download-to-training handoff is documented rather than directly wired in code. The repository does not show a live brokerage integration.

Main entry points: [`trading_algo.py`](https://github.com/yacoubb/stock-trading-ml/blob/master/trading_algo.py) (Signal and earnings analysis), [`util.py`](https://github.com/yacoubb/stock-trading-ml/blob/master/util.py) (Dataset preparation), [`save_data_to_csv.py`](https://github.com/yacoubb/stock-trading-ml/blob/master/save_data_to_csv.py) (History downloader), [`basic_model.py`](https://github.com/yacoubb/stock-trading-ml/blob/master/basic_model.py) (OHLCV model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Market data"]
  node_downloader["History downloader"]
  node_csv["Price history CSV"]
  node_preprocess["Dataset preparation<br/>[util.py]"]
end

subgraph group_modeling["Modeling"]
  node_basic["OHLCV model<br/>[basic_model.py]"]
  node_technical["Indicator model<br/>[tech_ind_model.py]"]
  node_basicartifact["Basic model file"]
  node_technicalartifact["Technical model file"]
end

subgraph group_trading["Trading analysis"]
  node_trader["Signal and earnings analysis<br/>[trading_algo.py]"]
  node_plots["Prediction plots<br/>[trading_algo.py]"]
end

node_user(("User"))
node_alphavantage{{"Alpha Vantage"}}

node_user -->|"requests history"| node_downloader
node_downloader -->|"fetches prices"| node_alphavantage
node_downloader -->|"writes CSV"| node_csv
node_csv -->|"provides history"| node_preprocess
node_user -->|"trains model"| node_basic
node_user -->|"trains model"| node_technical
node_basic -->|"calls dataset prep"| node_preprocess
node_technical -->|"calls dataset prep"| node_preprocess
node_basic -->|"saves model"| node_basicartifact
node_technical -->|"saves model"| node_technicalartifact
node_user -->|"runs analysis"| node_trader
node_trader -->|"loads model"| node_technicalartifact
node_trader -->|"calls dataset prep"| node_preprocess
node_trader -->|"plots results"| node_plots

click node_downloader "https://github.com/yacoubb/stock-trading-ml/blob/master/save_data_to_csv.py"
click node_preprocess "https://github.com/yacoubb/stock-trading-ml/blob/master/util.py"
click node_basic "https://github.com/yacoubb/stock-trading-ml/blob/master/basic_model.py"
click node_technical "https://github.com/yacoubb/stock-trading-ml/blob/master/tech_ind_model.py"
click node_trader "https://github.com/yacoubb/stock-trading-ml/blob/master/trading_algo.py"
click node_plots "https://github.com/yacoubb/stock-trading-ml/blob/master/trading_algo.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_downloader,node_csv,node_preprocess,node_user toneBlue
class node_basic,node_technical,node_basicartifact,node_technicalartifact toneAmber
class node_trader,node_plots toneMint
class node_alphavantage toneIndigo
```

## Components

### Market data

- [History downloader](https://github.com/yacoubb/stock-trading-ml/blob/master/save_data_to_csv.py): `save_data_to_csv.py`
- **Price history CSV**
- [Dataset preparation](https://github.com/yacoubb/stock-trading-ml/blob/master/util.py): `util.py`

### Modeling

- [OHLCV model](https://github.com/yacoubb/stock-trading-ml/blob/master/basic_model.py): `basic_model.py`
- [Indicator model](https://github.com/yacoubb/stock-trading-ml/blob/master/tech_ind_model.py): `tech_ind_model.py`
- **Basic model file**
- **Technical model file**

### Trading analysis

- [Signal and earnings analysis](https://github.com/yacoubb/stock-trading-ml/blob/master/trading_algo.py): `trading_algo.py`
- [Prediction plots](https://github.com/yacoubb/stock-trading-ml/blob/master/trading_algo.py): `trading_algo.py`

### Other components

- **User**
- **Alpha Vantage**

## Connections

- User → History downloader: requests history (evidence: `README.md`)
- History downloader → Alpha Vantage: fetches prices (evidence: `save_data_to_csv.py`)
- History downloader → Price history CSV: writes CSV (evidence: `save_data_to_csv.py`)
- Price history CSV → Dataset preparation: provides history (evidence: `README.md`)
- User → OHLCV model: trains model (evidence: `README.md`)
- User → Indicator model: trains model (evidence: `README.md`)
- OHLCV model → Dataset preparation: calls dataset prep (evidence: `basic_model.py`)
- Indicator model → Dataset preparation: calls dataset prep (evidence: `tech_ind_model.py`)
- OHLCV model → Basic model file: saves model (evidence: `basic_model.py`)
- Indicator model → Technical model file: saves model (evidence: `tech_ind_model.py`)
- User → Signal and earnings analysis: runs analysis (evidence: `README.md`)
- Signal and earnings analysis → Technical model file: loads model (evidence: `trading_algo.py`)
- Signal and earnings analysis → Dataset preparation: calls dataset prep (evidence: `trading_algo.py`)
- Signal and earnings analysis → Prediction plots: plots results (evidence: `trading_algo.py`)
