## Function to simulate from a ARMA-GARCH process
arma11.garch11 <- function(n, ph, th, a, b, a0=1, rand.gen = rnorm, innov = rand.gen(n, ...),
n.start = 500, start.innov = rand.gen(n.start, ...),...){
# Simulates a ARMA(1,1)-GARCH(1,1) process
# with parameters ph, th, a, b, a0.
# x[t] <- ph*x[t-1] + th*eps[t-1] + eps[t]
# eps[t] <- e[t]*sqrt(v[t])
# v[t] <- a0 + a*eps[t-1]^2 + b*v[t-1];
# ph : AR
# th : MA
# a : ARCH
# b : GARCH
# checks
if(abs(a+b)>=1) stop("model is not stationary")
if(b/(1-a)>=1) stop("model has infinite fourth moments")
if (!missing(start.innov) && length(start.innov) < n.start)
stop(gettextf("'start.innov' is too short: need %d points", n.start), domain = NA)
e <- c(start.innov[1L:n.start], innov[1L:n])
ntot <- length(e)
x <- v <- eps <- double(ntot)
v[1] <- a0/(1.0-a-b);
eps[1] <- e[1]*sqrt(v[1])
x[1] <- eps[1];
for(i in 2:ntot){
v[i] <- a0 + a*eps[i-1]^2 + b*v[i-1];
eps[i] <- e[i]*sqrt(v[i])
x[i] <- ph*x[i-1] + th*eps[i-1] + eps[i]
}
if (n.start > 0) x <- x[-(1L:n.start)]
return(ts(x));
}
## **************************************************************************
## Comparison between the robust and the non-robust test in presence of GARCH errors
## Simulates from the ARMA(1,1)-GARCH(1,1)
set.seed(12)
x1 <- arma11.garch11(n=100, ph=0.9, th=0.5, a=0.85, b=0.1, a0=1,n.start=500)
TARMAGARCH.test(x1, ar.ord=1, ma.ord=1, arch.ord=1, garch.ord=1, d=1)
TARMA.test(x1, ar.ord=1, ma.ord=1, d=1, ma.fixed=FALSE)
## a TARMA(1,1,1,1) where the threshold effect is on the AR parameters
set.seed(123)
x2 <- TARMA.sim(n=100, phi1=c(0.5,-0.5), phi2=c(0.0,0.8), theta1=0.5, theta2=0.5, d=1, thd=0.2)
TARMAGARCH.test(x2, ar.ord=1, ma.ord=1, d=1)
Run the code above in your browser using DataLab