Machine learning for markets

LSTM and sequence models

4 min

Standard neural networks treat each input independently and have no notion of order. But a price history is a sequence — the order is the information. Recurrent neural networks (RNNs), and especially the LSTM (Long Short-Term Memory), are built to model sequences, and the LSTM is the model ForecastingStocks uses for its longer-horizon forecasts.

What makes an LSTM different

An LSTM processes a sequence one step at a time while maintaining a memory (a 'cell state') that carries information forward. Crucially, it has learnable gates that decide:

  • what new information to store,
  • what old information to forget,
  • what to output at each step.

This gating lets it remember relevant context over long spans — for instance, that volatility spiked twenty days ago — while discarding noise. Plain RNNs struggle with long memory because the learning signal fades over many steps (the 'vanishing gradient'); the LSTM's gates were invented precisely to fix that.

Why it suits price data

Markets have memory: volatility clustering, momentum, regime persistence. An LSTM can in principle learn these temporal dependencies directly from raw return sequences, without a human hand-coding indicators.

The honest caveat — even for our own model

The same dangers from the previous lesson apply with full force, plus one more: it is dangerously easy to leak future information into a sequence model through careless windowing or scaling, producing a backtest that cannot be reproduced live. ForecastingStocks treats its LSTM output as one probabilistic input among several, never a guarantee — and every forecast on the platform should be read that way. A model that fit the past is not a promise about the future.

Finished reading?
Risk disclaimer

This content is for educational and informational purposes only and is not investment, financial, tax or legal advice. Trading and investing carry risk, including the possible loss of capital. Any performance shown by third-party tools is hypothetical and not a promise of future results. Do your own research and consider professional advice before making any decision.