library(quantmod)
library(fGarch)
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),]
attach(odat)
x<-odat[order(Date),]
fit <- arima(diff(x$Close), order=c(1,0,2))
err <- rnorm(30, 0, sd(diff(x$Close)))
sim <- diff(x$Close)[99]
for (t in 2:30) {
sim[t] <- fit$coef[1]*sim[t-1] + fit$coef[2]*err[t-1]*0.5
+ fit$coef[3]*err[t-2]*0.5
}
par(mfrow=c(3,1))
par(mar=c(3,3,1,2))
x$newday <- as.Date(x$Date, "%m/%d/%Y")
plot(x$newday, x$Close, type='l', col='red',
panel.first=grid(col = "gray", lty = "dotted"), pch=20)
points(x$newday, x$Close, pch = 20, col = "red")
ye <- x$Close[100]
td<-x$newday[length(x$newday)]+1
for (j in 2:30) {
td[j] <- x$newday[length(x$newday)] + j
ye[j] <- sim[j-1]+ye[j-1]
}
td<-as.Date(td)
points(td, ye, col='red', pch=20, type='b')
plot(diff(x$Close), type='l', col=heat.colors(32)[15],panel.first=grid(col = "gray", lty = "dotted"))
##########################################################
library(forecast)
fit <- auto.arima(x$Close)
fore <- forecast(fit, h=10)
plot(fore)
ye

댓글 없음:
댓글 쓰기