This project implements and compares two deep learning models — LSTM and GRU — to predict next-day Open and Close prices from historical OHLCV data. Models are built with PyTorch and trained on rolling 30-day sequences.
- LSTM (Long Short-Term Memory): Captures long-term dependencies in time series.
- GRU (Gated Recurrent Unit): Lighter alternative with fewer parameters.
- Data preprocessing with pandas, NumPy, scikit-learn
- Sequence windowing (past 30 days → next-day prediction)
- Training & inference with PyTorch
- Saved artifacts:
lstm_model_weights.pth,scaler.save - Performance comparison using MSE (per target)
- Visualizations of actual vs. predicted prices
- Ready to integrate with Streamlit (this repo) or Flask
| Model | MSE (Open) | MSE (Close) |
|---|---|---|
| LSTM | 10.7422 | 16.8829 |
| GRU | 62.9326 | 50.9872 |
LSTM outperformed GRU in both Open and Close price predictions.
.
├── README.md
├── requirements.txt
├── app.py # Streamlit app
├── model.py # LSTM/GRU definitions
├── lstm_model_weights.pth # trained weights (PyTorch state_dict)
├── scaler.save # fitted MinMaxScaler (joblib)
└── forecasting_notebook.ipynb # training/experiments (optional)
- Install dependencies
pip install -r requirements.txt- Run the Streamlit app
streamlit run app.py- Upload a CSV with columns:
Open, High, Low, Close, Volume
(Feature order must match the scaler used during training.)
Actual Open: 111.20, Pred Open: 110.68 | Actual Close: 109.14, Pred Close: 111.37
Actual Open: 110.60, Pred Open: 110.17 | Actual Close: 110.73, Pred Close: 111.18
...
- Load
lstm_model_weights.pthandscaler.save - Deploy with Streamlit (this repo) or Flask
- Optional: containerize with Docker for cloud deployment
- Python
- PyTorch
- NumPy & Pandas
- scikit-learn
- Matplotlib & Seaborn
Try the model live on Streamlit: Stock Price Forecaster Demo
Dante Santurian – University of Michigan