4. Autocorrelation plots: ACF and PACF
Level 8: Time Series - Stationarity
An autocorrelation plot, also called a correlogram or ACF plot, is used to visualize the correlation of a series with its own lags. Applied to a price series in finance or in any other field, it provides information about the following:
1. Trend: if the price series has a strong trend, the autocorrelations at the first lags can be significantly positive, because in a trending series consecutive values tend to be closer to one another than values further apart in time.
2. Seasonality: regular patterns of rises and falls in the autocorrelation function can suggest seasonality. If there is a consistent pattern (for instance, a spike every 12 lags), it may indicate an annual seasonal effect when the data are monthly.
3. Mean reversion: in financial price series, a negative autocorrelation at the first or second lag could suggest a mean-reverting process: upward moves tend to be followed by downward moves and vice versa. This is especially relevant for strategies such as pairs trading.
4. Random walk: if the first-lag autocorrelation is close to zero and so are all the others, it suggests the series could be a random walk. In stock prices this is usually the case, and the series is better described by its returns than by its levels.
5. Stationarity: a sharp drop in the autocorrelation after a few lags suggests the series may be stationary (or that it has been made stationary through transformations). Non-stationary data, by contrast, show a slow decay of the autocorrelations.
6. Model identification: in the context of autoregressive (AR) and moving average (MA) models, the autocorrelation plot helps identify the order. If the ACF of a series cuts off sharply after p lags but the partial autocorrelation function (PACF) decays gradually, the series can be regarded as an AR(p) process.
Interpreting a correlogram calls for caution: price series in finance often show no significant autocorrelation in levels because of the efficient markets hypothesis, but their returns or changes may well show patterns; significant autocorrelation at the first lags of the returns may indicate momentum or mean reversion; and in non-stationary series the autocorrelation can stay significant for many lags, giving a false impression of a relationship. That is why, when working with financial prices, it is standard practice to analyze the autocorrelation of the returns rather than that of the prices.
autocorrelation_plot(df)
autocorrelation_plot(Re)
plt.figure(figsize=(10, 6))
pd.plotting.autocorrelation_plot(Re)
plt.xlim([0, 50])
plt.title('Autocorrelation of Re over the first 50 lags')
plt.show()When reading the ACF of financial returns there are several keys. Random walk and white noise: the raw price series usually follows something close to a random walk, with no correlation between consecutive values; once you compute returns, the series looks more like white noise, with no predictable pattern, and in ideal white noise every autocorrelation at lags greater than zero is close to zero. Significance level: the plot includes horizontal lines marking the significance threshold; if the autocorrelations fall inside those bands they are considered not significant. Short-term dependencies: in some return series you observe significant autocorrelation at the first lags, caused by volatility clustering (large changes tend to be followed by large changes and small ones by small ones) or by delayed market reactions to news. Decay patterns: a slow decay may suggest a long-memory process or an MA process. Seasonal effects: repeated spikes at regular intervals indicate seasonality, which is rare in daily returns but possible in monthly or quarterly data. Non-stationarity: if the ACF starts very high and comes down very slowly, it is a sign that the series is not stationary and needs differencing or transformation.
In short, for financial returns the ACF tells you whether they are purely random or whether there are potentially exploitable patterns. Prudence is in order: even when patterns are detected, they may not persist over time, and transaction costs can rapidly erode any gains derived from them.
Statsmodels offers its own version as a line plot, with lags on the horizontal axis and correlations on the vertical one:
plot_acf(df, lags=50); plt.show()
plot_acf(Re, lags=50); plt.show()
autocorrelation_plot(df[-100:]) # only the last 100 observations
plot_acf(df[-100:], lags=50); plt.show()The partial autocorrelation function (PACF) shows the relationship between an observation and observations at earlier steps once the effect of the intervening observations has been removed. The x axis is the lag, the y axis the partial autocorrelation between -1 and 1, and the horizontal lines mark the confidence intervals (usually 95%): values outside those lines are statistically significant and serve as evidence for including autoregressive terms.
How to draw conclusions: if the PACF cuts off sharply while the ACF decays more slowly, it suggests an autoregressive model of the order marked by the last significant lag; if the PACF decays gradually and the ACF cuts off abruptly, it suggests a moving average model; if both decay gradually, the series may fit better into a mixed ARMA model. The PACF plot guides you on the autoregressive order, but it is only one piece: model selection must also take into account domain knowledge, the ACF and the significance of the parameters.
plot_pacf(df[-100:], lags=49)