The Ljung-Box test

Quantitative Risk Management in R

Alexander McNeil

Professor, University of York

Testing the iid hypothesis with the Ljung-Box test

  • Numerical test calculated from squared sample autocorrelations up to certain lag
  • Compared with chi-squared distribution with degrees of freedom (df)
  • Should also be carried out on absolute terms

$$

$$X^2 = n(n+2) \sum_{j=1}^k{{\hat{\rho}(j)^2} \over {n-j}}$$

Quantitative Risk Management in R

Example of Ljung-Box test

Box.test(ftse, lag = 10, type = "Ljung")
    Box-Ljung test

data: ftse
X-squared = 41.602, df = 10, p-value = 8.827e-06
Box.test(abs(ftse), lag = 10, type = "Ljung")
    Box-Ljung test

data: abs(ftse)
X-squared = 314.62, df = 10, p-value < 2.2e-16
Quantitative Risk Management in R

Applying Ljung-Box to longer-interval returns

ftse_w <- apply.weekly(ftse, FUN = sum)
head(ftse_w, n = 3)
                 ^FTSE
2008-01-04 -0.01693075
2008-01-11 -0.02334674
2008-01-18 -0.04963134
Box.test(ftse_w, lag = 10, type = "Ljung")
    Box-Ljung test

data: ftse_w
X-squared = 18.11, df = 10, p-value = 0.05314

$$$$$$$$$$$$$$$$

Box.test(abs(ftse_w), lag = 10, type = "Ljung")
    Box-Ljung test

data: abs(ftse_w)
X-squared = 34.307, df = 10, p-value = 0.0001638
Quantitative Risk Management in R

Let's practice!

Quantitative Risk Management in R

Preparing Video For Download...