Problem 3

The first step is to import EUR/USD currency pair exchange rate, ECB/EURUSD, using Quandl packages. We will denote ECB/EURUSD as \(EURUSD_{t}\).

EURUSD <- Quandl("ECB/EURUSD", type="zoo")
eurusd <- EURUSD[,4]

Next step is to construct the log change of \(EURUSD_{t}\), \(y_{t}\), as follow:

yt <- diff(log(eurusd))

where \(y_{t} = \Delta \log{EURUSD_{t}}\)

(a) Building EWMA and GARCH(1,1) Volatility Model

(i) Constructing EWMA

To construct Exponentially Weighted Moving Average or EWMA, we need to use the following code:

ybar <- mean(yt)
eurusd.ma4 <- SMA((yt-ybar)^2,n=4)
eurusd.ma24 <- SMA((yt-ybar)^2,n=24)
eurusd.ewma <- EWMA((yt-ybar)^2,lambda=.05) # note: in EWMA lambda is actually 1-lambda

For the lambda, we arbitrarily choose lambda=0.05. Compared to convetional moving average, EWMA put more weight on latest observation to be able to more strongly predict the trend. The next code is used to plot and compared all the calculateion of the moving averages.

par(mfrow=c(2,2), cex=0.6, mar=c(2,2,3,1))
plot((yt-ybar)^2, type="l", main="EURUSD squared demeaned weekly log return")
plot(eurusd.ma4, type="l", main="4 week moving average")
plot(eurusd.ma24, type="l", main="24 week moving average")
plot(eurusd.ewma, type="l", main="exponentially weighted moving average")

(ii) Estimating GARCH(1,1) with normal innovations

In this part we will estimate GARCH(1,1) model for log change of EURUSD, \(y_{t}\), using the following code. The result later will be compared with previously calculated EWMA.

garchmodel1 <- garchFit( ~ garch(1,1), data=coredata(yt), trace=FALSE) 
summary(garchmodel1)

Title:
 GARCH Modelling 

Call:
 garchFit(formula = ~garch(1, 1), data = coredata(yt), trace = FALSE) 

Mean and Variance Equation:
 data ~ garch(1, 1)
<environment: 0x000000001d97e6c8>
 [data = coredata(yt)]

Conditional Distribution:
 norm 

Coefficient(s):
        mu       omega      alpha1       beta1  
4.8764e-05  1.2316e-07  2.8535e-02  9.6896e-01  

Std. Errors:
 based on Hessian 

Error Analysis:
        Estimate  Std. Error  t value Pr(>|t|)    
mu     4.876e-05   8.531e-05    0.572  0.56760    
omega  1.232e-07   4.199e-08    2.933  0.00336 ** 
alpha1 2.854e-02   3.064e-03    9.313  < 2e-16 ***
beta1  9.690e-01   3.145e-03  308.091  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Log Likelihood:
 16250.51    normalized:  3.684087 

Description:
 Fri Mar 25 00:06:37 2016 by user: Rullan Rinaldi 


Standardised Residuals Tests:
                                Statistic p-Value  
 Jarque-Bera Test   R    Chi^2  467.2629  0        
 Shapiro-Wilk Test  R    W      0.9897908 0        
 Ljung-Box Test     R    Q(10)  6.083835  0.8081713
 Ljung-Box Test     R    Q(15)  15.8161   0.3943783
 Ljung-Box Test     R    Q(20)  18.80033  0.5348369
 Ljung-Box Test     R^2  Q(10)  6.912306  0.733697 
 Ljung-Box Test     R^2  Q(15)  7.365904  0.9466897
 Ljung-Box Test     R^2  Q(20)  12.06334  0.9138786
 LM Arch Test       R    TR^2   7.00247   0.8574503

Information Criterion Statistics:
      AIC       BIC       SIC      HQIC 
-7.366361 -7.360565 -7.366363 -7.364317 

(b) Calculating One and Five Percent VaR for EWMA and GARCH(1,1)

Using the following code we calculate and plot 1% VaR and 5% VaR for previously calculated (and estimated) EWMA and GARCH(1,1) model.

t <- index(yt)
var5.ewma  <- ybar - 1.645 * sqrt(eurusd.ewma)
var5.garch <- ybar - 1.645 * garchmodel1@sigma.t
var1.ewma  <- ybar - 2.326 * sqrt(eurusd.ewma)
var1.garch <- ybar - 2.326 * garchmodel1@sigma.t

par(mfrow=c(2,2), cex=0.6, mar=c(2,2,3,1))
plot(t, yt,type="l", main ="5% VaR EWMA")
lines(t, var5.ewma, col = "blue")
plot(t, yt,type="l", main ="5% VaR GARCH(1,1)")
lines(t, var5.garch, col ="blue")
plot(t, yt,type="l", main ="1% VaR EWMA")
lines(t, var1.ewma, col = "red")
plot(t, yt, type="l", main ="1% VaR GARCH(1,1)")
lines(t, var1.garch, col ="red")

From the figures above, we can see that 1% and 5% VaR are smoother for GARCH estimation compared to EWMA. However 1% and 5% VaR for EWMA relatively more “tight” compared to the actual data.

In the following code, we calculate the fraction of sample where loss exceed both 1% and 5% VaR for EWMA and GARCH(1,1).

sum(yt < var5.ewma)/length(yt) # fraction of sample where loss exceeds 5% VaR for EWMA
[1] 0.04624802
sum(yt < var5.garch)/length(yt) # fraction of sample where loss exceeds 5% VaR for GARCH(1,1)
[1] 0.04670143
sum(yt < var1.ewma)/length(yt) # fraction of sample where loss exceeds 1% VaR for EWMA
[1] 0.007481297
sum(yt < var1.garch)/length(yt) # fraction of sample where loss exceeds 1% VaR for GARCH(1,1)
[1] 0.01314895

(c) Day in the Sample with the Largest Drop in EUR/USD

To obtain the day in the sample with the largest drop and its magnitude, we need to extract several information from our series using the following code:

min(yt) # identify the observation within the sample with the largest drop in EUR/USD
[1] -0.04735441
index(yt[yt==min(yt)]) # day in the sample with the largest drop in EUR/USD
[1] "2008-12-19"
min(var5.ewma)  # largest loss in 5% VaR measured by EWMA
[1] -0.02911564
min(var5.garch) # largest loss in 5% VaR measured by GARCH(1,1)
[1] -0.02439871
min(var1.ewma)  # largest loss in 1% VaR measured by EWMA
[1] -0.04116379
min(var1.garch) # largest loss in 1% VaR measured by GARCH(1,1)
[1] -0.03449413

The largest drop in EUR/USD is -4.73%, which happened on 12/19/2008. Eventhough a drop by this magnitude cannot be captured by all VaR measurement (one and 5 percent based on EWMA and GARCH(1,1)), but the measurement of VaR that give us the closest prediction is 1% VaR measured by EWMA.

```