R code: Understanding Dynamic Conditional Correlation (DCC) model

This post explains the structure of DCC (dynamic conditional correlation) model of Engle (2002) and then, uses rmgarch R package for estimating DCC model. This R package also provides various extended versions of DCC model.

The Aurora Borealis in the northern Finland in winter


Dynamic Conditional Correlation model



Engle (2002) proposed the dynamic conditional correlation model as a multivariate GARCH model. DCC describes the time-varying conditional correlation matrix.

DCC model uses a GARCH specification as well as a DCC specification. The GARCH specification in rugarch R package is explained in the previous post,




Understanding the structure of DCC model


Like the univariate GARCH(1,1) model, DCC(1,1) model also starts from the error vector since it is a kind of multivariate GARCH model.


Error vector in a mean equation \[\begin{align} \epsilon_t = H_t^{1/2} Z_t \end{align}\] \(H_t\) is the conditional covariance matrix. Therefore we can interpret \(H_t^{1/2}\) as a multivariate version of conditional volatility but with information of conditional correlation.


Conditional covariance matrix and its decomposition (≈ stdev × corr × stdev) \[\begin{align} H_t &\equiv D_t R_t D_t = (\rho_{ij} \sqrt{h_{ii,t}h_{jj,t}}) \end{align}\] Since \(H_t\) is a conditional covariance matrix, it can be decomposed with the conditional correlation (\(R_t\)) and volatility (\(D_t\)).


Conditional volatility of the error terms \[\begin{align} D_t &\equiv \text{diag}(h_{11,t}^{\frac{1}{2}}, ...,h_{kk,t}^{\frac{1}{2}}) \end{align}\] \(D_t\) is the diagonal matrix of time varying standard deviation (conditional volatility) from a univariate GARCH process. Therefore, the conditional variance (\(h_{ii,t}\)) is assumed to follow the GARCH process.

\[\begin{align} h_{11,t} = \text{GARCH}(1,1) \\ h_{22,t} = \text{GARCH}(1,1) \\ ... \\ h_{kk,t} = \text{GARCH}(1,1) \end{align}\]
As our focus is to make \(R_t\) time-varying like the equation for the conditional volatility of GARCH model, we do not use \(\epsilon_t\) since \(R_t\) is not a covariance of \(\epsilon_t\) but a correlation of it. The equation for the conditional volatility of GARCH model includes one or more products of error terms which reflect new information or innovation. This type of product terms can be interpreted as a kind of covariance not correlation. Therefore, we need new error term, the covariance of which is \(R_t\).


Standardized error vector (= error / conditional volatility) \[\begin{align} \tilde{\epsilon}_t = D_t^{-1}\epsilon_t &=\left(\frac{\epsilon_{1t}}{h_{11,t}^{1/2}}, ...,\frac{\epsilon_{kt}}{h_{kk,t}^{1/2}}\right)^{'} \\ &= (\tilde{\epsilon}_{1t}, ..., \tilde{\epsilon}_{kt})^{'} \end{align}\]
Why use \(\tilde{\epsilon}_t\)? Since its covariance is \(R_t\). Hence, \(\tilde{\epsilon}_t \times \tilde{\epsilon}_t^{'}\) can be included in the conditional correlation equation.


\(R_t\) : the conditional covariance of \(\tilde{\epsilon}_t\) \[\begin{align} \text{Cov}(\tilde{\epsilon}_t, \tilde{\epsilon}_t) &= \text{Cov}(D_t^{-1}\epsilon_t, D_t^{-1}\epsilon_t) \\ &= D_t^{-1}\text{Cov}(\epsilon_t, \epsilon_t)D_t^{-1} \\ &= D_t^{-1} H_t D_t^{-1} \\ &= D_t^{-1} D_t R_t D_t D_t^{-1} \\ &= R_t \\ &= \text{Corr}(\epsilon_t, \epsilon_t) \end{align}\]
It is worth noting that the conditional correlation between the disturbances (\(\text{Corr}(\epsilon_t, \epsilon_t) \)) is the conditional covariance between the standardized disturbances (\(\text{Cov}(\tilde{\epsilon}_t, \tilde{\epsilon}_t)\)).

As the purpose of DCC model is to estimate the time-varying correlation matrix \(R_t\), we can think of the following equation naturally.


Dynamics of time-varying correlation matrix (incorrect) \[\begin{align} R_t &= (1-\alpha-\beta)R + \alpha \tilde{\epsilon}_{t-1}\tilde{\epsilon}_{t-1}^{'} + \beta R_{t-1} \end{align}\] where R is the unconditional covariance matrix of the standardized error vector (\(\tilde{\epsilon}_t\)).

The above equation is looking good but it does not guarantee the basic structure of the correlation matrix such as a unit diagonal. Therefore we cannot use it and transform or constrain it in such a way that \(R_t\) should have diagonal elements of one and off-diagonal elements ranging from -1 and 1.

For this purpose, a two step approach is used: 1) unrestricted dynamics of conditional correlation matrix, 2) transform it into the structure of the correlation matrix.


Dynamics of the unconstrained time-varying conditional correlation matrix \[\begin{align} Q_t = (1-\alpha-\beta)R + \alpha \tilde{\epsilon}_{t-1}\tilde{\epsilon}_{t-1}^{'} + \beta Q_{t-1} \end{align}\] where R is the unconditional covariance matrix of the standardized error vector (\(\tilde{\epsilon}_t\)) and it is typical to be calculated from the sample data directly without an estimation.

The development of the unconstrained time-varying conditional correlation matrix is similar to that of conditional variance equation of GARCH model. However, we need to put constraints on these unconstrained dynamics.


Constrained time-varying correlation matrix (\(R_t\)) from unconstrained one (\(Q_t\)) \[\begin{align} R_t = \text{diag}(Q_t)^{-\frac{1}{2}} Q_t \text{diag}(Q_t)^{-\frac{1}{2}} \end{align}\] Since \(Q_t\) is denominated by its diagonal elements in both sides, diagonal elements are all one and off-diagonal elements are between -1 and 1. Therefore we can get the time-varying conditional correlation matrix correctly.



Summary of DCC model


Now we can summarize the full equations of DCC(1,1) model as follows.

\[\begin{align} \epsilon_t &= H_t^{1/2} Z_t \\ H_t &\equiv D_t R_t D_t \\ D_t &\equiv \text{diag}(h_{11,t}^{\frac{1}{2}}, ...,h_{kk,t}^{\frac{1}{2}}) \\ & \quad h_{11,t} = \text{GARCH}(1,1) \\ & \quad h_{22,t} = \text{GARCH}(1,1) \\ & \quad ... \\ & \quad h_{kk,t} = \text{GARCH}(1,1) \\ \tilde{\epsilon}_t &= D_t^{-1}\epsilon_t \\ Q_t &= (1-\alpha-\beta)R + \alpha \tilde{\epsilon}_{t-1}\tilde{\epsilon}_{t-1}^{'} + \beta Q_{t-1} \\ R_t &= \text{diag}(Q_t)^{-\frac{1}{2}} Q_t \text{diag}(Q_t)^{-\frac{1}{2}} \\ \end{align}\]



Data


Data are Dow Jones Industrial Average and NASDAQ Composite. Their index and returns are as follows.
R code: Understanding Dynamic Conditional Correlation (DCC) model, rmgarch
R code: Understanding Dynamic Conditional Correlation (DCC) model, rmgarch


R code


The following R code uses rmgarch R package to estimate GARCH(1,1)-DCC(1,1) model using dccfit() function and two specification functions: ugarchspec() and dccspec(). You can also perform forecasting exercises using dccforecast() function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#========================================================#
# Quantitative Financial Econometrics & Derivatives 
# Machine/Deep Learing, R, Python, Tensorflow 
# by Sang-Heon Lee 
#
# https://shleeai.blogspot.com
#--------------------------------------------------------#
# DCC model
#========================================================#
 
graphics.off(); rm(list = ls())
 
library(PerformanceAnalytics) # CalculateReturns
library(quantmod)
library(rugarch) # ugarchspec
library(rmgarch) # dccspec, dccfit
 
#===========================================
# Data
#===========================================
 
# Dow Jones Industrial Average (^DJI)
# NASDAQ Composite (^IXIC) 
symbol.vec = c("^DJI""^IXIC")
getSymbols(symbol.vec, from ="1992-01-01", to = "2000-1-1")
 
# extract adjusted closing prices
DJ <- DJI [, "DJI.Adjusted" , drop=F]
ND <- IXIC[, "IXIC.Adjusted", drop=F]
 
# calculate log-returns & remove first NA
DJ.ret = CalculateReturns(DJ, method="log")[-1,]
ND.ret = CalculateReturns(ND, method="log")[-1,]
colnames(DJ.ret) = "DowJones"
colnames(ND.ret) = "Nasdaq"
 
# create combined data series horizontally
DJ.ND.ret = merge(DJ.ret, ND.ret)
 
#===========================================
# DCC estimation
#===========================================
 
#----------------------------------------------
# univariate normal GARCH(1,1) for each series
#----------------------------------------------
garch11.spec = ugarchspec(
    mean.model = list(armaOrder = c(0,0), 
                      include.mean=FALSE), 
    variance.model = list(garchOrder = c(1,1), 
                          model = "sGARCH"), 
    distribution.model = "norm")
 
#---------------------------------------------------
# DCC spec: GARCH(1,1) for conditional correlations
#---------------------------------------------------
dcc.garch11.spec = dccspec(
    uspec = multispec(replicate(2, garch11.spec)),
    dccOrder = c(1,1), distribution = "mvnorm")
 
dcc.garch11.spec
 
#--------------------------------
# fitting DCC model
#--------------------------------
dcc.fit = dccfit(dcc.garch11.spec, data = DJ.ND.ret)
dcc.fit
 
# conditional sd of each series
x11(); plot(dcc.fit, which=2)
# Conditional Covariance
x11(); plot(dcc.fit, which=3)
# conditional correlation
x11(); plot(dcc.fit, which=4)
 
cs


After running the above R code, we can draw figures for conditional volatility estimates of each GARCH models.

R code: Understanding Dynamic Conditional Correlation (DCC) model, rmgarch

we can also draw plots of dynamic conditional covariance and correlation with which = 2, 3, 4 option.
R code: Understanding Dynamic Conditional Correlation (DCC) model, rmgarch

Estimation results of DCC model consist of parameter estimates of individual GARCH and DCC model.

R code: Understanding Dynamic Conditional Correlation (DCC) model, rmgarch


Concluding Remarks


This post tried to give a kind understanding of DCC model and then introduces rmgarch R package to estimate the DCC model. I think DCC model is so powerful and rmgarch R package is so helpful. This package also provides a variety of extended DCC models and you can find them in the rmgarch manual. \(\blacksquare\)


No comments:

Post a Comment

Tentative Topics (Keeping Track to Avoid Forgetting)

Segmented Nelson-Siegel model
Shifting Endpoints Nelson-Siegel model
Nadaraya-Watson estimator
Locally weighted scatterplot smoothing (LOWESS)
Time-Varying Parameter Vector Autoregressions (TVP-VAR)
Time-varying or Dynamic Copula
Bayesian VAR
Adrian-Crump-Moench (ACM) term premium model
GARCH-EVT-Copula approach