Dynamic conditional correlations

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

barryoli
Posts: 18
Joined: Sun Sep 01, 2013 10:52 pm

Dynamic conditional correlations

Postby barryoli » Sun Sep 08, 2013 3:34 pm

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

trubador
Did you use forum search?
Posts: 1520
Joined: Thu Nov 20, 2008 12:04 pm

Re: Dynamic conditional correlations

Postby trubador » Mon Sep 09, 2013 2:09 am

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)

barryoli
Posts: 18
Joined: Sun Sep 01, 2013 10:52 pm

Re: Dynamic conditional correlations

Postby barryoli » Mon Sep 09, 2013 7:09 pm

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.

trubador
Did you use forum search?
Posts: 1520
Joined: Thu Nov 20, 2008 12:04 pm

Re: Dynamic conditional correlations

Postby trubador » Tue Sep 10, 2013 1:52 am

If you post the EViews workfile or the Excel file, I'll look at it.

barryoli
Posts: 18
Joined: Sun Sep 01, 2013 10:52 pm

Re: Dynamic conditional correlations

Postby barryoli » Tue Sep 10, 2013 1:41 pm

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
Attachments
Trubador.wf1
(333.69 KiB) Downloaded 410 times

trubador
Did you use forum search?
Posts: 1520
Joined: Thu Nov 20, 2008 12:04 pm

Re: Dynamic conditional correlations

Postby trubador » Thu Sep 12, 2013 12:13 am

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")

barryoli
Posts: 18
Joined: Sun Sep 01, 2013 10:52 pm

Re: Dynamic conditional correlations

Postby barryoli » Thu Sep 12, 2013 12:38 pm

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)

barryoli
Posts: 18
Joined: Sun Sep 01, 2013 10:52 pm

Re: Dynamic conditional correlations

Postby barryoli » Thu Sep 12, 2013 4:13 pm

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)

trubador
Did you use forum search?
Posts: 1520
Joined: Thu Nov 20, 2008 12:04 pm

Re: Dynamic conditional correlations

Postby trubador » Fri Sep 13, 2013 12:34 am

I ran the code, and it worked just fine. What is the build date of your copy of EViews? (-->Help/About EViews)

barryoli
Posts: 18
Joined: Sun Sep 01, 2013 10:52 pm

Re: Dynamic conditional correlations

Postby barryoli » Fri Sep 13, 2013 2:07 pm

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.

barryoli
Posts: 18
Joined: Sun Sep 01, 2013 10:52 pm

Re: Dynamic conditional correlations

Postby barryoli » Sun Sep 15, 2013 7:49 pm

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.
Attachments
Eviews errors.docx
(764.45 KiB) Downloaded 418 times

trubador
Did you use forum search?
Posts: 1520
Joined: Thu Nov 20, 2008 12:04 pm

Re: Dynamic conditional correlations

Postby trubador » Mon Sep 16, 2013 12:20 am

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.

barryoli
Posts: 18
Joined: Sun Sep 01, 2013 10:52 pm

Re: Dynamic conditional correlations

Postby barryoli » Mon Sep 16, 2013 12:30 am

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

barryoli
Posts: 18
Joined: Sun Sep 01, 2013 10:52 pm

Re: Dynamic conditional correlations

Postby barryoli » Mon Sep 16, 2013 1:28 am

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

barryoli
Posts: 18
Joined: Sun Sep 01, 2013 10:52 pm

Re: Dynamic conditional correlations

Postby barryoli » Mon Sep 16, 2013 4:58 pm

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...:-)


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest