Skip to content

Instantly share code, notes, and snippets.

@mattbaggott
Created November 18, 2012 04:28
Show Gist options
  • Save mattbaggott/4103536 to your computer and use it in GitHub Desktop.
Save mattbaggott/4103536 to your computer and use it in GitHub Desktop.
Engle's AutoRegressive Conditional Heteroskedasticity (ARCH) estimator
arch_test <- function (x, order=10){
# AutoRegressive Conditional Heteroskedasticity (ARCH) estimator
xsq <- x^2
nobs <- length(x)
inds <- outer(0:(nobs - order - 1), order:1, "+")
xmat <- xsq[inds]
dim(xmat) <- dim(inds)
xreg <- lm(xsq[-1:-order] ~ xmat)
summary(xreg)$r.squared * (nobs - order)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment