Skip to content
All library documents

LSTM Models for Stock Price Forecasting and Trading

Article BigQuant

Summary

This tutorial describes using a recurrent LSTM network to forecast stock closing prices from recent price history. It forms rolling sequences from historical data, reshapes them into the three-dimensional input expected by the network, and separates each sequence into inputs and the next closing price as the target. The model uses two LSTM layers with dropout, followed by a dense output layer, and is trained with mean squared error and RMSprop. Training settings include batch size, epochs, and a validation split.

For forecasts beyond one step, the method feeds each predicted close back into the next input alongside recent observed prices, allowing it to generate a sequence. The proposed backtest buys when the forecast period ends above its starting close; otherwise it stays out or exits. The author reports that results were not especially good and suggests parameter tuning as a possible factor. No quantitative performance evidence, transaction-cost analysis, or safeguards against time-series leakage are provided, so the example is instructional rather than evidence of a robust trading edge.

Key ideas

  • LSTM networks can model sequential price data and are presented here for next-day closing-price forecasts.
  • Historical prices are organized into rolling windows, with each window's final value serving as the prediction target.
  • The network combines two LSTM layers, dropout, and a dense output trained with mean squared error.
  • Multi-step forecasts reuse previous predictions as inputs, which can compound forecast errors.
  • The suggested backtest buys when the final forecasted close exceeds the first, but reported results are weak.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.