First we read in the data, install the appropriate packages, load the packages into our working directory using the “library()” function, and create a timeseries variable “tsrate”
## Warning: package 'broom' was built under R version 3.2.3
hw <- read.csv("C:/Users/kgwunderlich1s/Desktop/hw.txt", sep="")
ymd(paste(hw$Year,hw$Mon,hw$Day,sep = "/"))->hw$date
ts(hw$Rate)->tsrate
Now we use the “auto.arima()” function to achieve a forecast model with p=4,d=1,q=4
fit <- auto.arima(tsrate)
## Warning in auto.arima(tsrate): Unable to fit final model using maximum
## likelihood. AIC value approximated
fcast <- forecast(fit)
fcast$fitted->hw$forecast
dates<-hw$date[735]+months(1:10)
tidy(fit)
## term estimate std.error
## 1 ar1 -0.006933305 0.18409084
## 2 ar2 0.307028265 0.12285361
## 3 ar3 -0.434984420 0.12831388
## 4 ar4 0.323025540 0.10868138
## 5 ar5 0.221112357 0.05109936
## 6 ma1 0.029766416 0.18606073
## 7 ma2 -0.069541925 0.12713478
## 8 ma3 0.632318825 0.10420285
## 9 ma4 -0.236353283 0.09434336
The above model implies cycles because of the +,- alternating estimates for AR p’s and MA q’s
From here we can see the following plots in the respective order:
1)Observed Rates
2)Forecast Rates (plus 10 forecasted values)
3)Observed Rates against Forecast Rates
plot(hw$Rate,x = hw$date,main="True Rates",ylab="Return Rates",xlab="date",type="l")
plot(fcast,xlab="Rate Observation Value",ylab="Return Rates")
plot(y=hw$forecast,x=hw$Rate,ylab="Forecasted Rates",xlab="True Rates")
cbind(as.character(dates),fcast$mean)->ans
Finally, the forecasted rates for 2009 are:
## Time Series:
## Start = 736
## End = 745
## Frequency = 1
## as.character(dates) fcast$mean
## 736 2009-04-01 8.73062653174108
## 737 2009-05-01 8.98999141104361
## 738 2009-06-01 9.1646731184688
## 739 2009-07-01 9.34213812460723
## 740 2009-08-01 9.44466344831955
## 741 2009-09-01 9.55723141694743
## 742 2009-10-01 9.62451004103085
## 743 2009-11-01 9.70995822094358
## 744 2009-12-01 9.75341491317477
## 745 2010-01-01 9.80911541266399