Stock Price Forecasting with LSTM
An LSTM model with attention that forecasts stock prices 1–30 days ahead, tested with walk-forward validation, with a Streamlit dashboard and Flask API.
- Status
- Prototype
- Layers
- AIData
- Used by
- A research and learning project showing how to build a data-driven forecast that is tested honestly; not an investment advice tool.
The problem
Many forecasting models look good on paper because they accidentally use future data during testing.
The solution
The pipeline lags technical indicators by a day, fits the scaler on training data only, and tests the model on a rolling basis like real conditions. Results can be explored in a Streamlit dashboard or through the API.
How it works
What happens, step by step, from the user's point of view.
- 01
Price data is fetched automatically
A stock's price and trading-volume history is downloaded from Yahoo Finance.
- 02
Indicators use past data only
The system calculates returns, volatility, momentum, and volume signals, using only data up to the previous day.
- 03
The LSTM model learns patterns
The model reads the sequence of previous days and gives more weight to the days it finds important (attention).
- 04
Tested on a rolling basis
The model trains on one period and is tested on the next, stepping forward each time. The scaler only learns from training data.
- 05
User picks stock and horizon
In the Streamlit dashboard, the user types a ticker and picks how many days ahead, up to 30.
- 06
Results appear as charts
The forecast shows up as a chart and a table. Other apps can request the same result from the Flask API.
System design
Who uses it, what they see, what works behind the scenes, and where the data lives. Read it from left to right.
1People
- Analyst or researcherChooses a ticker and how many days to forecast
2What they see
- Streamlit dashboardPrice history chart, forecast chart, and results table
- Flask APIServes forecasts to other apps from a single address
3Behind the scenes
- LSTM with attentionA PyTorch model predicts the next day's move, repeated forward
- Walk-forward validationTests the model period by period without peeking at future data
4Data and supporting tools
- Yahoo FinanceSource of stock price history via the yfinance library
- MLflowRecords every training experiment and its results
- DockerPackages the app so it runs on any machine
Key features
- LSTM with temporal attention
- Rolling walk-forward validation
- Data-leakage safeguards
- Interactive chart dashboard
- Prediction API and Docker
Built with
- Python
- PyTorch
- pandas
- scikit-learn
- yfinance
- Streamlit
- Flask
- Plotly
- MLflow
- Docker
- GitHub Actions
What the business gets
- Shows how to test a forecast honestly before anyone relies on it.
- Leaks of future data are prevented from the data-preparation stage onward.
- The same approach carries over to sales, stock, or demand forecasting.
- Results can be viewed in a dashboard or pulled into other apps through the API.
Terms on this page
- LSTM
- A type of AI model that reads data in sequence, like daily prices, and remembers patterns from earlier days.
- Walk-forward
- Testing by training on the past and predicting the next period, stepping forward each time, like using the model for real.
- Data leakage
- A mistake where the model accidentally sees future data, making test results look better than reality.
- API
- A service door that lets other apps request forecasts automatically.
Can it work for your business?
The validation approach carries over to demand, stock, or sales forecasting for your business, with honest testing before anyone relies on it.
Ask about this project