Conditional heteroskedasticity and volatility clustering
Today let's understand why the size of the daily swings in a stock index keeps changing over time, and what that does to the forecasts we make from it.
Our running example is the DAX, the main stock index of the German market. Each trading day the index closes at some level, and that day's return is the percent change from the previous close. Below are 260 consecutive daily returns of the DAX, from late 1996 to late 1997.
Compare the two ends of the plot. In the first 60 days the returns have a standard deviation of 0.879, and no day moves more than 2.16 percent in either direction. In the last 60 days the standard deviation is 1.952, and the returns swing much further, from -6.01 on day 252 to 4.32 on day 253.
From closing prices to daily returns
The DAX prices come with R. The built-in EuStockMarkets dataset holds the daily closing prices of four European stock indices from 1991 to 1998, and we take its DAX column.
We work with returns instead of prices. The daily log return, in percent, is
\[ r_t = 100 \times \left( \log P_t - \log P_{t-1} \right) \]
where \(P_t\) is the closing price on day \(t\). For small moves it is almost the same as the percent change from one close to the next. Unlike a change in index points, it means the same thing at any level of the index.
The code below computes the returns and prints the first few prices and returns.
The first price fell from 1,628.75 to 1,613.63, so the first return is -0.933, a fall of about 0.9 percent. There are 1,860 prices but only 1,859 returns, because the first price has no day before it.
Here are the mean, standard deviation, smallest and largest return.
The mean daily return is 0.065 percent, which is small next to a standard deviation of 1.030. The worst day was a fall of 9.628 percent and the best day a rise of 5.076 percent.
The plot has the prices on top and the returns below, with a dashed line at the mean return.
The prices trend upward, so there is no fixed level they move around. The returns move around their mean of 0.065, the dashed line close to 0. That makes them the series we can describe with a mean and a variance.
Rolling volatility over 60 trading days
Volatility is how widely the returns spread out, and it is measured as the standard deviation of the returns. So far we have one standard deviation for the whole series, 1.030. But is the spread the same everywhere in the series?
To find out, we compute the standard deviation over a moving window: days 1 to 60, then days 2 to 61, then days 3 to 62, and so on to the end. This is a rolling standard deviation, and 60 trading days is about three months. The 1,859 returns give 1,800 windows.
Across the 1,800 windows the standard deviation runs from 0.478 up to 1.987, with a median of 0.879. The most volatile window is 4.2 times as volatile as the calmest one.
Next we find where those two windows start, and in which year.
The calmest window starts on day 1,323 and the most volatile on day 1,597. The dataset counts trading days as fractions of a year, so 1996.6 is about 60 percent of the way through 1996. The + 1 in the code matches each return to the date of the price that produced it.
The plot shows the returns above and their 60-day standard deviation below. The dashed line marks the 1.030 of the whole series, and the two dots mark the calmest and the most volatile window.
The rolling standard deviation stays low for a long run of windows, then rises and stays high. Neighbouring windows share 59 of their 60 returns, so the line is smooth by construction. What matters is how far it travels, from 0.478 to 1.987.
This pattern has a name: volatility clustering. Large moves tend to be followed by large moves, and small moves by small ones, of either sign.
The lowest and the highest 60-day volatility side by side
The chart below puts the 60 returns of the calmest window and the 60 returns of the most volatile window on the same axes. Switch between the points and the boxplot, where each box holds the middle half of the returns.
We call these two sets of 60 returns the low volatility stretch and the high volatility stretch.
The code below gives the numbers behind the chart.
Both stretches have a mean near 0, 0.159 in the low volatility one and -0.242 in the high volatility one. The standard deviations are far apart, 0.478 against 1.987, a ratio of 4.2. The low volatility returns stay between -1.086 and 1.159, while the high volatility returns run from -6.007 to 4.321.
Now compare both with the standard deviation of the whole series, 1.030. It is about twice the low volatility stretch's 0.478 and about half the high volatility stretch's 1.987. So that one number describes neither stretch.
Unconditional and conditional variance
The spread of the returns is not one fixed number, so we need words for what changes. Let's start with the two kinds of variance.
The unconditional variance is one number for the whole series: the variance of all 1,859 returns, whose square root is the 1.030 we have been using. It ignores when each return happened. A series is heteroskedastic when its variance is not constant over time, and homoskedastic when it is.
The conditional variance is the variance of today's return given what we know up to yesterday. We write it \(\sigma_t^2\), and the bar reads "given":
\[ \sigma_t^2 = \mathrm{Var}\left( r_t \mid r_{t-1}, r_{t-2}, \dots \right) \]
A return can then be written as
\[ r_t = \mu + \sigma_t z_t \]
where \(\mu\) is the mean return, \(z_t\) is a random shock with mean 0 and variance 1, and \(\sigma_t\) is the standard deviation that applies on day \(t\). When \(\sigma_t\) changes with the recent past, the series has conditional heteroskedasticity.
Does the recent past really tell us about the size of today's return? We measure recent volatility as the standard deviation of the previous 60 returns, the trailing standard deviation. Then we sort the days into three equal groups by it, low, mid and high, and measure the spread of the return that follows each window.
The last window has no day after it, so we drop it, which leaves 1,799 windows. today holds the return that follows each window, days 61 to 1,859. The cut points between the thirds are 0.771 and 1.044.
Now read the table. The standard deviation of today's return rises from 0.736 in the low third to 0.992 in the mid third and 1.239 in the high third. The mean stays near 0 in all three, at 0.029, 0.088 and 0.087.
So the average return does not change with recent volatility, but the spread of the return does. That is conditional heteroskedasticity in the DAX.
Quick check: what does one standard deviation of 1.030 say about the two stretches?
The low volatility stretch has a standard deviation of 0.478 and the high volatility stretch has 1.987. The whole series has 1.030. Which statement is right?
The ACF of daily returns
The tool for asking whether a value depends on earlier values is the autocorrelation function, or ACF. The autocorrelation at lag k is the correlation between the return on day \(t\) and the return k days earlier. Lag 1 compares each day with the day before, and lag 2 compares it with two days before.
For lag k the formula is
\[ \hat{\rho}_k = \frac{\sum_{t=k+1}^{n} (r_t - \bar{r})(r_{t-k} - \bar{r})}{\sum_{t=1}^{n} (r_t - \bar{r})^2} \]
where \(\hat{\rho}_k\) is the autocorrelation at lag k, \(\bar{r}\) is the mean return and n is the number of returns.
The code computes lag 1 by hand as the sum of the products of neighbouring deviations from the mean, divided by the sum of the squared deviations. Then it compares the result with acf().
Both give -0.0004, essentially 0. Yesterday's return has almost no linear relationship with today's.
How far from 0 does an autocorrelation have to be before we count it? If the returns had no autocorrelation at all, a sample autocorrelation from n returns would be roughly normal with mean 0 and standard deviation \(1/\sqrt{n}\). A normal value falls within 1.96 standard deviations of its mean 95% of the time, where 1.96 is qnorm(0.975). So the band is \(\pm 1.96/\sqrt{n}\), and about 1 lag in 20 falls outside it by chance alone.
The block below checks the 1.96, computes the band, prints the first five autocorrelations, lists the lags outside the band and plots the ACF up to lag 20.
With 1,859 returns the band is 0.0455, and the dashed lines in the plot sit at plus and minus that value. Lags 1 to 5 are 0.000, -0.027, -0.010, 0.000 and -0.032, all inside the band, and so is every lag from 1 to 10.
Only lags 11 and 17 are outside. With 20 lags we expect about 1 outside by chance, so 2 is not a surprise. The tall spike at lag 0 is a return correlated with itself, always 1, and is not part of the test.
So the DAX returns show no linear dependence on earlier returns. But this ACF is computed on the returns themselves, so it cannot see whether the size of the swings depends on the past.
The ACF of squared returns
The variance is the average squared deviation from the mean. The mean return is 0.065, close to 0, so a day's squared return \(r_t^2\) is close to its squared deviation from the mean. That makes \(r_t^2\) a one-day measure of the variance.
If the variance moves in runs, the squared returns should be correlated with earlier squared returns. We compute their ACF with the same formula, starting with lag 1 by hand. The block also prints the largest squared return and the median one.
Lag 1 is 0.0789, already outside the band of 0.0455. Next we compute the whole ACF of the squared returns and, for comparison, the ACF of the absolute returns \(|r_t|\), another measure of a day's size.
The first five autocorrelations of the squared returns are all positive, and 9 of the 20 lags are outside the band, lags 1 to 7 plus 14 and 15. A large squared return tends to be followed by more large ones. For the absolute returns all 20 lags are outside the band, with 0.109 at lag 1.
Why is the pattern stronger for the absolute returns? One reason is that squaring gives the extreme days a huge weight. The return of -9.628 has a square of 92.69, while the median squared return is 0.30, so a few days dominate the sums in the ACF of the squares.
Now put the two ACFs side by side. The returns are inside the band at lags 1 to 10, and the squared returns are outside it at lags 1 to 7. The returns are uncorrelated, but their squares are not. So the returns are not independent, because independent returns would have uncorrelated squares too.
How well a constant-variance 95% interval covers low- and high-volatility days
This matters because a forecast interval is built from a variance. A 95% prediction interval for the next return is a range the return should fall inside on 95% of days. Its coverage is the share of days whose return really does fall inside, so a 95% interval should have coverage near 95%.
If we assume one constant variance, the interval is the mean plus or minus 1.96 standard deviations. We compute it from the whole series, so any failure comes from assuming one variance and not from estimation error. Then we count the days it misses in each volatility third, and in the two stretches.
The interval runs from -1.95 to 2.08, a width of 4.04 on every day. Over all 1,799 days its coverage is 94.7%, close to the 95% we set. But that average hides two errors that cancel.
In the low third the coverage is 98.3%, with 10 misses where about 30 are allowed, since 5% of 600 days is 30. In the high third it is 90.3%, with 58 misses. The same picture shows in the two stretches: the interval misses 0 of the 60 days in the low volatility stretch and 20 of the 60 in the high volatility stretch. So the interval is too wide when volatility is low and too narrow when it is high.
Now use the dependence we found. Instead of the constant standard deviation, we use the trailing standard deviation: the interval is the mean plus or minus 1.96 times the standard deviation of the previous 60 returns.
The trailing interval changes its width with the volatility: 2.59 on average in the low third, 3.50 in the mid third and 5.24 in the high third. The constant width of 4.04 is 1.6 times the low third's trailing width and 0.77 of the high third's. The trailing interval's coverage is 92.7%, 92.7% and 95.8%, so every third is now within 2.3 points of 95%, where before they ranged from 98.3% to 90.3%.
The overall coverage of the trailing interval is 93.7%, a little under 95%. The block below counts the days more than 3 trailing standard deviations from the mean, and how many a normal curve allows.
There are 21 such days, against about 5 if the returns followed a normal curve. So, measured in trailing standard deviations, the returns have heavier tails than a normal curve, and the 1.96 in the interval does not allow for that. That keeps the coverage a little under 95%.
The plot shows 260 days of returns with both intervals. The dashed lines are the constant interval, and the green lines are the trailing interval.
The dashed band stays where it is, while the green band moves with the recent volatility.
How far can interval coverage fall when the variance is not constant?
The DAX interval broke the assumption of a constant variance. The widget below shows how much damage that assumption can do, but it runs its own simulated data and not the DAX.
It simulates a regression with 60 points whose error spread grows with x, so it fails the same equal-variance assumption, over x instead of over time. At every dial position it runs 2,000 studies and builds a 95% interval for the slope in each. Coverage is the share of those intervals that contain the true slope, and the widget shows it next to R-squared.
Start with the spread constant. Coverage is 95.1% and R-squared is 0.503. Move the dial to a widest spread 3.7 times the narrowest, and coverage falls to 92.8%. At 5.8 times it is 90.8%.
The ratio between the DAX's highest and lowest 60-day standard deviation, 4.2, lies between these two positions.
At the top of the dial, with the widest spread 81.5 times the narrowest, coverage is 70.7%. But R-squared has only moved from 0.503 to 0.533. So the fit statistic most people check does not warn you that the interval is wrong. The DAX interval fails for the same reason: it assumes one variance.
Quick check: which conclusion about the DAX interval is right?
The constant-variance 95% interval covers 94.7% of all days. Which conclusion follows from the coverage by volatility third and from the dial?
Your turn: test the CAC 40 for volatility clustering
Now apply the detection to a new series. The CAC 40 is the main French stock index, and it is in the same dataset as the DAX, in the column "CAC". It has the same 1,859 returns, so the band is the same 0.0455.
Compute the CAC 40 returns, then the lag 1 autocorrelation of the returns and of the squared returns. Decide whether each is inside or outside the band.
Show answer
# Compute the lag 1 autocorrelation of the CAC 40 returns and of their squares
cac_ret <- 100 * diff(log(as.numeric(EuStockMarkets[, "CAC"])))
round(acf(cac_ret, plot = FALSE)$acf[2], 3)
#> [1] 0.03
round(acf(cac_ret^2, plot = FALSE)$acf[2], 3)
#> [1] 0.12R prints 0.030 as 0.03. The lag 1 autocorrelation of the CAC 40 returns is inside the band, and that of the squared returns is 2.6 times the band. So the CAC 40 shows volatility clustering too.
References
- The Variation of Certain Speculative Prices - Mandelbrot (1963), Journal of Business 36(4), 394-419. Large changes tend to be followed by large changes.
- Autoregressive Conditional Heteroscedasticity with Estimates of the Variance of United Kingdom Inflation - Engle (1982), Econometrica 50(4), 987-1007. The model that makes the variance conditional.
- Empirical properties of asset returns: stylized facts and statistical issues - Cont (2001), Quantitative Finance 1(2), 223-236. Uncorrelated returns, correlated squares.
- Forecasting: Principles and Practice, 3rd edition - Hyndman and Athanasopoulos, sections 2.8 (autocorrelation) and 5.5 (prediction intervals).
- Auto- and Cross- Covariance and -Correlation Function Estimation - R Core Team, the documentation for
acf()in the stats package.
Quick recap
You measured volatility clustering in the DAX and saw what it does to a forecast interval. To summarize:
- The 60-day standard deviation of the DAX returns runs from 0.478 to 1.987 while the mean stays near 0. That is volatility clustering.
- Conditional heteroskedasticity means the variance of a day's return depends on the recent returns. The standard deviation of today's return rose from 0.736 to 0.992 to 1.239 across the low, mid and high thirds of the trailing standard deviation.
- The ACF of the returns is inside the band at lags 1 to 10, and the ACF of the squared returns is outside it at lags 1 to 7. Uncorrelated returns with correlated squares are not independent.
- A constant-variance 95% interval covers 94.7% of days but 98.3%, 95.5% and 90.3% across the three thirds. An interval that follows the trailing standard deviation covers between 92.7% and 95.8% in every third.
In the next lesson, we write this conditional variance as an ARCH model.