Created
December 29, 2017 10:16
-
-
Save yht/be6e457000186d506b55b27d7287786c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Library | |
######### | |
library(quantmod) | |
# Get Stock Daily | |
################# | |
getSymbols.google("IDX:TLKM", env=globalenv(), | |
from="2005-04-01") | |
# Some Setup | |
############ | |
n <- nrow(`IDX:TLKM`) | |
h <- 6 * 20 | |
tlkm <- ts(`IDX:TLKM`[(n-h+1):n, c("IDX:TLKM.Close")]) | |
#tlkm <- ts(`IDX:TLKM`[, c("IDX:TLKM.Close")]) | |
plot(tlkm) | |
# Arima Forecast | |
################ | |
#fit <- auto.arima(tlkm, lambda=0, d=0, D=1, max.order=10, | |
# stepwise=FALSE, approximation=FALSE) | |
fit <- arima(tlkm, order=c(0,1,1), | |
seasonal=list(order=c(0,1,0), | |
period=10)) | |
fcast <- forecast(fit, h=5) | |
#tsdisplay(residuals(fit)) | |
# Moving Average | |
################ | |
ma10 <- ma(`IDX:TLKM`, order=10) | |
fcast10 <- forecast(ma10[6:(n-5)], h=10) | |
ma05 <- ma(`IDX:TLKM`, order=5) | |
fcast05 <- forecast(ma05[3:(n-3)], h=10) | |
# Ploting | |
######### | |
plot(fcast) | |
lines(1:h, | |
fcast10$x[(n-h-9):(n-10)], | |
col="blue") | |
lines(1:h, | |
fcast05$x[(n-h-4):(n-5)], | |
col="red") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment