7. Autocorrelation, normality and standardized residuals
Level 7: Rigorous Statistical Diagnostics
Autocorrelation of the residuals. If the covariance between the errors of two different observations is not zero, the errors are correlated. It is an extremely common problem in time series, that is, in almost everything we do in trading. The classic case is a first-order autoregressive error: today's error is rho times yesterday's error plus a fresh disturbance, with rho smaller than one in absolute value. The covariance between today's error and yesterday's is then rho times the error variance, which is not zero: the model has serially correlated errors.
Estimating by OLS while ignoring the violation still yields unbiased and consistent estimators. But the estimators are inefficient and the variance of the coefficients is biased, so inference stops being reliable; in practice this usually inflates the apparent significance of the factors. Also beware of the causal diagnosis: autocorrelated errors can be a symptom of a misspecified model (some dynamic you have not modeled) rather than an isolated statistical problem.
The Durbin-Watson test. The null is that the errors are not serially correlated; the alternative is that they follow a first-order autoregressive process. The statistic is computed as the sum of squared differences between consecutive residuals, divided by the sum of squared residuals. Its value always falls between 0 and 4: a value of 2 indicates no autocorrelation, values clearly below 2 indicate positive autocorrelation and values above indicate negative autocorrelation.
The Breusch-Godfrey test. More flexible: it covers higher orders of autocorrelation and works whether or not the regressors include lags of the dependent variable. An auxiliary regression of the residual on the explanatory variables and on p lags of the residual itself is fitted, and the test checks that all the coefficients on those lags are zero. The statistic is N minus p, multiplied by the R squared of the auxiliary regression, and follows a chi squared distribution with p degrees of freedom. The Ljung-Box test is also available for the same null.
from statsmodels.stats.stattools import durbin_watson
from statsmodels.stats.diagnostic import acorr_breusch_godfrey
print(durbin_watson(model.resid.values))
print(acorr_breusch_godfrey(model, nlags=2))Normality of the residuals. It is needed if we want correct p-values and critical values when testing hypotheses about the coefficients. The null is that the residuals follow a normal distribution. Among the available tests: Anderson-Darling, which compares the empirical distribution with the theoretical one; Shapiro-Wilk, which according to Monte Carlo simulations has the highest power, closely followed by Anderson-Darling and ahead of Kolmogorov-Smirnov and Lilliefors; Kolmogorov-Smirnov, based on the maximum distance between the two distributions; Cramer-von Mises, an alternative to the previous one; and Jarque-Bera, valid for large samples, which combines skewness and kurtosis and follows a chi squared distribution with two degrees of freedom under the null.
from statsmodels.stats.stattools import jarque_bera
print(jarque_bera(model.resid.values))On daily financial returns, Jarque-Bera rejects normality almost always, because of the high kurtosis (fat tails). This is not a flaw in the analysis: it is a known property of markets. The sensible response is to lean on asymptotic results with large samples and on robust standard errors, not to delete the bad days.
Standardized residuals. Since residuals can have different variances, to compare them across observations we divide each residual by an estimate of its own standard deviation: the estimated standard deviation of the error, multiplied by the square root of one minus the corresponding diagonal element of the projection matrix. They are very useful for spotting outliers: as a rule, any observation with a standardized residual greater than 2 in absolute value deserves a close look.