apaIsAutocorrelatedLjungBox(Returns, Lag, ConfidenceLevel)
=apaIsAutocorrelatedLjungBox(Returns, Lag, ConfidenceLevel)Result
Ljung-Box test for statistically significant autocorrelations up to a certain lag. Returns TRUE if the null hypothesis of zero autocorrelation is rejected, FALSE otherwise, and the p-value.
Syntax
Returns: r x 1 vector of returns; must not be constant
Lag: number of lags to test, between 1 and r − 1
ConfidenceLevel: confidence level strictly between 0 and 1, e.g. 0.95
Algorithm
Q = n(n + 2)·Σk ρk² / (n − k), k = 1, …, Lag. Q is compared with the chi-square distribution with Lag degrees of freedom; the p-value is the right-tail probability of Q.
Remarks
The output is a 2 x 1 vector: TRUE/FALSE (TRUE if Q exceeds the chi-square critical value at ConfidenceLevel, i.e. zero autocorrelation is rejected) and the p-value.
The autocorrelations ρk use the sum of squared deviations from the mean of the full series in the denominator, so the choice between sample and population moments cancels.
A Lag outside 1 to r − 1, a ConfidenceLevel outside (0, 1) or a constant series returns an error message.
