Page 1 of 2

Dynamic conditional correlations

Posted: Sun Sep 08, 2013 3:34 pm
by barryoli
I posted this on the econometric section but think it missed the mark.

Please excuse my ignorance in econometrics and eviews.

I'm trying to create a time varying correlation series from two series (bond and stock returns).
For each of the bond and stock returns I've estimated a GARCH(1,1) model and from each created a GARCH variance series.

The correlation I've then created is the sample covariance(numerator)/(product of the square root of each estimated GARCH variance- denominator)
The sample covariance is estimated from the covariance of the returns series.

This series of "correlations" assumes the sample covariance (numerator) remains constant.
Since its not directly related to the GARCH variances (denominator) it isn't bounded -1+1 like a normal correlation.
(In fact I'm not sure what it is).

What I want to do is to assume that the sample covariance is time varying (like the GARCH variance series).

I believe this is the dynamic conditional correlation...but I'm stuck in knowing how to do it in eviews (or anything else for that matter).

Any help gratefully appreciated.
I'm using Eviews8


Another question relates to a moving correlation using @movcorr(x,y,n). Where n is the window. This creates a correlation where the observations are overlapping ie 1-20, 2-21, 3-22 etc.
What is the most efficient way of calculating a correlation between series that are not overlapping. ie 1-20, 21-40, 41-60 etc. rather than 1-20, 2-21, 3-22 etc.
I'm only going to get a correlation on obs 20, 40,60 etc but they aren't overlapping like the @movcorr.

Any help doubly appreciated.

Cheer
Barry

Re: Dynamic conditional correlations

Posted: Mon Sep 09, 2013 2:09 am
by trubador
Please search the forum for examples of dynamic conditional correlation estimation in EViews.
As for the second question, the information is there so all you need to do is pull it out:

Code: Select all

'Determine the sample range %pagesmpl = @pagesmpl %beg = @word(%pagesmpl,1) !beg = @dtoo(%beg) 'Window size for moving correlation !window = 20 'Generate the moving correlation first series movcor = @movcor(series1,series2,!window) 'Retain only the correlations of interest. series cor = @recode(@mod(@obsnum-!beg+1,!window)=0,movcor,NA) 'Get rid of NAs and store the data as a vector stom(cor,corvec)

Re: Dynamic conditional correlations

Posted: Mon Sep 09, 2013 7:09 pm
by barryoli
Thanks trubador,
I expect this is going to take some time...I'm not much of an eviews user nor a programmer. I've looked for dynamic correlations and couldn't find anything that helped but I'll look further.

In the meantime I'm trying to sort out the correlation stuff.
I'm stuck on the sample range. My sample is unstructured ie although daily I've not used dates as they've been manipulated a bit (pub hols removed etc).
So I'm stuck on the !beg=@tdoo(%beg) line...how to I specify its the begging of unstructured data...I tried !beg=1 but then it crashed later...

Sorry if this is basic...your help is much appreciated...
Cheers
Barry

PS: I've gone off and searched for DCC and found some material and code by Hvtcapollo but I was lost.

Re: Dynamic conditional correlations

Posted: Tue Sep 10, 2013 1:52 am
by trubador
If you post the EViews workfile or the Excel file, I'll look at it.

Re: Dynamic conditional correlations

Posted: Tue Sep 10, 2013 1:41 pm
by barryoli
Thank you very much.

The two series which I'm trying to calculator Dynamic Conditional Correlations (as well as the rolling correlations which I can do and the non-overlapping which I'm also stuck on) is
ASX200RETURNS
BONDRETS

Cheers
Barry

Re: Dynamic conditional correlations

Posted: Thu Sep 12, 2013 12:13 am
by trubador
You can either contract the page or create a proper copy to make the code work:

Code: Select all

pagecontract if asx200returns<>0 'or pagecopy(page=mycopy, smpl="1 5057 if asx200returns<>0")

Re: Dynamic conditional correlations

Posted: Thu Sep 12, 2013 12:38 pm
by barryoli
Thanks but that didn't work.
I copied the code to create a new page and a new page with 4999 obs was created.
Then I copied the code you wrote previously and it said 'cor is not defined'. I tried doing parts of the code and didn't have any success either.

God help me when I get to try to do the DCC!

:-(
This what the code is (note I changed series1 to asx200returns and series2 to bondrets).

pagecontract if asx200returns<>0
'Determine the sample range
%pagesmpl = @pagesmpl
%beg = @word(%pagesmpl,1)
!beg = @dtoo(%beg)

'Window size for moving correlation
!window = 20

'Generate the moving correlation first
series movcor = @movcor(asx200returns,bondrets,!window)

'Retain only the correlations of interest.
series cor = @recode(@mod(@obsnum-!beg+1,!window)=0,movcor,NA)

'Get rid of NAs and store the data as a vector
stom(cor,corvec)

Re: Dynamic conditional correlations

Posted: Thu Sep 12, 2013 4:13 pm
by barryoli
If I just do this bit it tells me I've an illegal date. :-(


pagecontract if asx200returns<>0
%pagesmpl = @pagesmpl
%beg = @word(%pagesmpl,1)
!beg = @dtoo(%beg)

Re: Dynamic conditional correlations

Posted: Fri Sep 13, 2013 12:34 am
by trubador
I ran the code, and it worked just fine. What is the build date of your copy of EViews? (-->Help/About EViews)

Re: Dynamic conditional correlations

Posted: Fri Sep 13, 2013 2:07 pm
by barryoli
Bugger...I've just realised that the version I'm using on my laptop is Eviews7 while at work its Eviews8, I'm away from work at the moment so I'll have to wait until I get back to work (Monday) before I run it on Eviews8 to see if that makes the difference.

I don't see why this should make the difference but not much I can do until I check it at work...I'm not so confident though...

I tried again on Eviews7 (copied all the coding into a program window and pressed return) and it returns the error: Cor is undefined.
Then I created a new page first the first line- that worked ok and contraction dropped 58 observations.

Then I copied the remaining code into the program window and it gave me the message: Cor is undefined.

I deleted all the code and tried to run this:
%pagesmpl = @pagesmpl
%beg = @word(%pagesmpl,1)
!beg = @dtoo(%beg)

It returned: Illegal date
I then ran this line:
%pagesmpl = @pagesmpl

(%pagesmpl successfully completed)

so that worked

I added this:
%beg = @word(%pagesmpl,1)

(%beg successfully completed)

so that worked

as soon as I addded
!beg = @dtoo(%beg)

It said illegal date. Anyway not much I can do until I check it on Eviews8 at work on Monday.


Cheers
Barry.

Re: Dynamic conditional correlations

Posted: Sun Sep 15, 2013 7:49 pm
by barryoli
Well, Version 8 didn't help solve my problem.
Attached are various screen shots and what i did.
End result is Cor not defined.

Any help again gratefully appreciated.

Cheers
Barry.

Re: Dynamic conditional correlations

Posted: Mon Sep 16, 2013 12:20 am
by trubador
You are trying to run a program from command line. Go to File/New/Program, which will open a program window. You should copy and paste the code into the window and then hit run.

Re: Dynamic conditional correlations

Posted: Mon Sep 16, 2013 12:30 am
by barryoli
Gives you some idea how igorant I am of how to use eviews...thought I could run such a thing from the program line...sorry to take up your valuable time...
and thanks....

I shall go away and play with this for a while.

No doubt I will have to come back for some help on DCC...if you can give me some direction here that would also be most gratefully appreciated.

Regards and thanks again.
Barry

Re: Dynamic conditional correlations

Posted: Mon Sep 16, 2013 1:28 am
by barryoli
Amazing how easy life can be with a small adjustment!
All good with the non-overlapping correlations...did it across 20, 30, 50 and 100 day non-overlapping windows..crosschecked a few with excel....too easy.

now I'm ready to move onto DCC...any help again much appreciated.

Regards
Barry

Re: Dynamic conditional correlations

Posted: Mon Sep 16, 2013 4:58 pm
by barryoli
OK. I've amended the code so it does 20,30,50,100 windows, all in one go!

I'm like a kid with a new toy...

Don't laugh! I haven't done any programming for 30years...well, any that has worked.
The only thing i've found a bit unnerving is that you can delete the eviews program without a prompt asking you to save it...but I can live with that by writing the code in Word and pasting it...


Off to search for dynamic conditional correlations...

I'll be back...:-)