Skip to content
All projects
Google Stock Price Prediction using LSTM and PyTorch
Machine Learningcompleted

Google Stock Price Prediction using LSTM and PyTorch

May 20232 months
2 frameworksthe same LSTM built in Keras and in PyTorch, to learn the model from the inside out

Overview

This was my deep dive into sequence models. The goal was never to get rich predicting GOOG — it was to understand LSTMs by building the same forecaster two ways, in Keras and in PyTorch, and watching where they agreed and diverged. It covers the full loop: pull historical prices, engineer features, train, and evaluate against held-out data.

Tech Stack

backend
PyTorchKeras
other
PandasMatplotlibyfinance

Challenges

  • Scaling and cleaning noisy financial time-series so a model could learn from it.
  • Choosing features that actually carry signal — and dropping the ones that don't.
  • Tuning architecture and hyperparameters without overfitting to the past.
  • Resisting the classic trap: a model that quietly "predicts" yesterday and looks great on a chart.

Solution

Prices were scaled with MinMaxScaler and enriched with moving averages and daily returns. I built matched LSTM models in Keras and PyTorch, used dropout and early stopping to fight overfitting, then compared them on identical splits with line and candlestick visualizations — to sanity-check predictions rather than trust a single loss number.

Outcome

Both models tracked the broad trend reasonably on unseen data, but the real payoff was intuition: I came away understanding why naive price prediction is so seductive and so misleading, and how much of "good results" in time-series is really data leakage wearing a disguise.

What I'd do differently

Predicting raw price was the wrong target — it makes a lagged copy look brilliant. I'd predict returns instead of price, use walk-forward validation rather than a single split, and judge it on directional accuracy and a trading-style backtest, not RMSE on a normalized chart.

Built with

PyTorchKerasyfinanceMinMaxScalerMatplotlibPandas