### short-term Goverment Securities R library(ts) # to read the data x <- scan("E:\\Stat207\\Midterm\\Securities.dat") # you can make x a regular time series object x <- ts(x, freq=12) # plot the data par(mfrow=c(1,1)) ts.plot(x,gpars=list(xlab="Month", ylab="short-term Goverment Securities")) # plot the ACF and PACF win.graph() par(mfrow=c(2,2)) acf(x) acf(x, type="partial") # note the nonstationarity, difference the data x.diff <- diff(x) # plot the differenced data win.graph() par(mfrow=c(1,1)) ts.plot(x.diff, gpars=list(xlab="Month", ylab="differenced short-term Goverment Securities")) # plot the ACF and PACF win.graph() par(mfrow=c(2,2)) acf(x.diff) acf(x.diff, type="partial") # ARIMA # now the ARMA(0,1,1) fit x.arima <- arima0(x, order=c(0,1,1)) summary(x.arima) win.graph() par(mfrow=c(3,1)) ts.plot(x.arima$resid) acf(x.arima$resid) acf(x.arima$resid,type="partial") # Forecast 12 time units ahead for ARIMA(0,1,1) model x.arima.fore <- predict(x.arima,n.ahead=12) cbind(x.arima.fore$pred,x.arima.fore$se) win.graph() par(mfrow=c(1,1)) ts.plot(x,x.arima.fore$pred,x.arima.fore$pred+2*x.arima.fore$se, x.arima.fore$pred-2*x.arima.fore$se)