Problem 3

First we need to import EUR/USD exchange rate into R and do a log transformation:

exrate1 <- Quandl("ECB/EURUSD", type="zoo")
exrate <- exrate1[,4]
lexrate <- diff(log(exrate))

EWMA and GARCH(1,1) Volatility Model

For the Exponentially Weighted Moving Average or EWMA, we use the following code to calculate and plot EWMA:

lexrate.ewma <- EWMA((lexrate-mean(lexrate))^2,lambda=.05)
plot(lexrate.ewma, type="l", main="Exponentially Weighted Moving Average")

GARCH(1,1) Estimation

For GARCH(1,1) estimation with normal innovation, we use the following code:

garch11 <- garchFit( ~ garch(1,1), data=coredata(lexrate), trace=FALSE) 
summary(garch11)

Title:
 GARCH Modelling 

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

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

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 23:09:23 2016 by user: evanu 


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 

5% Var and 1% Var

Calculating 1% VaR and 5% VaR for EWMA and GARCH(1,1):

var5ewma <- mean(lexrate) - 1.645 * sqrt(lexrate.ewma)
var5garch <- mean(lexrate) - 1.645 * garch11@sigma.t
var1ewma <- mean(lexrate) - 2.326 * sqrt(lexrate.ewma)
var1garch <- mean(lexrate) - 2.326 * garch11@sigma.t

Plotting our previous calculation:

timeindex <- index(lexrate)
par(mfrow=c(2,2), cex=0.6, mar=c(2,2,3,1))

plot(timeindex, lexrate,type="l", main ="5% VaR EWMA")
lines(timeindex, var5ewma, col = "blue")
plot(timeindex, lexrate,type="l", main ="1% VaR EWMA")
lines(timeindex, var1ewma, col = "blue")

plot(timeindex, lexrate,type="l", main ="5% VaR GARCH")
lines(timeindex, var5garch, col ="blue")
plot(timeindex, lexrate, type="l", main ="1% VaR GARCH")
lines(timeindex, var1garch, col ="blue")

Calculating fraction of times in the sample where the log change fall below the 5% VaR and 1% VaR.

sum(lexrate < var5ewma)/length(lexrate) # fraction of sample where loss exceeds EWMA 5% VaR
[1] 0.04624802
sum(lexrate < var1ewma)/length(lexrate) # fraction of sample where loss exceeds EWMA 1% VaR
[1] 0.007481297
sum(lexrate < var5garch)/length(lexrate) # fraction of sample where loss exceeds GARCH 5% VaR
[1] 0.04670143
sum(lexrate < var1garch)/length(lexrate) # fraction of sample where loss exceeds GARCH 1% VaR
[1] 0.01314895

Largest Depreciation

Code for calculation and time identification:

min(lexrate) # onservation with the largest depreciation of EUR to USD
[1] -0.04735441
index(lexrate[lexrate==min(lexrate)]) # day of the largest depreciation
[1] "2008-12-19"
min(var5ewma)  # largest depreciation by EWMA 5% VaR
[1] -0.02911564
min(var1ewma)  # largest depreciation by EWMA 1% VaR
[1] -0.04116379
min(var5garch) # largest depreciation by GARCH 5% VaR
[1] -0.02439871
min(var1garch) # largest depreciation by GARCH 1% VaR
[1] -0.03449413

The largest depreciation for EUR compared to USD happened on 12/19/2008.