Autocorrelation
The correlation of a series with a delayed copy of itself. If it is not zero, the past tells you something about the future.
01The formula
- the sample autocorrelation at lag k: how much the series resembles itself k steps earlier
- the value of the series at time t, such as a daily return
- the average of the series
- the length of the series
- the lag-1 autocorrelation of an AR(1) process
02See it move
03Where it is used
- Quant researcherChecks returns for autocorrelation: positive means momentum, negative means reversal, both are tradable.
- Market makerSees negative lag-1 autocorrelation in trade prices from the bounce between bid and ask, and does not mistake it for a signal.
- Risk managerCorrects volatility and Sharpe ratios for autocorrelated returns, which make smoothed assets look safer than they are.
04Why traders use it
A strategy that forecasts from past returns is betting that autocorrelation is not zero. Measuring it, and knowing how big it can be by chance, is the first test of any such idea.
05Worked example
For a series of 250 points with true φ = 0.60, the sample lag-1 autocorrelation is 0.623 against a theory value of 0.600. At lag 5 it is 0.074. Anything inside ±0.124 could be pure noise.
06How it is built
- Shift the series by steps and pair each value with the one steps before it.
- Compute the covariance of the pairs and divide by the variance of the series: that is .
- For an AR(1), , so and : it fades geometrically.
- If the true autocorrelation is zero, is roughly normal with standard deviation , which gives the band.
07The common mistake
Testing twenty lags and celebrating the one outside the band. At 95% confidence, about one lag in twenty will poke out by chance alone.
08In Python and LaTeX
import numpy as np from statsmodels.tsa.stattools import acf rng = np.random.default_rng(7) phi, n = 0.6, 250 x = np.zeros(n) for t in range(1, n): x[t] = phi * x[t - 1] + rng.standard_normal() d = x - x.mean() print(np.isclose(np.sum(d[1:] * d[:-1]) / np.sum(d * d), acf(x, nlags=1)[1])) # True print(round(1.96 / np.sqrt(n), 3)) # 0.124 noise band
\hat\rho_k = \frac{\sum_{t=k+1}^{n} (x_t - \bar x)(x_{t-k} - \bar x)}{\sum_{t=1}^{n} (x_t - \bar x)^2}, \qquad \text{AR(1): } \rho_k = \phi^k09Where it fits
Rather not code the maths yourself? Describe your trading idea and let AI build the bot.
Build a bot with AgenKitThe worked example and the model run the same code, so every number matches. Models simplify markets on purpose. This is education, not financial advice.