# NOT RUN {
## the data
dax <- EuStockMarkets[,"DAX"]
plot(dax)
## using a penalised autorgressive model
w <- wlag(dax, lag=20)
m1 <- gamlss(dax~ la(dax, lags=20, order=1, from.lag=1), weights=w)
lines(fitted(m1)~as.numeric(time(dax)), col=2)
wp(m1, ylim.all=1) # not very good model
# }
# NOT RUN {
## Try modelling the variance
m2 <- gamlss(dax~ la(dax, lags=20, order=1, from.lag=1),
sigma.fo=~la(dax^2, lags=10, order=1, from.lag=1), weights=w)
wp(m2, ylim.all=1)# maybe the tails
m3 <- gamlss(dax~ la(dax, lags=20, order=1, from.lag=1),
sigma.fo=~la(dax^2, lags=10, order=1, from.lag=1),
weights=w, family=TF)
wp(m3, ylim.all=1) # better model
plot(m3, ts=TRUE) # autocorrelation OK
## using FTSE to precict DAX
ftse <- EuStockMarkets[,"FTSE"]
# fitting using penLags
l1 <- penLags(dax, ftse, lags=30, plot=TRUE)
# similar model within gamlss
w <- wlag(ftse, lag=30)
g1 <- gamlss(dax~ la(ftse, lags=30, order=1), weights=w)
lines(fitted(m1)~as.numeric(time(dax)))
op <- par(mfrow=c(2,1))
# plotting the fitted coeficints of the AR terms
plot(coef(l1, "AR"), type="h")
plot(coef(g1$mu.coefSmo[[1]])[-1], type="h")
par(op)
g2 <- gamlss(dax~ la(ftse, lags=30, order=1)+la(dax, lags=20, order=1, from.lag=1) , weights=w)
g3 <- gamlss(dax~ la(ftse, lags=30, order=1)+la(dax, lags=20, order=1, from.lag=1) ,
sigma.fo=~la(dax^2, lags=10, order=1, from.lag=1), weights=w)
# }
Run the code above in your browser using DataLab