1 Modeling the Mexican peso exchange rate (MX/USD)

1.1 Get data

library(quantmod)
## Warning: package 'quantmod' was built under R version 4.0.3
## Loading required package: xts
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.0.3
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(PerformanceAnalytics)
## 
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
## 
##     legend
getSymbols(Symbols="DEXMXUS", src="FRED")
## 'getSymbols' currently uses auto.assign=TRUE by default, but will
## use auto.assign=FALSE in 0.5-0. You will still be able to use
## 'loadSymbols' to automatically load data. getOption("getSymbols.env")
## and getOption("getSymbols.auto.assign") will still be checked for
## alternate defaults.
## 
## This message is shown once per session and may be disabled by setting 
## options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.
## [1] "DEXMXUS"
library(readxl)
library(xts)
library(zoo)
library(tseries)
library(forecast)
library(astsa)
## Warning: package 'astsa' was built under R version 4.0.3
## 
## Attaching package: 'astsa'
## The following object is masked from 'package:forecast':
## 
##     gas
library(lmtest)


mexrate = to.monthly(DEXMXUS)
## Warning in to.period(x, "months", indexAt = indexAt, name = name, ...): missing
## values removed from data
mexrate = Cl(mexrate)

1.2 Visualize

plot(mexrate)

mexrate.ts <- ts(coredata(mexrate$DEXMXUS.Close), start = c(1993,11),frequency=12 )

1.3 Check for stationary

s12.mexrate <- diff(log(mexrate.ts), lag = 12)
plot(s12.mexrate)

1.4 Dicky Fuller Test

adf.test(diff(log(mexrate.ts), lag = 12), k = 0)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  diff(log(mexrate.ts), lag = 12)
## Dickey-Fuller = -3.4591, Lag order = 0, p-value = 0.04695
## alternative hypothesis: stationary

1.5 Calibrate model

acf2(diff(log(mexrate.ts), lag = 12), max.lag = 24)

##      [,1]  [,2]  [,3]  [,4] [,5]  [,6]  [,7]  [,8]  [,9] [,10] [,11] [,12]
## ACF  0.93  0.84  0.76  0.67 0.60  0.53  0.46  0.40  0.32  0.24  0.15  0.06
## PACF 0.93 -0.13 -0.04 -0.10 0.11 -0.05 -0.04 -0.04 -0.14 -0.02 -0.19  0.03
##      [,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24]
## ACF   0.04  0.03  0.03  0.03  0.02  0.01 -0.01 -0.03 -0.04 -0.04 -0.04 -0.05
## PACF  0.38 -0.03  0.00 -0.09  0.03 -0.09  0.03 -0.05 -0.01 -0.03 -0.09 -0.02

1.6 Run Model

model1 <- Arima(mexrate.ts, order = c(1,0,0), 
            seasonal = list(order=c(0,1,0),period=12),
            include.constant = TRUE,
            lambda = 0) 

model1
## Series: mexrate.ts 
## ARIMA(1,0,0)(0,1,0)[12] with drift 
## Box Cox transformation: lambda= 0 
## 
## Coefficients:
##          ar1   drift
##       0.9298  0.0054
## s.e.  0.0202  0.0035
## 
## sigma^2 estimated as 0.002954:  log likelihood=473.38
## AIC=-940.75   AICc=-940.68   BIC=-929.48
coeftest(model1)
## 
## z test of coefficients:
## 
##        Estimate Std. Error z value Pr(>|z|)    
## ar1   0.9297921  0.0202014 46.0261   <2e-16 ***
## drift 0.0053892  0.0034740  1.5513   0.1208    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Interpretation

The annual % growth of the mexican peso exchange rate is positively and significantly related with the annual % growth of the last month. For each unit increased the previous month the current annual % growth of the rate would increase in about 0.9297921 units.

1.6.1 Check Residuals

acf2(model1$residuals,max.lag = 24)

##      [,1] [,2] [,3]  [,4] [,5] [,6]  [,7] [,8]  [,9] [,10] [,11] [,12] [,13]
## ACF  0.15 0.03 0.07 -0.13 0.02 0.02 -0.02 0.13  0.00  0.10 -0.04 -0.45 -0.08
## PACF 0.15 0.01 0.06 -0.15 0.06 0.01  0.00 0.11 -0.04  0.12 -0.11 -0.43  0.04
##      [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24]
## ACF  -0.07  0.00  0.07  0.05  0.00  0.02 -0.06 -0.02 -0.05  0.03  0.00
## PACF -0.02  0.09 -0.06  0.10 -0.03  0.02  0.00 -0.01  0.07  0.01 -0.27

1.7 Model 2

model2 <- Arima(mexrate.ts, order = c(1,0,1), 
            seasonal = list(order=c(0,1,0),period=12),
            include.constant = TRUE,
            lambda = 0) 

coeftest(model2)
## 
## z test of coefficients:
## 
##        Estimate Std. Error z value  Pr(>|z|)    
## ar1   0.9054186  0.0254696 35.5489 < 2.2e-16 ***
## ma1   0.1920791  0.0646965  2.9689  0.002988 ** 
## drift 0.0052809  0.0030645  1.7232  0.084843 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

The annual % growth of the mexican peso exchange rate is positively and significantly related with the annual % growth of the last month. For each unit increased the previous month the current annual % growth of the rate would increase in about 0.9054186 units.

The annual % growth of the mexican peso exchange rate is positively related to the shock of 1 month ago.The shock affects on 0.1920791 units for each unit in the current annual growth

acf2(model2$residuals,max.lag = 24)

##       [,1] [,2] [,3]  [,4] [,5] [,6]  [,7] [,8]  [,9] [,10] [,11] [,12] [,13]
## ACF  -0.01 0.04 0.11 -0.13 0.06 0.03 -0.04 0.15 -0.04  0.10  0.03 -0.45  0.01
## PACF -0.01 0.04 0.11 -0.13 0.05 0.03 -0.01 0.13 -0.03  0.11  0.00 -0.44 -0.02
##      [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24]
## ACF  -0.07  0.00  0.07  0.03  0.00  0.03 -0.07  0.00 -0.06  0.05 -0.01
## PACF -0.02  0.11 -0.05  0.10 -0.01  0.01  0.01 -0.03  0.06  0.08 -0.26

1.8 Model 3 (Choseen)

model3 <- Arima(mexrate.ts, order = c(1,0,1), 
            seasonal = list(order=c(0,1,1),period=12),
            include.constant = TRUE,
            lambda = 0) 
model3
## Series: mexrate.ts 
## ARIMA(1,0,1)(0,1,1)[12] with drift 
## Box Cox transformation: lambda= 0 
## 
## Coefficients:
##          ar1     ma1     sma1   drift
##       0.9901  0.1311  -0.9690  0.0053
## s.e.  0.0138  0.0586   0.1182  0.0016
## 
## sigma^2 estimated as 0.001559:  log likelihood=560.96
## AIC=-1111.92   AICc=-1111.72   BIC=-1093.12
acf2(model3$residuals,max.lag = 24)

##       [,1] [,2] [,3]  [,4] [,5]  [,6]  [,7]  [,8]  [,9] [,10] [,11] [,12] [,13]
## ACF  -0.01 0.01 0.08 -0.16 0.03 -0.03 -0.03  0.02 -0.01  0.14  0.05  0.03 -0.04
## PACF -0.01 0.01 0.08 -0.16 0.03 -0.03 -0.01 -0.01  0.01  0.14  0.05  0.03 -0.07
##      [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24]
## ACF  -0.07  0.02 -0.01  0.04 -0.03  0.02 -0.05  0.03  0.06  0.06  0.02
## PACF -0.04  0.02  0.01  0.04 -0.05  0.03 -0.09  0.04  0.03  0.10  0.01
coeftest(model3)
## 
## z test of coefficients:
## 
##         Estimate Std. Error z value  Pr(>|z|)    
## ar1    0.9900880  0.0137955 71.7691 < 2.2e-16 ***
## ma1    0.1311294  0.0585977  2.2378 0.0252348 *  
## sma1  -0.9689740  0.1181553 -8.2009 2.387e-16 ***
## drift  0.0052959  0.0015637  3.3867 0.0007074 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
model3$aic
## [1] -1111.918

1.8.1 Interpretation of selected Model

The annual % growth of the mexican peso exchange rate is positively and significantly related with the annual % growth of the last month. For each unit increased the previous month the current annual % growth of the rate would increase in about 0.9900880 units.

The annual % growth of the mexican peso exchange rate is positively related to the shock of 1 month ago.The shock affects on 0.1311294 units for each unit in the current annual growth

The annual % growth of the mexican peso exchange rate is negatively and significantly related with the annual % growth of 2 months ago, after considering the autocorrelation of lag 1 with the current annual % growth

We would keep with the Model 3

1.9 Forecast

forecast_mexrate <- forecast(model2, h=21)

# I plot the forecast
autoplot(forecast_mexrate)