https://github.com/munjpatel/lstm-fintrends
LSTM-FinTrends is an end-to-end project showcasing stock index direction forecasting using an LSTM model with derived metrics. It demonstrates a complete workflow, from data collection with yfinance to visualization via a Flask app. Automated using GitHub Actions, this project emphasizes the setup and execution of DL in financial forecasting.
https://github.com/munjpatel/lstm-fintrends
deep-learning flask-application github-actions lstm-neural-networks yfinance
Last synced: 28 days ago
JSON representation
LSTM-FinTrends is an end-to-end project showcasing stock index direction forecasting using an LSTM model with derived metrics. It demonstrates a complete workflow, from data collection with yfinance to visualization via a Flask app. Automated using GitHub Actions, this project emphasizes the setup and execution of DL in financial forecasting.
- Host: GitHub
- URL: https://github.com/munjpatel/lstm-fintrends
- Owner: MunjPatel
- License: mit
- Created: 2024-10-21T05:05:21.000Z (12 months ago)
- Default Branch: dev
- Last Pushed: 2025-09-11T17:12:22.000Z (29 days ago)
- Last Synced: 2025-09-11T20:10:41.230Z (29 days ago)
- Topics: deep-learning, flask-application, github-actions, lstm-neural-networks, yfinance
- Language: Python
- Homepage:
- Size: 11.4 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# **LSTM-FinTrends**
**LSTM-FinTrends** is an **end-to-end project** that forecasts the **directional movement of stock indices** based on derived metrics using an **LSTM (Long Short-Term Memory)** deep learning model. The goal is not to create a live application but to **demonstrate a complete workflow** from data preprocessing to model prediction, data storage, and visualization. The project includes key technologies like **LSTM for forecasting**, **data collection using yfinance**, a **Flask web app** for rendering results, and **process automation using GitHub Actions**.
---

---
## **π Project Overview**
1. **Data Collection**: Index data is collected for different stock tickers using the `yfinance` library. The data includes derived metrics like **close price direction**, **percentage changes**, and **rolling averages**.
2. **Model**: An **LSTM model** is used for its effectiveness in capturing **temporal dependencies**, making it suitable for time series data. The model forecasts the **direction of the stock's close price** based on previous values.
3. **Storage and Visualization**: The **forecasted results**, including metrics like **confusion matrix** and **accuracy**, are stored in **JSON files**. These results are rendered through a **Flask web interface**.
4. **Automation**: **GitHub Actions** are used to automate the process as defined in `actions.yml`.## **π§° Main Technologies**
- **LSTM**: Chosen for its ability to process sequences, making it effective for **time series analysis**.
- **yfinance**: Used to fetch **historical stock data** for various tickers.
- **Flask**: Provides a **simple web interface** to display model predictions.
- **GitHub Actions**: Automates the **end-to-end pipeline**.## Project Structure
```plaintext
.
βββ app.py # Flask app for visualization
βββ lstm.py # LSTM model training and prediction
βββ preprocessing.py # Data preprocessing
βββ requirements.txt # Required Python packages
βββ tickers.json # JSON file with ticker symbols and countries
βββ logs # Folder containing logs for the whole process
β βββ models_forecast.log
βββ templates/
β βββ home.html # Template for Flask app home page
β βββ performance.html # Template for Flask app results page
βββ results/ # JSON files with model predictions for each ticker
```
---## βοΈ **Implementation Steps**
### 1. **Data Preprocessing** (`preprocessing.py`)
- Fetches historical index data using `yfinance`.
- Computes derived features (e.g., **rolling mean**, **RSI**, etc.).
- Splits data into **train/test sets** and applies **scaling**.### 2. **Model Training & Prediction** (`lstm.py`)
- Builds a multi-layer **LSTM model** with dropout regularization.
- Trains on processed time series data.
- Saves prediction outputs to **JSON**.### 3. **Visualization** (`app.py`)
- Launches a **Flask app** that allows users to:
- Select a ticker
- View actual vs. predicted movement
- Inspect **accuracy and confusion matrix**### 4. **Automation** (`actions.yml`)
- **GitHub Actions** automate daily/weekly model runs.
- Fetches fresh data β trains model β updates results.---
## Running Locally
To run this project locally:
1. **Clone the Repository**:
```bash
git clone https://github.com/MunjPatel/LSTM-FinTrends.git
cd LSTM-FinTrends
```
2. **Install Requirements**:
```bash
pip install -r requirements.txt
```
3. **Run the Flask App**:
```bash
flask run
```
The app will be available at `http://127.0.0.1:5000`, where you can view the modelβs predictions and performance metrics.## License
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.