I am checking the closing prices(about 9000+ prices) of the stocks data to test for randomness.

The test I am using is Ljung Box test, in MFE toolbox for MATLAB,

I used 300 data of closing prices, and 8 lags. Q = test statistics. pval = pvalue.

[Q, pval] = ljungbox(closingPrices,lags);

However, no matter which 30 intervals of 300, I keep getting all the p-value as zero, meaning, reject null hypothesis and conclude that there is no serial correlation.

i tried with different types of stocks, but all the p-value are all zero, which made the Ljung Box's test not very interesting.

May i know if I had used the Ljung Box Test wrongly?

If you have any comments, please enlighten me, thank you very much.

  • $\begingroup$ I'd advise against Ljung-Box test for financial data. It has terrible size properties. $\endgroup$
    – Ryogi
    Commented Oct 13, 2013 at 16:42
  • $\begingroup$ Try using price returns and maybe look at lmtest since the returns are most likely heteroskedastic. $\endgroup$
    – brian
    Commented Oct 13, 2013 at 18:04

1 Answer 1


In the Ljung-Box test, the null hypothesis is:

$H_0$: The data are independently distributed

So, your p-values of 0 indeed indicate that you should reject the null hypothesis, but it means that your data is not independently distributed, and in particular that there is some significant autocorrelation in the process.

This is obviously the case, because you use prices!!! The price at time $t_{i+1}$ clearly depends of the price at time $t_i$.

In order to have an interesting result, you need to test the returns of the price series, as opposed to the prices themselves.

  • $\begingroup$ May I ask, how do you get the returns of the price series from the closing prices of the stocks for each trade window. For examples there are weekly prices, $27, $29, $30, $26 for march, and $31, $29, $30, $28 for April. So the returns of the price series for march is (2, 3, -1) with 1 lag, and for April it is (2, -1, -3) with 1 lag? $\endgroup$
    – Ice
    Commented Oct 14, 2013 at 2:37
  • $\begingroup$ Actually, you may not really ask this on this site as it is dedicated to professional quants or academics (see the faq), but the return $r_t$ is defined as $r_t=\frac{p_t}{r_{p-1}}-1$. $\endgroup$
    – SRKX
    Commented Oct 14, 2013 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.