Get startedGet started for free

The Ljung-Box test

1. The Ljung-Box test

The sample acf plot is a very good visual tool for detecting serial dependencies. But it would be nice if it could be complemented by some numerical tests to check whether the hypothesis that log-returns are iid can really be rejected. Recall that from a risk perspective, you can make more risk-sensitive predictions of future portfolio behavior if you model the serial dependencies.

2. Testing the iid hypothesis with the Ljung-Box test

You are going to learn about a numerical test of the iid hypothesis known as the Ljung-Box test. The test statistic is shown on the slide and is based on the sum of squared values of the sample autocorrelations. Remember that, if the data are iid the sample autocorrelations should mostly be close to zero. So the larger the value of the Ljung-Box statistic, the greater the evidence that there is serial dependence in the series. The test has one parameter, which is the number of sample autocorrelation values included in the test. In other words, the maximum lag k that is considered. If you include k sample autocorrelation values in the test statistic, then you should compare the value with a chi-squared distribution with k degrees of freedom. A typical choice for k might be 10. Recall that n is the sample size. However, it is important to note that it is not sufficient to simply carry out the Ljung-Box test on the log-returns. You should also carry out the test on the absolute values of the log-returns. This is because, as has already been observed, the autocorrelations of a volatile return data are often very small, but the autocorrelations of the absolute values tend to be much larger. If the data are truly iid, then they should generally pass the Ljung-Box test, whether you take the raw values or the absolute values.

3. Example of Ljung-Box test

The code on this slide implements the Ljung-Box test for the FTSE log-returns. It uses the function Box.test, and the argument lag specifies the number of sample autocorrelations to be included in the test. In the example, lag is set equal to 10. The option type equals "Ljung" has been chosen in order to get the Ljung-Box test; there is a variant on the test known as the Box-Pierce test, which can be obtained by type equals Box. For the log-returns, the value of the test statistic is around 42, and this gives a highly significant p-value of approximately eight point eight times 10 to the minus 6. So even the raw log-returns show strong evidence against the iid hypothesis. When the test is run on the absolute returns, the test result is even more significant, with a p-value less than two point two times 10 to the minus 16.

4. Applying Ljung-Box to longer-interval returns

In the exercises, you are also going to investigate what happens when the Ljung-Box test is applied to longer interval returns. What you should find is that the serial dependencies get somewhat weaker at the same time as the returns become more normally distributed. Let's see what happens when the Ljung-Box test is applied to weekly log-returns of the FTSE index and also their absolute values. Recall that weekly log-returns can be obtained by summing daily log-returns within the apply-weekly function. In the code, the weekly returns have been assigned to ftse underscore w. The tests are then applied exactly as before. This time, for the raw log-returns, the result is not quite significant at the 5% level; the p-value is very slightly larger than point zero five. However, the test is quite strongly significant for the absolute values with a p-value of point zero zero zero one six.

5. Let's practice!

Now let's practice using the Ljung-Box test with some of the data from previous exercises.

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.