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.

RInteractive R
# Turn the DAX closing prices into daily log returns in percent dax_price <- as.numeric(EuStockMarkets[, "DAX"]) dax_ret <- 100 * diff(log(dax_price)) length(dax_price) #> [1] 1860 range(dax_price) #> [1] 1402.34 6186.09 head(dax_price, 4) #> [1] 1628.75 1613.63 1606.51 1621.04 round(head(dax_ret, 4), 3) #> [1] -0.933 -0.442 0.900 -0.178

  

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.

RInteractive R
# Summarise the daily returns round(c(mean = mean(dax_ret), sd = sd(dax_ret), min = min(dax_ret), max = max(dax_ret)), 3) #> mean sd min max #> 0.065 1.030 -9.628 5.076 length(dax_ret) #> [1] 1859

  

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.

RInteractive R
# Plot the prices above and the daily returns below par(mfrow = c(2, 1), mar = c(4, 4, 2, 1)) plot(dax_price, type = "l", xlab = "trading day", ylab = "DAX index level") plot(dax_ret, type = "l", xlab = "trading day", ylab = "daily return (%)") abline(h = mean(dax_ret), lty = 2)

  

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.

RInteractive R
# Compute the standard deviation of every 60-day window of returns win_len <- 60 n_windows <- length(dax_ret) - win_len + 1 rolling_sd <- sapply(1:n_windows, function(i) sd(dax_ret[i:(i + win_len - 1)])) n_windows #> [1] 1800 round(c(min = min(rolling_sd), median = median(rolling_sd), max = max(rolling_sd)), 3) #> min median max #> 0.478 0.879 1.987 round(max(rolling_sd) / min(rolling_sd), 1) #> [1] 4.2

  

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.

RInteractive R
# Find where the calmest and the most volatile 60-day windows start, and in which year low_start <- which.min(rolling_sd) high_start <- which.max(rolling_sd) c(low_start = low_start, high_start = high_start) #> low_start high_start #> 1323 1597 round(time(EuStockMarkets)[c(low_start, high_start) + 1], 1) #> [1] 1996.6 1997.6

  

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.

RInteractive R
# Plot the returns and their 60-day rolling standard deviation par(mfrow = c(2, 1), mar = c(4, 4, 2, 1)) plot(dax_ret, type = "l", xlab = "trading day", ylab = "daily return (%)") plot(rolling_sd, type = "l", xlab = "first trading day of the 60-day window", ylab = "standard deviation (%)") abline(h = sd(dax_ret), lty = 2) points(c(low_start, high_start), rolling_sd[c(low_start, high_start)], pch = 19)

  

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.

RInteractive R
# Summarise the low volatility and the high volatility stretches low_stretch <- dax_ret[low_start:(low_start + win_len - 1)] high_stretch <- dax_ret[high_start:(high_start + win_len - 1)] stretches <- data.frame( stretch = c("low volatility", "high volatility"), mean = c(mean(low_stretch), mean(high_stretch)), sd = c(sd(low_stretch), sd(high_stretch)), min = c(min(low_stretch), min(high_stretch)), max = c(max(low_stretch), max(high_stretch)) ) stretches[, -1] <- round(stretches[, -1], 3) stretches #> stretch mean sd min max #> 1 low volatility 0.159 0.478 -1.086 1.159 #> 2 high volatility -0.242 1.987 -6.007 4.321 round(sd(high_stretch) / sd(low_stretch), 1) #> [1] 4.2

  

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.

RInteractive R
# Split the days into thirds by the trailing 60-day standard deviation and measure today's return in each trailing_sd <- rolling_sd[-length(rolling_sd)] today <- dax_ret[(win_len + 1):length(dax_ret)] cuts <- quantile(trailing_sd, c(1/3, 2/3)) third <- cut(trailing_sd, breaks = c(-Inf, cuts, Inf), labels = c("low", "mid", "high")) round(unname(cuts), 3) #> [1] 0.771 1.044 data.frame( days = as.vector(table(third)), sd_today = round(tapply(today, third, sd), 3), mean_today = round(tapply(today, third, mean), 3) ) #> days sd_today mean_today #> low 600 0.736 0.029 #> mid 599 0.992 0.088 #> high 600 1.239 0.087

  

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?

Yes. One standard deviation for the whole series is an unconditional number, and here it is too big for the calm days and too small for the volatile days.
The two stretches have 0.478 and 1.987, and the rolling standard deviation ranged from 0.478 to 1.987 across all windows. Both means are near 0, so the difference in spread does not come from the means. The average of the two standard deviations is 1.23, not 1.030, and even a number like that would not describe either stretch.

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().

RInteractive R
# Compute the lag 1 autocorrelation of the returns by hand and with acf() n <- length(dax_ret) dev_ret <- dax_ret - mean(dax_ret) lag1_hand <- sum(dev_ret[-1] * dev_ret[-n]) / sum(dev_ret^2) lag1_acf <- acf(dax_ret, plot = FALSE)$acf[2] cat(sprintf("by hand: %.4f\nacf(): %.4f\n", lag1_hand, lag1_acf)) #> by hand: -0.0004 #> acf(): -0.0004

  

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.

RInteractive R
# Compare the ACF of the returns with the 95% band round(qnorm(0.975), 2) #> [1] 1.96 band <- 1.96 / sqrt(n) round(band, 4) #> [1] 0.0455 acf_ret <- acf(dax_ret, lag.max = 20, plot = FALSE)$acf[-1] round(acf_ret[1:5], 3) #> [1] 0.000 -0.027 -0.010 0.000 -0.032 which(abs(acf_ret) > band) #> [1] 11 17 par(mfrow = c(1, 1)) acf(dax_ret, lag.max = 20, main = "ACF of the daily returns")

  

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.

RInteractive R
# Compute the lag 1 autocorrelation of the squared returns by hand sq_ret <- dax_ret^2 dev_sq <- sq_ret - mean(sq_ret) lag1_sq <- sum(dev_sq[-1] * dev_sq[-n]) / sum(dev_sq^2) round(lag1_sq, 4) #> [1] 0.0789 round(c(largest_square = max(sq_ret), median_square = median(sq_ret)), 2) #> largest_square median_square #> 92.69 0.30

  

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.

RInteractive R
# Compare the ACF of the squared returns with the ACF of the absolute returns acf_sq <- acf(sq_ret, lag.max = 20, plot = FALSE)$acf[-1] acf_abs <- acf(abs(dax_ret), lag.max = 20, plot = FALSE)$acf[-1] round(acf_sq[1:5], 3) #> [1] 0.079 0.171 0.074 0.078 0.053 which(abs(acf_sq) > band) #> [1] 1 2 3 4 5 6 7 14 15 sum(abs(acf_abs) > band) #> [1] 20 round(acf_abs[1], 3) #> [1] 0.109 par(mfrow = c(1, 2)) acf(sq_ret, lag.max = 20, main = "Squared returns") acf(abs(dax_ret), lag.max = 20, main = "Absolute returns")

  

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.

Key Insight
The ACF of the returns asks whether the direction of a return depends on the past. The ACF of the squared returns asks whether its size does. In the DAX returns the first is flat and the second is not.

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.

RInteractive R
# Build the constant-variance 95% interval and count its misses in each third r_mean <- mean(dax_ret) const_lo <- r_mean - 1.96 * sd(dax_ret) const_hi <- r_mean + 1.96 * sd(dax_ret) inside_const <- today >= const_lo & today <= const_hi round(c(lower = const_lo, upper = const_hi, width = const_hi - const_lo), 2) #> lower upper width #> -1.95 2.08 4.04 round(100 * mean(inside_const), 1) #> [1] 94.7 round(100 * tapply(inside_const, third, mean), 1) #> low mid high #> 98.3 95.5 90.3 tapply(!inside_const, third, sum) #> low mid high #> 10 27 58 sum(low_stretch < const_lo | low_stretch > const_hi) #> [1] 0 sum(high_stretch < const_lo | high_stretch > const_hi) #> [1] 20

  

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.

RInteractive R
# Build the interval that follows the trailing standard deviation and compare the two trail_lo <- r_mean - 1.96 * trailing_sd trail_hi <- r_mean + 1.96 * trailing_sd inside_trail <- today >= trail_lo & today <= trail_hi data.frame( constant_coverage = round(100 * tapply(inside_const, third, mean), 1), trailing_coverage = round(100 * tapply(inside_trail, third, mean), 1), constant_width = round(const_hi - const_lo, 2), trailing_width = round(tapply(trail_hi - trail_lo, third, mean), 2) ) #> constant_coverage trailing_coverage constant_width trailing_width #> low 98.3 92.7 4.04 2.59 #> mid 95.5 92.7 4.04 3.50 #> high 90.3 95.8 4.04 5.24 round(100 * mean(inside_trail), 1) #> [1] 93.7

  

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.

RInteractive R
# Count the days beyond 3 trailing standard deviations against the count a normal curve allows sum(abs(today - r_mean) > 3 * trailing_sd) #> [1] 21 round(length(today) * 2 * pnorm(-3), 1) #> [1] 4.9

  

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.

RInteractive R
# Plot 260 days of returns with the constant interval and the trailing interval show_days <- 1400:1659 par(mfrow = c(1, 1)) plot(show_days, dax_ret[show_days], pch = 16, cex = 0.6, xlab = "trading day", ylab = "daily return (%)") abline(h = c(const_lo, const_hi), lty = 2) lines(show_days, trail_lo[show_days - win_len], col = "#1f7a55", lwd = 2) lines(show_days, trail_hi[show_days - win_len], col = "#1f7a55", lwd = 2) legend("topleft", legend = c("constant interval", "trailing interval"), lty = c(2, 1), lwd = c(1, 2), col = c("black", "#1f7a55"), bty = "n")

  

The dashed band stays where it is, while the green band moves with the recent volatility.

Key Insight
A constant-variance interval can have the right coverage on average and still be wrong in both directions: too wide when the series is calm and too narrow when it is volatile.

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?

Yes. The 94.7% is an average of two errors in opposite directions, and the assumption of one constant variance is what produces both.
The average coverage can be right while the interval fails in calm and in volatile periods. The ACF of the returns only shows that their direction is not predictable, and it says nothing about the variance. In the dial, R-squared stayed between 0.503 and 0.533 while coverage fell from 95.1% to 70.7%, so a fit statistic does not check the interval.

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.

Right: 0.030 for the returns is inside the band of 0.0455, and 0.120 for the squared returns is 2.6 times the band. The CAC 40 also has uncorrelated returns and correlated squares, which is volatility clustering.Build the returns like the DAX ones from the CAC column, then call acf() with plot = FALSE on cac_ret and again on cac_ret^2, and take the second element of the acf component, which is lag 1.
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.12

R 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

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.