STABLE  ·  Case Study 04  ·  Deep Learning / Finance

TCS STOCK LSTM

A deep learning LSTM architecture trained on 10 years of TCS historical data, using a 60-day sliding window to forecast next-day stock price trends.

● STABLE V.1.2.0 Model Trained TensorFlow LSTM Finance
0.0024
Test MSE
60d
Lookback Window
150
Training Epochs

Capturing Long-Range Temporal Dependencies

Stock price prediction is one of the canonical time-series problems in applied deep learning. Most beginner implementations reach for simple linear regression on a few recent candles — which captures noise, not signal. Prices are shaped by trends that unfold over weeks, not just the last few bars.

The challenge was building a model that genuinely captures long-range temporal dependencies in price movements. LSTM networks were designed for exactly this — they maintain a cell state that can carry relevant information forward across many timesteps, making them theoretically well-suited for multi-week price pattern learning on a single stock.

Model Design

10 years of TCS daily OHLCV data was fetched via Yahoo Finance, MinMax scaled per feature, then converted into 60-day sliding window sequences. Each sequence maps to a single next-day closing price. The LSTM stack uses three layers with dropout regularisation between each to prevent overfitting on the relatively small dataset.

10yr TCS OHLCV Data
Data Preprocessing
MinMaxScaler
60-Day Sliding Window Sequences
LSTM Layer 1
LSTM Layer 2
LSTM Layer 3
Dropout (0.2)
Dense Output Layer
Next-Day Price Prediction
Evaluation — MSE · RMSE · R²

Training used Adam optimiser with early stopping — patience of 10 epochs monitoring validation loss. This prevented the model from overfitting past the natural convergence point around epoch 130–150 on typical runs.

Built With

🐍 Python 3.11 🧠 TensorFlow / Keras 📐 LSTM (3 Layers) 🐼 Pandas 🔢 NumPy 📊 Matplotlib ⚙️ Scikit-learn (MinMaxScaler) 📈 Yahoo Finance API

What the Model Achieved

What I'd Do Differently

Lesson 01

Normalisation is critical for LSTM convergence

Raw price values in the thousands caused gradient instability during early training runs. Applying MinMaxScaler per feature to the [0, 1] range before sequence construction stabilised convergence immediately.

Lesson 02

Lookback window length requires empirical tuning

There's no theoretical answer to "how many days." Too short (15 days) failed to capture weekly seasonality. Too long (120 days) introduced pre-earnings noise that hurt validation loss. 60 days was the empirical sweet spot for TCS specifically.

Lesson 03

Dropout + early stopping are non-negotiable

Without dropout, the model memorised the training curve and generalised poorly. Without early stopping, it continued "learning" noise after epoch 140. Both together are the minimum viable regularisation for finance LSTM work.

Lesson 04

MSE ≠ tradeable signal

Low MSE doesn't mean the model is useful for trading. Direction accuracy — predicting up vs. down — matters far more than minimising the squared price error. I'd add a direction accuracy metric to every evaluation run in future work.

Want to explore the model?

The full training notebook, data pipeline, and evaluation plots are on GitHub. Great starting point for any time-series deep learning project.

// Other Case Studies ← AI Trading Coach NeuraFlow AI →