Google Stock Price Prediction using LSTM and PyTorch
An LSTM model that forecasts Google's stock price from historical data, built twice, in Keras and in PyTorch, to understand what the network was doing.

- Year
- May 2023
- Timeline
- 2 months
- Type
- Machine Learning
- Status
- Completed
2 frameworks
The same LSTM built in Keras and in PyTorch, compared on identical data splits.
Overview
This was my introduction to sequence models. The goal was to understand LSTMs, not to make money predicting GOOG, by building the same forecaster in Keras and in PyTorch and seeing where they agreed and diverged. It covers the full loop: pull historical prices, engineer features, train, and evaluate against held-out data.
The hard parts
- 01
Scaling and cleaning noisy financial time-series so a model could learn from it.
- 02
Choosing features that carry signal and dropping the ones that don't.
- 03
Tuning architecture and hyperparameters without overfitting to the past.
- 04
Avoiding the classic trap: a model that "predicts" yesterday's price and looks great on a chart.
The approach
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 against overfitting, then compared them on identical splits with line and candlestick charts, to check predictions visually instead of trusting a single loss number.
Outcome
Both models tracked the broad trend reasonably on unseen data. What I took away was an understanding of why naive price prediction looks so convincing and is so misleading, and how much of a good time-series result can be data leakage.
What I'd do differently
Predicting raw price was the wrong target, because it makes a lagged copy look brilliant. I would predict returns instead of price, use walk-forward validation instead of a single split, and judge the model on directional accuracy and a trading-style backtest, not RMSE on a normalized chart.
Stack
Like what you see?
Let's build the next one.
Hiring, or have a problem that needs this kind of engineering? I read every message myself.

