Week 5 - EViews Practice Note

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

125.

811 Advanced Risk Analytics

Week 5
Correlations and Copulas

1
Part I – Estimating conditional correlation with Dynamic Conditional
Correlation Model (Engle, 2002) using EViews

Dynamic Conditional Correlation (DCC) Model is a simple class of the Multivariate GARCH model proposed
by Engle (2002) in the article published in Journal of Business & Economic Statistics with the same title. It
is called “Multivariate” because it can model two or more time series variables at the same time taking
into account their dependence structure (i.e., correlation matrix).

In the first part of this note, we will discuss the specification of the model and how can we apply it in
EViews. For simplicity, we will illustrate the case of DCC(1,1) for two time series with an assumption of
joint normal distribution.

For an user-guide friendly usage with click-and-see approach, you need to download the DCCGARCH11
add-in and install it in EViews, which is available for free here,
http://forums.eviews.com/viewtopic.php?t=9677

At the end of this document, you are also provided the EViews code for reference.

1. DCC-MGARCH: the model specification for DCC(1,1)

Consider there are two financial return series 𝑟1,𝑡 and 𝑟2,𝑡 . Let assume they are both white noise
processes and have a joint normal distribution with zero mean and variance-covariance Ω𝑡 .1

𝑟1,𝑡 2
0 𝜎1,𝑡 𝜎12,𝑡
[𝑟 ] |𝐼𝑡−1 ~ 𝑀𝑉𝑁 ( , [ 2 ]) (1)
2,𝑡 0 𝜎 21,𝑡 𝜎2,𝑡

where 𝐼𝑡−1 represents the information set available at time t-1. The symbol “|” means conditional, this
means, when taking into account of all information available up to (and include) time t-1, the
conditional distribution of return series follow a Multivariate Normal distribution (MVN), with a time-
varying variance-covariance matrix
2
𝜎1,𝑡 𝜎12,𝑡
Ω𝑡 = [ 2 ] (2)
𝜎21,𝑡 𝜎2,𝑡

Subscription t indicates the “time-varying” behavior of this conditional variance-covariance matrix (i.e.,
their values can be different in every point in time)2. The correlation emerged from these conditional
variance and covariance is therefore “conditional” or time-varying too. That is why it has the name
“Dynamic Conditional Correlation”.

1
As in previous week’s practice document, you can also model the mean equation of 𝑟1,𝑡 , and 𝑟2,𝑡 with ARMA
structure to capture the serial correlation in the return level itself.
2
In opposite, when we say “unconditional”, this is the average value of a variable calculated over a long period of
time and it does not depend on time. We can think “unconditional” as a mean of a variable. For example,
unconditional variance is the long-term variance which can be calculated as an average of variances over a long
period of time.

2
From the variance-covariance matrix Ω𝑡 , one can decompose it to show the Correlation matrix 𝑅𝑡 as:

Ω𝑡 = 𝐷𝑡 𝑅𝑡 𝐷𝑡 (3)

where

 0 
Dt =  1,t 
 0  2,t 

 1 12,t 
Rt =  
 12,t 1 

Engle (2002) shows that the correlation can be equivalently calculated using the elements of the
conditional variance-covariance matrix of standardized residuals of the two-return series (𝑧1,𝑡 , and
𝑧2,𝑡 ).

𝑟1,𝑡
𝑧1,𝑡 = (4)
𝜎1,𝑡
𝑟2,𝑡
𝑧2,𝑡 = (5)
𝜎2,𝑡

According to this standardization, we can see that the distribution of 𝑧1,𝑡 and 𝑧2,𝑡 is close to standard
normal distribution, which has unconditional mean of zero and unconditional mean of standard
deviation as 1, and their unconditional joint-distribution is close to bivariate standard normal
distribution. This may help the model optimization achieve a consistent result easier.

The conditional variance-covariance matrix of 𝑧1,𝑡 and 𝑧2,𝑡 is denoted as:

2
𝑞1,𝑡 𝑞12,𝑡
Q𝑡 = [ 2 ]
𝑞21,𝑡 𝑞2,𝑡

Based on these notations, the conditional correlation, that we need to estimate, can be calculated as,
𝑞12,𝑡
𝜌12,𝑡 = (6)
𝑞1,𝑡 𝑞2,𝑡

Now we can see, in order to estimate the 𝜌12,𝑡 , we need to estimate the 𝑞12,𝑡 , 𝑞1,𝑡 , and 𝑞2,𝑡 . A
convenient way is to use a specification that is similar to the GARCH(1,1) model for these conditional
variance and covariance of the standardized residuals. This is what Engle(2002) proposed. In the case
of two assets, we can write this model as:
2 2 2
𝑞1,𝑡 = (1 − 𝜃1 − 𝜃2 ) + 𝜃1 𝑧1,𝑡−1 + 𝜃2 𝑞1,𝑡−1
{𝑞12,𝑡 = (1 − 𝜃1 − 𝜃2 )𝜌12 + 𝜃1 𝑧1,𝑡−1 . 𝑧2,𝑡−1 + 𝜃2 𝑞12,𝑡−1 (7)
2 2 2
𝑞2,𝑡 = (1 − 𝜃1 − 𝜃2 ) + 𝜃1 𝑧2,𝑡−1 + 𝜃2 𝑞2,𝑡−1

3
Where 𝜌12 is the unconditional correlation, which can be calculated using the data for the whole
sample. 𝜃1 and 𝜃2 are the two parameters we need to estimate so that we can generate the 𝑞12,𝑡 ,
𝑞1,𝑡 , and 𝑞2,𝑡 series.

We can see that, in order to estimate this “GARCH” type model (7), we need the series of standardized
residuals 𝑧1,𝑡 and 𝑧2,𝑡 . As the return series (𝑟1,𝑡 and 𝑟2,𝑡 ) are observable, which are what we already
have, we will need the variance series of the return series, 𝜎1,𝑡 and 𝜎2,𝑡 to calculate 𝑧1,𝑡 and 𝑧2,𝑡 as in
Equation (4) and (5).

To solve this problem, we can easily use univariate GARCH(1,1) as studied in week 4 to generate the
𝜎1,𝑡 and 𝜎2,𝑡 as

2 2 2
𝜎1,𝑡 = 𝜔1 + 𝛼1 𝑟1,𝑡−1 + 𝛽1 𝜎1,𝑡−1
{ 2 2 2 (8)
𝜎2,𝑡 = 𝜔2 + 𝛼2 𝑟2,𝑡−1 + 𝛽2 𝜎2,𝑡−1

Therefore, the procedure would be two-step estimation method.

• In the first step estimation, we need to estimate model (8) separately for each equation. After we
have the estimated parameters of (8), we can generate the GARCH series 𝜎̂1,𝑡 and 𝜎̂2,𝑡 . 𝑧̂1,𝑡 and
𝑧̂2,𝑡 are then can be generated using (4) and (5).

• In the second step estimation, the estimated 𝑧̂1,𝑡 and 𝑧̂2,𝑡 are then can be used to estimate the model
(7) using the following log-likelihood function that was shown in Engle (2002)
𝑇
1
𝐿𝐶𝑜𝑟 = − ∑(𝑙𝑜𝑔 | 𝑅𝑡 |+𝑧 ′ 𝑡 𝑅𝑡−1 𝑧𝑡 − 𝑧 ′ 𝑡 𝑧𝑡 ) (9)
2
𝑡=1

2. Estimating the DCC-MGARCH with a system of two variables in EViews

We will illustrate the estimation of DCC(1,1) model using the data in bond_stockcorreal.wf1. This
Eviews workfile contains the two returns series of the S&P 500 (named as rsp) and 10-year government
bond index of the US (named as rb) from 02 Jan 1990 to 01 Oct 2008. The estimated dynamic
correlation shows us some evidence of “flight-to-quality” phenomenon during the market crises,
including the Dot-com bubble crisis 2002 and the Global Financial Crisis 2008.

In the first step estimation, we need to estimate the GARCH(1,1) model for each return series,
assuming normal distribution and no model is required for the mean equation:
2 2 2
𝜎1,𝑡 = 𝜔1 + 𝛼1 𝑟1,𝑡−1 + 𝛽1 𝜎1,𝑡−1
{ 2 2 2
𝜎2,𝑡 = 𝜔2 + 𝛼2 𝑟2,𝑡−1 + 𝛽2 𝜎2,𝑡−1

In the menu of Eviews, click Quick/Estimate Equation Type in the box, rsp , and choose the method
ARCH – Autoregressive Conditional Heteroskedasticity

4
A pop-up box appears. In the default setting, the model is GARCH(1,1), the error distribution is normal
distribution and there is no restriction on variance target. Keep the default option as appear that ARCH
order is 1 and GARCH order is 1. Name the Equation as EQ_RSP. The output looks like as follows:

5
Apply similar steps to bond return series (rb), we have the GARCH(1,1) model of rb as follows:

Next step is to generate the standardized residual (𝑧̂1,𝑡 and 𝑧̂2,𝑡 ) from the estimated GARCH(1,1) models
of the two returns series following Equation (4) and (5). Eviews provides the convenient tool to
automatically extract these 𝑧̂1,𝑡 and 𝑧̂2,𝑡 series: In the Equation windows, click Proc/Make Residual Series,
a pop-up will appear, choose the option Standardized and name the series as z1. Similarly, we can
generate z2 as a standardized residual series for the bond return case (rb)

6
2 2
Now that we have the estimated z1 and z2 series, we need to generate the starting values of the 𝑞1,𝑡 , 𝑞2,𝑡
and 𝑞12,𝑡 because the data generating process in Equation (7) would need these starting points to
generate the whole series of variance-covariance of the standardized residuals given the parameters. We
can simply assign the unconditional (or average) variance-covariance of the standardized residuals as the
starting values. For each series (one by one), click to Quick/Generate Series and type in the box as:

For the variance of z1

For variance of z2

For the covariance of z1 and z2

7
Now we can perform the 2nd step estimation by applying the Maximum Log-Likelihood Estimation to
Equation (9) to obtain the estimated parameters of system (7), which are 𝜃1 , 𝜃2 and then generate the
dynamic conditional correlation.

Note that when the numerical optimization (i.e., EViews will search the optimal value of 𝜃1 , 𝜃2 using an
algorithm using a specified starting value), we will need to declare the 𝜃1 , 𝜃2 and their starting values for
the algorithm to search. So first we need to create an object which tells Eviews which coefficient need to
be estimated and what is the starting value. Click to Object/New Object and choose Matrix-Vector-Coef
and name it with T, choose Coefficient Vector with 2 row and 1 column as we have two parameters. After
the coefficient vector is created, you can edit the starting value, let make it starting value of the first row
is 0.2 and the second row is 0.7.

We now can create the Logl object in EViews to represent the Equation (9), by clicking to Object/New
Object in the Eviews menu and choose LogL, name the object as DCC

8
In the Lol object window, type in the following commands:

Click to Estimate, choose the sample for estimation is 1/04/1990 10/01/2008 (due to there are missing
values on 02nd and 03rd of January) then Click OK and you can see the estimated value of 𝜃1 , 𝜃2

9
You can also see the estimated values of the correlation, named as RHO12, graph it, you can see the
RHO12 is time-varying and we can observe its significant negative values during the crises, indicating
“flight-to-quality” phenomenon, in which investors tend to shift their investors from risky assets (stock)
to a safe haven asset (government bond).

10
Part II – Application of Copulas on Loan Portfolio

This part will illustrate how we can estimate the Copula correlation and the unconditional default
probability of a loan portfolio following the One factor Gaussian Copula Model:

𝑈𝑖 = 𝑎𝐹 + √(1 − 𝑎2 )𝑍𝑖

Where 𝐹 and 𝑍𝑖 follows standard normal distribution. 𝑍𝑖 is uncorrelated with each other and also with 𝐹.

In an application to loan portfolio, 𝑖 stands for loan 𝑖th in the portfolio and 𝑈𝑖 is the transformed variable
from the time to default of loan i in the portfolio (𝑇𝑖 ) using the percentile-to-percentile mapping under the
Copula approach.

Note that, 𝐹 is the common factor for every loan in the portfolio, which makes loans in the portfolio
correlated. 𝑍𝑖 is the idiosyncratic factor that specifically belongs to loan 𝑖th.

The model is known as Vasicek’s Model. Base on this specification, we can estimate the Copula correlation
(𝜌 = 𝑎2 ) and the unconditional Probability of Default (i.e., 𝑃𝐷 = 𝑃𝑟𝑜𝑏(𝑇1 < 𝑇)) by Maximizing the sum
of the log of the following probability density function (the Maximum Likelihood Estimation method):

2
1−𝜌 1 √1 − 𝜌𝑁 −1 (DR) − 𝑁 −1 (PD)
𝑔(DR) = √ exp { [(𝑁 −1 (DR))2 − ( ) ]} (10)
𝜌 2 √𝜌

Now, let illustrate this estimation in EViews, first, let import the Default rate data (name,
Defaultrates_EV.xls) into EViews, you can see there is the annual default rate, namely dr.

There are two parameters to be estimated 𝜌 and PD, so we need to declare and give the starting values
of these two coefficients.

Click to Object/New Object and choose Matrix-Vector-Coef and name it with param, choose Coefficient
Vector with 2 row and 1 column as we have two parameters. After the coefficient vector is created, you
can edit the starting value, let make it starting value of the first row is 0.1 (representing 𝜌) and the second
row is 0.01 (representing PD).

11
We now can create the Logl object in EViews to represent the Equation (10), by clicking to Object/New
Object in the Eviews menu and choose LogL, name the object as Vasicek

In the Lol object window, type in the following commands:

Click to Estimate and choose the sample for estimate as 1970 2016. After clicking to OK, you can see the
estimation output of the Copula correlation (Param(1)) and the conditional probability of default
(Param(2))

12
13
Part III – Codes for reference

1. Codes for DCC(1,1) Model

'************************************************************************************
*************************************************************************************
********************************
'Project: DCC of US stock and Bond return
'This program is to estimate the model DCC (1,1) proposed by Engle (2002)
'Reference: Engle, R.F. ( 2002). Dynamic conditional correlation: A simple class of multivariate
generalized autoregressive conditional heteroskedasticity models. Journal of Business & 'Economic
Statistics 20, 339-350.
'This code run properly with Eviews 5 or later
'Hung Do
'************************************************************************************
*************************************************************************************
********************************

'change path to program path


%path=@runpath
cd %path

'load workfile containing the return series


load bond_stockcorrel.WF1

'set sample range


sample s1 01/04/1990 10/01/2008
scalar pi=3.14159

'fitting univariate GARCH(1,1) models to each of the two returns series


equation eq_rsp.arch(1,1,m=1000,h) rsp
equation eq_rb.arch(1,1,m=1000,h) rb

'extract the standardized residual series from the GARCH fit


eq_rsp.makeresids(s) z1
eq_rb.makeresids(s) z2

'extract garch series from univariate fit


eq_rsp.makegarch() garch1
eq_rb.makegarch() garch2

'Caculate sample variance of series z1, z2 and covariance of z1and z2 and correlation between z1 and z2
scalar var_z1=@var(z1)
scalar var_z2=@var(z2)
scalar cov_z1z2=@cov(z1,z2)
scalar corr12=@cor(z1,z2)

14
'defining the starting values for the var(z1) var(z2) and covariance (z1,z2)
series var_z1t=var_z1
series var_z2t=var_z2
series cov_z1tz2t=cov_z1z2

'declare the coefficient starting values


coef(2) T
T(1)=0.2
T(2)=0.7

' ...........................................................
' LOG LIKELIHOOD for correlation part
' set up the likelihood
' 1) open a new blank likelihood object and name it 'dcc'
' 2) specify the log likelihood model by append
' ...........................................................

logl dcc
dcc.append @logl logl

'specify elements of the variance-covariance matrix of standardized residuals: var_z1t, var_z2t,


cov_z1tz2t
dcc.append var_z1t=@nan(1-T(1)-T(2)+T(1)*(z1(-1)^2)+T(2)*var_z1t(-1),1)
dcc.append var_z2t=@nan(1-T(1)-T(2)+T(1)*(z2(-1)^2)+T(2)*var_z2t(-1),1)
dcc.append cov_z1tz2t=@nan((1-T(1)-T(2))*corr12+T(1)*z1(-1)*z2(-1)+T(2)*cov_z1tz2t(-1),1)

'specify rho12
dcc.append rho12=cov_z1tz2t/@sqrt(@abs(var_z1t*var_z2t))

'defining the determinant of correlation matrix


dcc.append detrRt=(1-(rho12^2))

'define the log likelihood function


dcc.append logl=(-1/2)*(log(detrRt)+(z1^2+z2^2-2*rho12*z1*z2)/detrRt - z1^2 - z2^2)

'estimate the model


smpl s1
dcc.ml(showopts, m=500, c=1e-5)

'display output and graphs


show dcc.output
graph corr.line rho12

show corr

15
2. Codes for Vacisek’s Model

'************************************************************************************
****************************************
'Estimate the Vasicek's model : An application of a Factor Copula Model to Loan Portfolio
'Using the Gaussian Copulas
‘Hung Do
'************************************************************************************
****************************************

'change path to program path


%path=@runpath
cd %path

'Import the XLS data this code is generalized so that you can import file with more than 1 sheet
%names = @tablenames("DefaultRates_EV.xls")
%n = @word(%names,1)
wfopen "DefaultRates_EV.xls" range=%n
for !i=2 to @wcount(%names)
%n = @word(%names, !i)
import "DefaultRates_EV.xls" range=%n
next

' set all sample


smpl @all

' declare coef vectors to use for estimation including rho and PD
coef(2) param
param(1)=0.2 'starting value for correlation (Rho)
param(2)=0.01 'starting value for unconditional probability of default (PD)

'set up the log likelihood as formula shown in slide


logl vasicek
vasicek.append @logl logl
vasicek.append p1=@sqrt((1-param(1))/param(1))
vasicek.append p2=@qnorm(dr)
vasicek.append p3= (@sqrt(1-param(1))*@qnorm(dr) - @qnorm(param(2)))/@sqrt(param(1))
vasicek.append logl = log(p1*@exp(0.5*(p2^2-p3^2)))

'Estimate and display results


vasicek.ml(showopts, m=1000, c=1e-5)
show vasicek.output

16

You might also like