Recurrent Neural Networks
A recurrent neural network reads a sequence one step at a time while carrying forward a running summary of everything it has seen so far, updating that summary the same way at every step so it can, in principle, remember arbitrarily far back.
Prerequisites: The Multilayer Perceptron, Backpropagation
A plain feedforward network takes one fixed-size input and produces one output; it has no notion of "before" and "after." Feed it yesterday's return and today's return as two separate inputs and it treats them as unrelated numbers, with no memory that yesterday even happened. But a lot of what matters in markets — momentum building, volatility clustering, a regime shift unfolding — is defined by order: the same return means something different depending on what came before it.
A recurrent neural network reads a sequence like a trader reading a tape: at every new print, it doesn't start from scratch — it updates a running mental summary of "what's going on," folding the new data point into everything it already believed, and that updated summary is what it carries into the next print. The summary is a fixed-size vector, and crucially the same update rule is applied at every step, so a network trained on ten-step sequences can, at least in principle, be run on sequences of any length.
The mechanics, one symbol at a time
Let be the input at time (say, today's return and volume) and be the hidden state — the running summary — after processing . The recurrence is:
In words: the new summary is a weighted combination of the previous summary and the current input, squashed through a nonlinearity exactly like an ordinary neural network layer. says how much of the old summary to carry forward and how, says how to fold in the new data, and is a baseline. The same three parameters are reused at every single timestep — this weight sharing across time is the entire point, it's what lets one trained network handle sequences of any length rather than needing a separate set of weights per position.
A prediction, if you want one at every step (or just the last one), reads off the current hidden state through an ordinary output layer: .
Worked example 1: unrolling three steps by hand
A toy RNN with scalar (1-number) state for clarity: , starting at . Inputs are three days of standardized returns: , , .
Step 1: .
Step 2: .
Step 3: .
Notice almost entirely wiped out the memory of the strong up-day at — it landed near zero because the down-day at roughly cancelled it. then builds fresh off that near-zero state. This is a small, concrete instance of what "vanishing memory" looks like: information from early steps can get diluted to near nothing by the time a few more steps have passed, purely from how the weights happen to combine.
Worked example 2: why training is a chain rule down a whole sequence
Training an RNN means backpropagating the error at the final step, , all the way back to the weights used at — a technique called backpropagation through time. Using the chain rule, the gradient of the loss at with respect to picks up a factor from every step in between:
Each factor involves multiplied by the derivative of , which is at most 1 and typically much smaller once the state is away from zero. If each factor is, say, 0.3, then over just 10 steps the compounded gradient is — essentially zero. A signal from an error 10 steps in the future has almost no way to influence weights used 10 steps ago. This is the vanishing gradient problem in concrete numbers, and it's exactly why plain RNNs struggle to learn dependencies spanning more than a handful of steps, and why gated variants (LSTM, GRU) were built specifically to give the gradient a more direct path back.
Use the explorer above to build intuition for a related idea: how a running quantity (there, a sample average; here, the hidden state) settles as more data arrives — and how sensitive that settling process is to how strongly each new point is weighted against the accumulated history.
What this means in practice
Plain ("vanilla") RNNs are rarely used directly today; gated variants — LSTM and GRU — add learned gates that let the network decide what to keep, forget, and output at each step, which mitigates (not eliminates) the vanishing gradient problem and lets them handle dependencies spanning tens to a few hundred steps. In quant work, RNNs and their gated cousins show up for order-book sequence modeling, intraday volatility forecasting, and any setting where the data truly arrives as an ordered stream rather than a fixed table. They've lost ground to attention-based models on long sequences precisely because attention gives every past step a direct connection to the present, sidestepping the step-by-step information bottleneck described above — but RNNs remain cheaper, simpler, and often good enough for shorter, streaming, low-latency settings.
An RNN processes a sequence step by step, updating one fixed-size hidden state with the same weights at every step, which lets it in principle remember arbitrarily far back — but training that memory reliably is limited in practice by vanishing gradients over long spans.
The classic confusion: assuming a trained RNN "remembers" everything in its history equally well just because the architecture allows it to, in theory, use information from any past step. In practice a plain RNN's effective memory is often just a handful of steps, because gradient signal from far in the past shrinks to near nothing during training — testing whether a model actually uses long-range information (not just whether it theoretically could) requires deliberately checking, not assuming.
Related concepts
Practice in interviews
Further reading
- Goodfellow, Bengio & Courville, Deep Learning, ch. 10
- Elman, Finding Structure in Time