I decided to use the monthly average of the exchange rate of the Australian dollar for every 1 USD.
library(forecast)
## Warning: package 'forecast' was built under R version 3.4.2
library(xts)
## Warning: package 'xts' was built under R version 3.4.3
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 3.4.3
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(tseries)
## Warning: package 'tseries' was built under R version 3.4.3
library(readr)
exchange.data=read_csv("~/Dropbox/Boston College/Predictive Analytics/Data/exchange-rate-of-australian-doll.csv")
## Parsed with column specification:
## cols(
## Month = col_character(),
## `Exchange rate of Australian dollar: $A for 1 US dollar. Monthly average: Jul 1969 ? Aug 1995` = col_double()
## )
## Warning: 1 parsing failure.
## row # A tibble: 1 x 5 col row col expected actual expected <int> <chr> <chr> <chr> actual 1 315 <NA> 2 columns 1 columns file # ... with 1 more variables: file <chr>
exchange.ts=ts(exchange.data$`Exchange rate of Australian dollar: $A for 1 US dollar. Monthly average: Jul 1969 ? Aug 1995`,frequency=12, start=c(1969,7))
plot(exchange.ts, ylab="Australian dollar per 1 USD", xlab="Year")
We see that the data is non-stationary with no seasonality that I can notice.
plot(decompose(exchange.ts))
Split the Data:
head(exchange.data)
## # A tibble: 6 x 2
## Month
## <chr>
## 1 1969-07
## 2 1969-08
## 3 1969-09
## 4 1969-10
## 5 1969-11
## 6 1969-12
## # ... with 1 more variables: `Exchange rate of Australian dollar: $A for 1
## # US dollar. Monthly average: Jul 1969 ? Aug 1995` <dbl>
tail(exchange.data)
## # A tibble: 6 x 2
## Month
## <chr>
## 1 1995-04
## 2 1995-05
## 3 1995-06
## 4 1995-07
## 5 1995-08
## 6 Exchange rate of Australian dollar: $A for 1 US dollar. Monthly average: Ju
## # ... with 1 more variables: `Exchange rate of Australian dollar: $A for 1
## # US dollar. Monthly average: Jul 1969 ? Aug 1995` <dbl>
exchange.train=exchange.data[1:308,]
exchange.test=exchange.data[309:314,]
#Last 6 months
exchange.train.ts=ts(exchange.train$`Exchange rate of Australian dollar: $A for 1 US dollar. Monthly average: Jul 1969 ? Aug 1995`,frequency=12, start=c(1969,7))
exchange.test.ts=ts(exchange.test$`Exchange rate of Australian dollar: $A for 1 US dollar. Monthly average: Jul 1969 ? Aug 1995`,frequency=12, start=c(1995,3))
Fitting the Two Models
myets=ets(exchange.train.ts, model="ZZZ")
myarima=auto.arima(exchange.train.ts)
myets
## ETS(M,N,N)
##
## Call:
## ets(y = exchange.train.ts, model = "ZZZ")
##
## Smoothing parameters:
## alpha = 0.9762
##
## Initial states:
## l = 1.113
##
## sigma: 0.0277
##
## AIC AICc BIC
## -463.9057 -463.8267 -452.7154
myarima
## Series: exchange.train.ts
## ARIMA(0,1,0)
##
## sigma^2 estimated as 0.0007468: log likelihood=669.54
## AIC=-1337.08 AICc=-1337.07 BIC=-1333.35
arima.forecast=forecast(myarima, h=6)
ets.forecast=forecast(myets, h=6)
plot(arima.forecast)
plot(ets.forecast)
Accuracy: Let’s see how the two models performed in comparison to the test set
accuracy(arima.forecast, exchange.test.ts)
## ME RMSE MAE MPE MAPE
## Training set -0.001210669 0.02728346 0.01517894 -0.173668 1.698613
## Test set -0.011333333 0.01837571 0.01533333 -1.595267 2.127182
## MASE ACF1 Theil's U
## Training set 0.1995632 -0.03692003 NA
## Test set 0.2015931 0.24367145 1.169739
accuracy(ets.forecast, exchange.test.ts)
## ME RMSE MAE MPE MAPE
## Training set -0.001239269 0.02726999 0.01520193 -0.1777326 1.699661
## Test set -0.011773144 0.01865018 0.01562654 -1.6556487 2.168068
## MASE ACF1 Theil's U
## Training set 0.1998654 -0.01078625 NA
## Test set 0.2054480 0.24367145 1.185402
It seems that the ARIMA(0,1,0) was slightly better than the ETS model in almost all the error categories.