In this part of the question EUR vs USD Foreign Exchange Reference Rate (EUR/USD) will be analyzed.
Fisrt let’s start with the models of EWWA and GARCH(1,1)
library(Quandl)
library(tseries)
library(fTrading)
## Warning: package 'fTrading' was built under R version 3.2.4
## Warning: package 'timeSeries' was built under R version 3.2.4
## Warning: package 'fBasics' was built under R version 3.2.4
library(fGarch)
## Warning: package 'fGarch' was built under R version 3.2.4
er=Quandl("ECB/EURUSD", type="zoo")
str(er)
## 'zoo' series from 1999-01-04 to 2016-03-24
## Data: num [1:4412] 1.18 1.18 1.17 1.16 1.17 ...
## Index: Date[1:4412], format: "1999-01-04" "1999-01-05" "1999-01-06" "1999-01-07" ...
head(er)
## 1999-01-04 1999-01-05 1999-01-06 1999-01-07 1999-01-08 1999-01-11
## 1.1789 1.1790 1.1743 1.1632 1.1659 1.1569
tail(er)
## 2016-03-17 2016-03-18 2016-03-21 2016-03-22 2016-03-23 2016-03-24
## 1.1311 1.1279 1.1271 1.1212 1.1171 1.1154
plot(er, xlab="", ylab="", main="EUR/USD exchange rate (ER)")
Now let’s log transform it and take first difference:
ler = log(er)
dler = diff(ler)
plot(dler, xlab="", ylab="", main="Difference of lof transformed EUR/USD")
The volatility model for the GARCH(1,1) model will be:
garch = garchFit( ~ garch(1,1), data=dler, trace=FALSE)
garch
##
## Title:
## GARCH Modelling
##
## Call:
## garchFit(formula = ~garch(1, 1), data = dler, trace = FALSE)
##
## Mean and Variance Equation:
## data ~ garch(1, 1)
## <environment: 0x075637e0>
## [data = dler]
##
## Conditional Distribution:
## norm
##
## Coefficient(s):
## mu omega alpha1 beta1
## 4.8760e-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.56764
## 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 14:23:36 2016 by user: bahundja
summary(garch)
##
## Title:
## GARCH Modelling
##
## Call:
## garchFit(formula = ~garch(1, 1), data = dler, trace = FALSE)
##
## Mean and Variance Equation:
## data ~ garch(1, 1)
## <environment: 0x075637e0>
## [data = dler]
##
## Conditional Distribution:
## norm
##
## Coefficient(s):
## mu omega alpha1 beta1
## 4.8760e-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.56764
## 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 14:23:36 2016 by user: bahundja
##
##
## Standardised Residuals Tests:
## Statistic p-Value
## Jarque-Bera Test R Chi^2 467.2633 0
## Shapiro-Wilk Test R W 0.9897908 0
## Ljung-Box Test R Q(10) 6.083834 0.8081714
## Ljung-Box Test R Q(15) 15.8161 0.3943783
## Ljung-Box Test R Q(20) 18.80033 0.5348368
## Ljung-Box Test R^2 Q(10) 6.912299 0.7336977
## Ljung-Box Test R^2 Q(15) 7.365895 0.94669
## Ljung-Box Test R^2 Q(20) 12.06333 0.913879
## LM Arch Test R TR^2 7.002462 0.8574508
##
## Information Criterion Statistics:
## AIC BIC SIC HQIC
## -7.366361 -7.360565 -7.366363 -7.364317
The volatility model for the EWMA model will be:
mdler = mean(dler)
ind=index(dler)
smadler <- SMA((dler-mdler)^2,n=100)
edler = EWMA((dler - mdler)^2,lambda=0.05)
plot(edler, type="l", main="EWMA volatility model")
v5ewma = mdler - 1.6 * sqrt(dler)
## Warning in sqrt(dler): NaNs produced
v1ewma = mdler - 2.326 * sqrt(dler)
## Warning in sqrt(dler): NaNs produced
par(mfrow = c(1,2))
plot(ind, dler, main = "5% VAR-EWMA")
lines(ind, v5ewma, col = "blue")
plot(ind, dler, main = "1% VAR-EWMA")
lines(ind, v1ewma, col = "blue")
v5garch = mdler - 1.6 * garch@sigma.t
v1garch = mdler - 2.326 * garch@sigma.t
par(mfrow = c(1,2))
plot(ind, dler, main = "5% VAR garch")
lines(ind, v5garch, col ="blue")
plot(ind, dler, main = "1% VAR garch")
lines(ind, v1garch, col ="blue")