2014년 1월 5일 일요일

arch(1) model

require(tseries)

URL <- "http://ichart.finance.yahoo.com/table.csv?s=^KS11"
dat <- read.csv(URL)
dat$Date <- as.Date(dat$Date, "%Y-%m-%d")

odat<-dat[c(1:100),]

N<-99

attach(odat)

x<-odat[order(Date),]


price <- x[[2]]
ret <- 0

for (i in 1:length(price)) {
ret[i] <- (price[i]-price[1])/price[1]
}

par(mfrow=c(3,1))
par(mar=c(3,3,1,2))
x=c(1:length(ret))
plot(price, type='l', xaxt='n')

y<-diff(price)
plot(x = y, ylab = expression(y[t]), xlab = "t", type = "l", col = "red", 
     panel.first=grid(col = "gray", lty = "dotted"))
  points(x = y, pch = 20, col = "blue")
 

x.arch <- garch(ret-mean(ret), order = c(0,1), trace=TRUE)  # Fit ARCH(1)

#summary(x.arch)                     # Diagnostic tests
vol <- x.arch$fitted.values[,1]

plot(x, ret, type='l', col='lightgray', ylim=c(-0.01,0.08), xaxt='n')
points(x=x, y=vol, col='red', type='l')

abline(h=0, col="lightgray")


댓글 없음:

댓글 쓰기