# LSTM / Recurrent Networks

A Machine Learning reference entry (Learned models) in the LuxAlgo Library: explained, not implemented as a chart indicator.

## What are LSTMs and recurrent networks?

Recurrent networks are [neural networks](https://www.luxalgo.com/library/concept/neural-networks/) built for sequences: they process one step at a time while carrying a hidden state forward, so earlier bars influence how later bars are read. The LSTM (long short-term memory), introduced by Hochreiter and Schmidhuber in 1997, adds gated memory cells that learn what to keep, update, and forget, countering the vanishing-gradient problem that made plain recurrent nets forget long-range context. The GRU is a lighter variant with similar behavior.

In financial machine learning, LSTMs were the default sequence model of the mid-2010s wave: fed windows of returns and engineered inputs (see [feature engineering](https://www.luxalgo.com/library/concept/feature-engineering/)) to predict next-period direction, return, or volatility. What the network is asked to predict matters as much as the architecture, which is the territory of [label definition and prediction horizon](https://www.luxalgo.com/library/concept/label-definition-and-prediction-horizon/).

The honest track record is sobering. On liquid markets, LSTMs regularly fail to beat much simpler baselines once evaluated strictly out of sample with costs, and attention-based architectures have displaced them across most of the research literature. They remain a reasonable tool where sequence memory genuinely helps, notably volatility, which is far more persistent than returns.

## Why there's no indicator for this

An LSTM is not a formula; it is a trained artifact. Producing one requires machinery no charting engine contains: a large labeled dataset, time-ordered train/validation/test splits, feature scaling fitted only on past data, compute-heavy optimization, and scheduled retraining as markets drift, the problem [online and incremental learning](https://www.luxalgo.com/library/concept/online-incremental-learning/) exists to manage. A chart script sees one symbol's loaded history and none of that pipeline.

Scripts marketed as on-chart LSTMs therefore do one of two things. Either they ship tiny frozen weights, meaning you run a stale model trained at an unknown time on unknown data, or they fit themselves to the visible chart history, which is in-sample curve fitting that looks prophetic backward and fails forward. Neither delivers the validated out-of-sample behavior that justifies using a learned model at all.

## How traders use it

- Volatility and direction forecasting research, where LSTM outputs are benchmarked against classical models; volatility is the friendlier target because it clusters and persists.
- Learned compression: a trained network's hidden state summarizes a sequence into a vector that feeds downstream models or an [ensemble vote](https://www.luxalgo.com/library/concept/ensemble-voting-of-signals/).
- Regime-aware stacks: pipelines gate network outputs by market state from [Markov-switching models](https://www.luxalgo.com/library/concept/hidden-markov-markov-switching-regimes/), trusting the net only in regimes resembling its training data.
- Probability outputs: classification variants emit scores that pass through [calibration](https://www.luxalgo.com/library/concept/logistic-signal-calibration/) before anyone sizes a position off them.

## LSTMs vs adjacent sequence models

- **Neural Networks** (https://www.luxalgo.com/library/concept/neural-networks/): Feedforward nets map a fixed snapshot of inputs to an output; recurrent nets carry state across time steps, buying sequence memory at the cost of harder, slower training.
- **Hidden Markov / Markov-switching Regimes** (https://www.luxalgo.com/library/concept/hidden-markov-markov-switching-regimes/): Both model sequences through hidden state, but an HMM uses a few interpretable discrete states estimated statistically, while an LSTM learns thousands of opaque continuous parameters.

## FAQ

### Are LSTMs good at predicting stock prices?

Published results are mixed at best. Prices are noisy and non-stationary, so the long-memory advantage rarely survives out-of-sample testing after costs. Results improve on volatility and on tasks with richer inputs than bare price.

### Why do LSTM backtests look great and then fail live?

Usually leakage (scaling or tuning touched future data), overfitting a small noisy sample, or a regime the frozen weights never saw. Strict walk-forward evaluation catches much of this beforehand.

### LSTM or GRU?

For most financial tasks the difference is minor. GRUs train faster with fewer parameters and reach similar accuracy; data quality and labeling choices dominate the architecture choice.

### Have transformers replaced LSTMs?

In research, largely yes: attention handles long context better and trains in parallel. LSTMs persist where datasets are small or where latency and simplicity matter.

## Related concepts

- Kernel Regression: https://www.luxalgo.com/library/concept/kernel-regression/
- Gaussian Process Regression: https://www.luxalgo.com/library/concept/gaussian-process-regression/
- Kernel Density Estimation: https://www.luxalgo.com/library/concept/kernel-density-estimation/
- Support Vector Machines: https://www.luxalgo.com/library/concept/support-vector-machines/
- Decision Trees: https://www.luxalgo.com/library/concept/decision-trees/
- Gradient Boosting: https://www.luxalgo.com/library/concept/gradient-boosting/
- Random Forest: https://www.luxalgo.com/library/concept/random-forest/
- Neural Networks: https://www.luxalgo.com/library/concept/neural-networks/
- Bayesian Classifiers: https://www.luxalgo.com/library/concept/bayesian-classifiers/
- Self-organizing Maps: https://www.luxalgo.com/library/concept/self-organizing-maps/

---

Source: https://www.luxalgo.com/library/concept/lstm-recurrent-networks/ (LuxAlgo Library, the encyclopedia of trading & technical analysis). Free to use with attribution: https://www.luxalgo.com/library/license/