# How to apply Ljung Box Test?

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.

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

$H_0$: The data are independently distributed
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$.
• 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? – Ice Oct 14 '13 at 2:37
• 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$. – SRKX Oct 14 '13 at 19:28