Deep learning · Completed
Stock price prediction with LSTM
A Flask API and React dashboard that runs a Keras LSTM model on historical prices, compares predictions with actual closes, and charts moving-average trends.

Overview
Enter a stock symbol and the app downloads its full price history, runs a long short-term memory (LSTM) network over it, and shows how closely the model’s predictions follow the real closing prices. Alongside the prediction it charts exponential moving averages, the indicators traders use to read short- and long-term trends.
The project has two parts: a Python API that handles data and inference, and a React single-page app for the dashboard.
How it works
- Data. The API downloads daily prices from January 2000 to today with yfinance. It works for any symbol Yahoo Finance lists, such as
AAPL,MSFT, orPOWERGRID.NS. - Trend indicators. It computes 20-, 50-, 100- and 200-day exponential moving averages of the closing price and renders two charts: a short-term view (20 and 50 days) and a long-term view (100 and 200 days).
- Train/test split. Closing prices are split in time order, 70% for training and the most recent 30% for testing. No shuffling, so the model is always evaluated on data that comes after what it learned from.
- Sequences. Prices are scaled to the 0–1 range with scikit-learn’s
MinMaxScaler. Each input is a sliding window of the previous 100 days, and the target is the next day’s close. The last 100 training days are prepended to the test set so the first test prediction has a full window. - Prediction. A pretrained Keras LSTM model, saved as
stock_model.h5, predicts each test day from its 100-day window. Predictions are scaled back to prices and plotted against the actual closes. - Response. The API returns summary statistics, the three chart images, a down-sampled series of dates with actual and predicted prices for the interactive chart, and a CSV download of the raw dataset.
Architecture
| Part | Technology | Responsibility |
|---|---|---|
| API | Flask, Flask-CORS | POST /api/predict endpoint, serves charts and datasets |
| Model | TensorFlow, Keras (LSTM) | Next-day price prediction from a 100-day window |
| Data | yfinance, pandas, NumPy, scikit-learn | Download, moving averages, scaling, sliding windows |
| Charts | Matplotlib | Trend and prediction charts saved as images |
| Dashboard | React 19, Vite, Tailwind CSS, Axios | Symbol search, statistics table, charts, dataset download |
Limitations and next steps
- One step ahead, not a forecast. Each prediction uses the real prices of the previous 100 days, so the chart shows how well the model tracks next-day prices. It does not forecast weeks into the future.
- Scaling. The scaler is refit on the test window, and predictions are converted back by dividing by the scale factor alone, so the scaler’s minimum offset is not restored. Reusing the training scaler with
inverse_transformwould make the comparison stricter. - Metrics. Adding error metrics such as RMSE and MAE next to the chart would make results comparable between stocks and model versions.
- Training code. The repository ships the trained model but not the training script. Publishing the notebook would make the model reproducible.
This is a learning project about time-series modeling, not financial advice.
Run it locally
git clone https://github.com/kazisalon/Stock-Price-Prediction-Using-LSTM.git
cd Stock-Price-Prediction-Using-LSTM
# API (port 5000)
cd backend
pip install -r requirements.txt
python app.py
# Dashboard (in a second terminal)
cd frontend
npm install
npm run dev