Diebold-Yilmaz EJ 2009

Use this forum for posting example programs or short bits of sample code.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Diebold-Yilmaz EJ 2009

Unread post by TomDoan »

Sure, though you might find it easier to pull the full table into a spreadsheet and do the calculation there.
zy761
Posts: 13
Joined: Mon Mar 19, 2012 1:01 am

Re: Diebold-Yilmaz EJ 2009

Unread post by zy761 »

TomDoan wrote:Sure, though you might find it easier to pull the full table into a spreadsheet and do the calculation there.
If I understand correctly, the volatility spillover index can be simply the sum of bilateral index:

compute tovol1(end)=100.0*(gfevdx(x,a)+gfevdx(y,a)+gfevdx(z,a)+gfevdx(x,b)+gfevdx(y,b)+gfevdx(z,b)+gfevdx(x,c)+gfevdx(y,c)+gfevdx(z,c))

Am I right?

Regards,
Jasmine
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Diebold-Yilmaz EJ 2009

Unread post by TomDoan »

With x,y,z as the target, and a,b,c as the sources, that's correct.
ronny200692
Posts: 3
Joined: Sun Apr 05, 2015 11:53 am

Re: Diebold-Yilmaz EJ 2009

Unread post by ronny200692 »

Hi Tom,
Recently I was trying to replicate Diebold-Yilmaz EJ 2009' s paper with my own dataset. The same as their paper, I need to calculate the spillover index. My data includes 47 countries span 2007 through 2012 in a weekly form. I've attached the data and code, can you please check with it to see what's wrong with my code. I'm kind of stuck here. Thanks in advance.

Ronny
Attachments
esti.xls
data
(284.5 KiB) Downloaded 934 times
code.RPF
code
(5.56 KiB) Downloaded 1195 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Diebold-Yilmaz EJ 2009

Unread post by TomDoan »

I'm not sure about the program, but you have a major problem with your data---four of your series have no data. Several others have zeroes which don't make any sense for the model. FYI, two digit year numbers like "07:01:05" are interpreted as 1907, not 2007 (so legacy programs will work properly). Anything written new should use four digit years.

Code: Select all

Series             Obs       Mean        Std Error      Minimum       Maximum
VDJIA                312  18.805720599  16.816413812   1.245033687 163.517480770
VFTSE                312  24.045548581  15.695044718   2.333598096  89.023123680
VFRA                 312  16.144924712  11.929524614   1.372978378  77.649037348
VGER                 312  31.651825859  22.385737142   5.019213533 224.937615018
VHKG                 312  17.501344391  11.881006615   0.000000000  71.851877079
VJPN                 312  16.956345612  12.369247530   0.977965432  72.345815428
VAUS                 312  13.183877293   9.368036685   1.102390019  60.414698695
VIDN                 312  12.050939011   8.395759190   1.657101711  77.957817683
VKOR                 312  19.639843303  13.111287847   0.000000000  83.385897064
VMYS                 312  15.275406073  12.174148853   1.377499545  78.498016350
VPHL                 312   5.536460407  15.034851139   0.000000000  92.432280531
VSGP                 312  17.485222483  12.537396488   0.000000000  66.468932933
VTAI                 312  16.854627445  13.381223711   1.356296130 135.476397008
VTHA                 312  22.539940588  21.990409814   1.472241780 180.220154357
VARG                 312  13.913621730   9.905503949   1.622676937  79.273626989
VBRA                 312   5.134383231  17.079478336   0.000000000 183.598019942
VCHL                 312  17.317173300  13.716375436   0.000000000  82.163506397
VMEX                 312  22.027073677  15.284161896   2.152959869 110.224982646
VTUR                 312  19.152543265  11.801389040   2.406105672  73.075583443
WGER                 312  19.922955651  14.365529052   0.868032532 114.548977447
WVRE                 312  21.025752897  19.003006683   0.000000000 166.522949656
WVHU                 312   0.000000000   0.000000000   0.000000000   0.000000000
WIRE                 312   8.675417429  16.570860729   0.000000000  85.511985218
VWTA                 312  23.742337016  17.667546253   1.978095895 125.857717148
WLUX                 312  22.035149391  35.408063527   0.000000000 310.572875875
WNET                 312  18.830784554  12.067356603   2.445203593  80.730055918
WNOR                 312  27.421267692  24.126051104   1.125789062 213.211865714
WPOL                 312  26.097834280  17.259470914   4.207864054 136.338282670
WPOR                 312   0.000000000   0.000000000   0.000000000   0.000000000
WRUS                 312   6.647674386  13.823942910   0.000000000  78.993488728
WSPA                 312  25.869561488  23.837147792   1.716495991 189.436935580
WWE                  312  21.046965398  14.240431666   1.018975765  91.291724002
WSWI                 312  10.697961125   7.278957686   0.735990763  57.015128023
WUNIK                312  19.869060062  14.376287151   1.453609302  91.535748841
WARG                 312  11.218805437  16.751928988   0.000000000 101.066084210
WBRA                 312  17.354084858  16.742478046   0.000000000 130.079984576
WCHI                 312  19.385110159  12.710107254   1.861770072  89.913239149
WCLO                 312   0.000000000   0.000000000   0.000000000   0.000000000
WME                  312   4.203042882  13.070291418   0.000000000 174.398834673
WPRU                 312   0.000000000   0.000000000   0.000000000   0.000000000
WEGY                 312  19.214919236  18.353594886   0.000000000 159.967731582
WISA                 312  17.246828435  13.432962851   1.281413465 135.793415472
WMOR                 312   0.432486015   2.150149497   0.000000000  16.353517590
WSOU                 312  14.985795219  10.367191236   2.799430607  92.929789513
WTUR                 312  24.001604228  17.452260332   2.868645573 131.222714094
WCAN                 312  13.629008598  11.791558418   1.032773753  95.149534309
WSU                  312  20.424126387  18.344531427   1.766047317 110.577481434
ronny200692
Posts: 3
Joined: Sun Apr 05, 2015 11:53 am

Re: Diebold-Yilmaz EJ 2009

Unread post by ronny200692 »

Hi Tom,
Thanks for your instant reply. Can you check with my data and code again. See attached please. The new problem is that Rats tells me "Empty Range on Series SPILLVOLS". I am kind of stuck here and can't find the problem. Another point is that I find that the value of spillover in the "view\series window" is no data. I don't know what happens here. And I think this is why my result shows a high(>95%) spillover index. The own variance share on the diagonal is so small, which does not make sense from the view of previous literature.

Ronny
Attachments
positive.xls
data
(56.5 KiB) Downloaded 938 times
1.RPF
code
(5.24 KiB) Downloaded 1229 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Diebold-Yilmaz EJ 2009

Unread post by TomDoan »

You have 34 series, 2 lag VAR on 53 data points. That won't work. You really shouldn't have the NOPRINT option on the ESTIMATE until you have this working. I understand that you're trying to extend this to some new countries, but if there isn't the right data, you won't be able to make it work.
ronny200692
Posts: 3
Joined: Sun Apr 05, 2015 11:53 am

Re: Diebold-Yilmaz EJ 2009

Unread post by ronny200692 »

TomDoan wrote:You have 34 series, 2 lag VAR on 53 data points. That won't work. You really shouldn't have the NOPRINT option on the ESTIMATE until you have this working. I understand that you're trying to extend this to some new countries, but if there isn't the right data, you won't be able to make it work.
Dear Tom,
Thanks for the quick reply. What do you mean by right data? I have 34 series in 6 years, the data I attached was just one year. "You really shouldn't have the NOPRINT option on the ESTIMATE until you have this working" means I should not include NOPRINT option in the equation?

Ronny
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Diebold-Yilmaz EJ 2009

Unread post by TomDoan »

If you have six years, don't try to do the analysis with just one! There's not enough data in one year of data to support the analysis. The NOPRINT option suppresses the message that the regression has no degrees of freedom.

With 34 countries and two lags (plus the constant) you need at least 69 data points just to estimate the model---and with a minimal amount of data (probably under three years), the results will be suspect because of the high forced collinearity of the regressors in such an overparameterized model.
econo
Posts: 32
Joined: Fri Sep 05, 2014 9:16 am

Re: Diebold-Yilmaz EJ 2009

Unread post by econo »

Dear Tom;

1. How can I extend the number of variables? here I have 52 stocks, How can I extend it to 500 stocks? what is the limit?
2. How can I export "Table for Global Market Volatility" into excel format?

FYI: I am using RATS 8.0
Best Regards

Code: Select all

open data VolatilityR.xls
data(format=xls,org=columns) /MMM	MO	MON	MRK	MS	MSFT	NKE	NOV	NSC 	ORCL	OXY	PEP	AAPL 	ABT	ACN	AIG	 ALL	AMGN	AMZN	APA	APC	AXP	BA	BAC	BAX	BIIB	BK	BMY	C	CAT	CL	CMCSA 	COF	COP	COST	CSCO	CVS	CVX	DD	DIS	DOW	DVN	EBAY 	EMC	EMR	EXC	F	FCX	FDX	FOXA	GD	GE	GILD	GS	HAL

dec vect[int] vols
enter(varying) vols
#MMM	MO	MON	MRK	MS	MSFT	NKE	NOV	NSC 	ORCL	OXY	PEP	AAPL 	ABT	ACN	AIG	 ALL	AMGN	AMZN	APA	APC	AXP	BA	BAC	BAX	BIIB	BK	BMY	C	CAT	CL	CMCSA 	COF	COP	COST	CSCO	CVS	CVX	DD	DIS	DOW	DVN	EBAY 	EMC	EMR	EXC	F	FCX	FDX	FOXA	GD	GE	GILD	GS	HAL	HD

system(model=volvar)
variables MMM	MO	MON	MRK	MS	MSFT	NKE	NOV	NSC 	ORCL	OXY	PEP	AAPL 	ABT	ACN	AIG	 ALL	AMGN	AMZN	APA	APC	AXP	BA	BAC	BAX	BIIB	BK	BMY	C	CAT	CL	CMCSA 	COF	COP	COST	CSCO	CVS	CVX	DD	DIS	DOW	DVN	EBAY 	EMC	EMR	EXC	F	FCX	FDX	FOXA	GD	GE	GILD	GS	HAL	HD
compute usegirf=1

lags 1 2
det constant
end(system)

estimate(noprint)
*
* Save the full estimation range for later use
*
compute rstart=%regstart(),rend=%regend()
*
* Analyze the 10 step responses
*
compute nsteps=10

*********************************************************************
*
* Produce the appropriate "factor" matrix from %sigma
*
function FactorMatrix
type rect FactorMatrix
if usegirf
   compute FactorMatrix=%sigma*inv(%diag(%sqrt(%xdiag(%sigma))))
else
   compute FactorMatrix=%decomp(%sigma)
end

compute gfactor=FactorMatrix()
errors(model=volvar,steps=nsteps,factor=gfactor,stderrs=gstderrs,noprint,results=gfevd)
compute gfevdx=%xt(gfevd,nsteps)
*
* These are for computing the contributions from others, to others and
* to others including own for each variable.
*
dec vect tovar(%nvar) fromvar(%nvar) tototal(%nvar)
ewise fromvar(i)=%sum(%xrow(gfevdx,i))-gfevdx(i,i)
ewise tovar(i)=%sum(%xcol(gfevdx,i))-gfevdx(i,i)
ewise tototal(i)=tovar(i)+1-fromvar(i)
compute spillover=100.0*%sum(tovar)/%nvar

*
report(action=define,title="Table for Global Market Volatility")
report(atrow=2,atcol=2) 100.0*gfevdx
report(atrow=%nvar+2,atcol=1,fillby=rows) "Contribution to others" 100.0*tovar
report(atrow=%nvar+3,atcol=1,fillby=rows) "Contribution including own" 100.0*tototal
report(atcol=%nvar+2,atrow=1) "From Others"
report(atcol=%nvar+2,atrow=2,fillby=cols) 100.0*fromvar
report(atrow=%nvar+2,atcol=%nvar+2,fillby=cols) 100.0*%sum(tovar)
report(atrow=%nvar+3,atcol=%nvar+2,align=right) %strval(spillover,"##.#")+"%"
report(atrow=2,atcol=2,torow=%nvar+1,tocol=%nvar+1,action=format,picture="*.#")
report(atrow=%nvar+2,torow=%nvar+3,atcol=1,tocol=%nvar+2,action=format,picture="###")
report(atcol=%nvar+2,atrow=2,torow=%nvar+2,action=format,picture="###")
report(action=show)

TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Diebold-Yilmaz EJ 2009

Unread post by TomDoan »

omid_ie wrote:Dear Tom;
1. How can I extend the number of variables? here I have 52 stocks, How can I extend it to 500 stocks? what is the limit?
The limit depends upon how much data you have. You would need a lot of observations to do that. With a one lag VAR, you would need about 1000 just to get a full rank matrix, but the results from anything less than probably 2500 would be so poorly defined that there would be no point.
omid_ie wrote: 2. How can I export "Table for Global Market Volatility" into excel format?
REPORT(ACTION=SHOW,...) has options to export the table:

UNIT=COPY/[OUTPUT]/other unit
FORMAT=CDF/DBF/DIF/HTML/PRN/TEX/WKS/XLS/XLSX/XML [default is formatted text]
You can use the UNIT option to redirect the report output to another unit (usually an external file previously opened with an OPEN instruction). If you use UNIT without using FORMAT, RATS will generate a text file, with the output formatted just as it is when displayed in the output window. If you prefer, you can use the FORMAT option to select one of the other file formats, as shown above (FORMAT only applies when used in conjunction with UNIT).
econo
Posts: 32
Joined: Fri Sep 05, 2014 9:16 am

Re: Diebold-Yilmaz EJ 2009

Unread post by econo »

As you can see I have 2500 obs.
this is like 92 stocks but I dont know to define in RATS 8.0 to input in the model in line
data(format=xls,org=columns) /MMM MO MON ...

thanx for second question
Attachments
VolatilityR.xls
(2.76 MiB) Downloaded 932 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Diebold-Yilmaz EJ 2009

Unread post by TomDoan »

Won't the data wizard take care of that?
econo
Posts: 32
Joined: Fri Sep 05, 2014 9:16 am

Re: Diebold-Yilmaz EJ 2009

Unread post by econo »

Even with the wizard, the limit of columns to import is 60.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Diebold-Yilmaz EJ 2009

Unread post by TomDoan »

Because the data set has only 60 columns.
Post Reply