Stock Price Predictor

Developed a full-stack machine learning application that predicts future stock prices using a Long Short-Term Memory (LSTM) neural network. Historical financial data is ingested from the Alpha Vantage API, preprocessed through normalization and sliding window techniques, and then used to train a multi-layer LSTM implemented in PyTorch. The model was optimized with dropout regularization, Adam optimization, learning-rate scheduling, and evaluation on train/validation splits to reduce overfitting and improve generalization.

The backend is built with Flask, serving both the model and a REST API, while visualizations (price history, training vs. validation splits, loss curves, and prediction overlays) are generated dynamically and delivered through a responsive web interface. The web app also returns a brief company summary along with the next-day stock price prediction, based on the last 20 days of input data and trained over more than 60 years of historical market data. This project demonstrates end-to-end skills in data engineering, deep learning, model optimization, and full-stack deployment of ML models.

The Model Implementation

The predictive engine of this project is a multi-layer Long Short-Term Memory (LSTM) neural network, trained on over 60 years of historical daily stock data. To capture temporal dependencies, the model was trained on sliding windows of 25 days, predicting the closing price for the next day.

The architecture was optimized using hyperparameter tuning (layers, hidden units, learning rate, and dropout) and enhanced with attention mechanisms to improve the weighting of significant past timesteps. Training leveraged the Adam optimizer with scheduled learning-rate decay, ensuring both stability and convergence.

The performance is demonstrated in the plots:

  • Train vs Validation shows the model closely tracking actual price trends.

  • Zoomed Validation highlights the fine-grained alignment between predicted and real values.

  • Next-Day Prediction illustrates how the model generalizes to unseen data, providing accurate short-term forecasts.

The close match between predicted and actual prices indicates that the model effectively learns temporal patterns in financial data, producing accurate and efficient forecasts suitable for decision support.

This web app provides a clean stock summary and prediction interface. The company details (sector, industry, market cap, and P/E ratio) are retrieved from the Alpha Vantage API, while the search bar is designed in HTML with integrated autocomplete suggestions for ticker symbols. The next-day predicted closing price is displayed prominently, generated by the underlying LSTM model, with the layout styled for clarity and easy user interaction. Matplotlib is dynamically rendered on the frontend through Jinja2 templates, allowing users to search tickers, view summaries, and access next-day predictions in a seamless web interface.

GitHub Repo
Next
Next

ML Models