Predicting foreign exchange rates

Our third and final data set will be constructed from a historical database of Euro Foreign Exchange Reference rates provided by the website of the European Central Bank. We can download a zipped archive containing the data from http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.zip. When unzipped, this archive contains a file titled eurofxref-hist.csv, which we can directly import into R using the read.csv() function:

> eurofxref.hist <- read.csv("eurofxref-hist.csv",
                             stringsAsFactors = F)
> eurofxref.hist[1 : 6, 1 : 6]
        Date    USD    JPY    BGN CYP    CZK
1 2014-09-05 1.2948 136.27 1.9558 N/A 27.596
2 2014-09-04 1.3015 136.89 1.9558 N/A 27.662
3 2014-09-03 1.3151 138.11 1.9558 N/A 27.658
4 2014-09-02 1.3115 137.63 1.9558 N/A 27.784
5 2014-09-01 1.3133 136.97 1.9558 N/A 27.738
6 2014-08-29 1.3188 137.11 1.9558 N/A 27.725

As we can see, our data frame contains the conversion rates for several different currencies. As this file is continually updated by the Central Bank, downloading the file today will produce a data frame that begins at a more recent date than that shown. Note that the data are in reverse chronological order and that there are some gaps in the dates. These gaps occur on weekends or bank holidays when no trading took place.

We have chosen to focus on the time series of Euro to American Dollar exchange rates. As a first step, we will restrict the date range of our time series. This will allow all our analysis to be reproduced exactly irrespective of the date that the data is downloaded. Specifically, we will limit the rows of our data frame to the years 2005-2013 (both years inclusive) and produce a time series obtained by reversing the USD column (to sort the data chronologically):

> selector <- (eurofxref.hist$Date <= as.Date('2013-12-31')) & 
              (eurofxref.hist$Date >= as.Date('2005-01-01'))
> eurofxref.hist <- eurofxref.hist[selector, ]
> euro_usd <- ts(rev(eurofxref.hist$USD))

Let's plot these data to see what it looks like:

Predicting foreign exchange rates

Here we will use the fGarch package, which provides us with the garchFit() function for training GARCH models. In finance, the GARCH(1, 1) process is quite commonly used, but as we know with a GARCH model, we are predicting the way the variance behaves over time. In order to model the behavior of the time series as a whole, we will also add an ARMA component.

We have repeated the steps to estimate the order of an ARIMA model, which we used with the previous two time series, and obtained that an ARMA(4, 4) model is appropriate for use with our economic time series. So we will investigate what a model with an ARMA(4, 4) and GARCH(1, 1) component predicts for our time series. With the garchFit() function, we need to specify the model parameters slightly differently via a formula:

> euro_usd_garch <- garchFit(~ arma(4,4) + garch(1, 1), data  = euro_usd, trace = FALSE)

Tip

At the time of this writing, there is a documented issue with the fGarch package that prevents the predict() function from working when a model is trained with an ARMA component that is of a higher order than ARMA(2, 2). For this reason, in the following plot, we will use this latter configuration.

With our model trained, we can now obtain a prediction:

> predict(euro_usd_garch, n.ahead = 20, plot = TRUE)

The following plot shows our forecast for this time series:

Predicting foreign exchange rates

The prediction is that the series will decrease slightly in the next few time periods. Note how the GARCH component of our model causes our confidence interval to widen significantly over the next few time intervals.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.29.145