A two-layer LSTM that learns from historical closing prices and predicts the next day's close, with a Streamlit app for interactive use and a script for repeatable runs. A learning project, written to be read and extended.
Prices are a sequence, so the model needs windows of history, not isolated rows.
Closing prices are scaled to 0 to 1 and cut into overlapping windows, giving the 3-dimensional input an LSTM expects.
A stacked LSTM with dropout learns from the windows and saves its best weights to disk.
The same code runs from a Streamlit app with sliders and from a plain script, so results can be repeated.
Each stage is its own small module in src/, shared by the app and the script.
Everything the README describes, and what the code does.
Choose a ticker, a date preset or custom range, the lookback window (30 to 100 days) and the number of epochs, then train and predict.
The downloaded price history and an actual versus predicted plot for the test period.
The last window of prices is scaled, passed through the model and converted back to a dollar value.
The best model weights are written to model/lstm_model.h5 for reuse.
main.py trains, evaluates and prints the next-day price without the UI.
Ticker, dates, window and epochs are parameters, and the architecture lives in one file.
A standard Python data-science stack.
| Layer | Technology | Why |
|---|---|---|
| Data | yfinance | Free historical prices from Yahoo Finance. |
| Model | TensorFlow / Keras | A Sequential LSTM is short to define and easy to read. |
| Scaling | scikit-learn MinMaxScaler | LSTMs train better on inputs scaled to a small range, and the scaler converts predictions back. |
| Interface | Streamlit | A working UI with sliders in a few lines of Python. |
| Plots | Matplotlib | Actual versus predicted charts. |
Small choices that keep the project understandable.
Data loading, model building, training and prediction live in src/, so the Streamlit app and main.py cannot drift apart.
Dropout of 0.2 after each LSTM layer reduces overfitting to the training history.
Training saves only the best weights by training loss, so the saved model is not just the last epoch.
The predictor reshapes its input to whatever window the model was trained with, so changing the lookback slider does not break next-day prediction.
The practical details of sequence models.
An LSTM needs input shaped as samples, time steps and features. Getting windows, reshaping and inverse scaling consistent took care at every stage.
✓ Explicit reshape at each stepIf the lookback slider differs between training and prediction, the shapes disagree. The predictor reshapes dynamically to the window length in use.
✓ Dynamic reshapeRaw scaled numbers mean little. Inverse scaling plus an actual versus predicted chart makes the model's behaviour visible.
✓ Inverse transform and plotsWhat the project shows.
Stock prices are hard to predict, and this project does not claim otherwise.
This is an educational model. A model that tracks yesterday's price closely can look accurate while adding no real predictive value.
Fit the scaler on the training split only, use walk-forward validation, report RMSE and MAE, and compare against a naive "tomorrow equals today" baseline.
Add features such as volume and indicators, try multi-step forecasts, and track experiments.
I'm open to full-time roles and project work in AI engineering, full-stack development, and backend systems.