Diebold-Yilmaz, IJF 2012
-
izymougoue2006
- Posts: 29
- Joined: Tue Apr 24, 2012 8:16 pm
Re: Diebold-Yilmaz, IJF 2012
Hello, can I send you my database.
We made some modifications which allowed us to have the volatility spillover table.
I remind you that I am studying the financial contagion of African stock markets during the covid-19 pandemic. I work with 16 markets, that is to say 16 variables. so I ask with 16 variables what modification should I do to generate the graphs.
We made some modifications which allowed us to have the volatility spillover table.
I remind you that I am studying the financial contagion of African stock markets during the covid-19 pandemic. I work with 16 markets, that is to say 16 variables. so I ask with 16 variables what modification should I do to generate the graphs.
Re: Diebold-Yilmaz, IJF 2012
Given the number of series you have, you probably need to look more to the calculations that are done in the 2009 paper (which is more similar in size) than the 2012 paper.TomDoan wrote:This is the replication file for Diebold and Yilmaz(2012), "Better to give than to receive: Predictive directional measurement of volatility spillovers," International Journal of Forecasting, vol. 28, no 1, 57-66. This is a companion piece to Diebold and Yilmaz(2009). The 2012 article uses "generalized" IRF's rather than the Cholesky IRF's used in the 2009 article, though the ability to use GIRF's has been included in the DY 2009 code for several years. The 2012 uses a much smaller set of series which makes several other types of measures feasible, such as rolling net pairwise spillovers. (Those could be computed in the 2009 data set, but there would be 171 pairs for that rather than 6 for the small set.)
-
izymougoue2006
- Posts: 29
- Joined: Tue Apr 24, 2012 8:16 pm
Re: Diebold-Yilmaz, IJF 2012
Good morning
Thank you for the explanations
After reviewing my database, I was able to get the graphics. Now my problem is the dates that do not appear in the x-axis but rather the totals of days that appear.
Thank you for the explanations
After reviewing my database, I was able to get the graphics. Now my problem is the dates that do not appear in the x-axis but rather the totals of days that appear.
Re: Diebold-Yilmaz, IJF 2012
You would have to post the data and program so I could see why you aren't getting the dates.
-
izymougoue2006
- Posts: 29
- Joined: Tue Apr 24, 2012 8:16 pm
Re: Diebold-Yilmaz, IJF 2012
hello Tom, you are doing well I hope
Please find attached below the codes. Please find attached to this text, my database
Please find attached below the codes. Please find attached to this text, my database
Code: Select all
open data C:\Users\PC\Desktop\COVIDSS.xlsx
data(format=xlsx,org=col) / TUN ZAN MAUR NIG MAR ZAM AFS EGY NAM BOS BRVM KEY FRA ALL USA CHINE
************************************************************************
compute usegirf=1
************************************************************************
*****************************return spillover***************************
dec vect[int] vols
enter(varying) vols
# TUN ZAN MAUR NIG MAR ZAM AFS EGY NAM BOS BRVM KEY FRA ALL USA CHINE
************************************************************************
************************************************************************
dec vect[string] longlabels(%size(vols))
enter longlabels
# "TUN" "ZAN" "MAUR" "NIG" "MAR" "ZAM" "AFS" "EGY" "NAM" "BOS" "BRVM" $
"KEY" "FRA" "ALL" "USA" "CHINE"
dec vect[string] shortlabels(%size(vols))
enter shortlabels
# "TUN" "ZAN" "MAUR" "NIG" "MAR" "ZAM" "AFS" "EGY" "NAM" "BOS" "BRVM" $
"KEY" "FRA" "ALL" "USA" "CHINE"
*
* Setup and estimate two lag VAR
*
system(model=volvar)
variables vols
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 4. Spillover Table for Global Market Volatility")
report(atrow=1,atcol=2,align=center,fillby=rows) shortlabels
report(atrow=2,atcol=1,fillby=cols) shortlabels
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)
*
* Rolling sample analysis
*
compute nspan=200
*
dec series totalspill
dec symm pairvar(%nvar,%nvar) pair(%nvar,%nvar)
dec vect[series] fromspill(%nvar) tospill(%nvar) netspill(%nvar) own(%nvar)
dec symm[series] pairspill(%nvar,%nvar) pairpercent(%nvar,%nvar)
clear(zeros) fromspill topspill totalspill netspill pairspill paircent own
*
do end=rstart+nspan-1,rend
estimate(noprint) end-nspan+1 end
*
* Skip any data points where the rolling VAR has an explosive root.
*
eigen(cvalues=cv) %modelcompanion(volvar)
if %cabs(cv(1))>=1.0 {
compute totalspill(end)=%na
next
}
compute gfactor=FactorMatrix()
errors(model=volvar,steps=nsteps,factor=gfactor,noprint,results=gfevd)
compute gfevdx=%xt(gfevd,nsteps)
ewise tovar(i)=%sum(%xcol(gfevdx,i))-gfevdx(i,i)
ewise fromvar(i)=%sum(%xrow(gfevdx,i))-gfevdx(i,i)
ewise pairvar(i,j)=gfevdx(i,j)-gfevdx(j,i)
ewise pair(i,j)=gfevdx(i,j)
compute totalspill(end)=100.0*%sum(tovar)/%nvar
compute %pt(fromspill,end,100.0*fromvar)
compute %pt(tospill,end,100.0*tovar)
compute %pt(netspill,end,100.0*(tovar-fromvar))
compute %pt(own,end,100.0*(1-fromvar))
compute %pt(pairspill,end,100.0*pairvar)
compute %pt(pairpercent,end,100.0*pair)
end do end
*
*
graph(footer="Spillover plot. Volatility. 200 week window. 10 step horizon")
# totalspill rstart+nspan-1 rend
*
* With a 140 week span instead, using both the 2 week and 10 week
* forecast horizons.
*
compute nspan=140
set spillvols rstart+nspan-1 rend = 0.0
set spillvol2 rstart+nspan-1 rend = 0.0
do end=rstart+nspan-1,rend
estimate(noprint) end-nspan+1 end
*
* Skip any data points where the rolling VAR has an explosive root.
*
eigen(cvalues=cv) %modelcompanion(volvar)
if %cabs(cv(1))>=1.0 {
compute spillvols(end)=%na
compute spillvol2(end)=%na
next
}
compute gfactor=FactorMatrix()
errors(model=volvar,steps=nsteps,factor=gfactor,stderrs=gstderrs,noprint,results=gfevd)
*
* Compute for 10 steps
*
compute gfevdx=%xt(gfevd,10)
ewise tovar(i)=%sum(%xcol(gfevdx,i))-gfevdx(i,i)
compute spillvols(end)=100.0*%sum(tovar)/%nvar
*
* Compute for 2 steps
*
compute gfevdx=%xt(gfevd,2)
ewise tovar(i)=%sum(%xcol(gfevdx,i))-gfevdx(i,i)
compute spillvol2(end)=100.0*%sum(tovar)/%nvar
end do end
spgraph(vfields=2, Header="Figure 1. Spillover index plot. Currency volatilities" ,$
footer="140 Week Rolling Windows")
graph(header="(a) 10 Week forecast horizon")
# spillvols rstart+nspan-1 rend
graph(header="(b) 2 Week forecast horizon")
# spillvol2 rstart+nspan-1 rend
spgraph(done)
***************************************************************************
***************************Own-variable markets****************************
spgraph(vfields=4,hfields=4,$
header="Figure 2. Own-variable market effects. volatility ")
do i=1,%nvar
graph(header=longlabels(i), style=bar)
# own(i)
end do i
spgraph(done)
***************************************************************************
*********************Directional spillovers********************************
spgraph(vfields=4,hfields=4,$
header="Figure 3. Directional volatility Spillovers", footer="Black line for inward and blue line for outward")
do i=1,%nvar
graph(header=longlabels(i)) 2
# fromspill(i)
# tospill(i)
end do i
spgraph(done)
***************************************************************************
**************************Net spillovers***********************************
spgraph(vfields=4,hfields=4, $
header="Figure 4. Net Volatility Spillovers")
do i=1,%nvar
graph(header=longlabels(i), style=bar)
# netspill(i)
end do i
spgraph(done)
************************************************************************
************************************************************************
spgraph(vfields=4,hfields=4,$
header="Figure 5. Net Volatility Spillovers Among Currencies")
do i=1,%nvar
graph(header=longlabels(i),style=bar)
# netspill(i) rstart+nspan-1 rend
end do i
spgraph(done)
*- Attachments
-
- COVIDSS.xlsx
- Database the study of the connectivity of African stock markets with their main trading and financial partners
- (200.67 KiB) Downloaded 417 times
Re: Diebold-Yilmaz, IJF 2012
The data file has a weird mix of numerically coded vs straight text dates. (We've seen that before, and I have no idea why anyone would ever do that). At any rate, the following will give you, so far as I can tell, the correct dates:
cal(d) 2020:01:02
data(format=xlsx,org=col,left=2) / TUN ZAN MAUR NIG MAR ZAM AFS EGY NAM BOS BRVM KEY FRA ALL USA CHINE
Note, however, that your final data point seems to be just 0's across the board, which I assume means that they were no longer keeping track, so you probably want to ignore that. (I would probably just delete it off the data set).
What exactly are your data? I assume something Covid related, but I can't really tell what (most of the series start high in 2020). The estimated VAR's tend to be unstable, which is why you end up with so few data points in the graphs for the rolling window analysis.
cal(d) 2020:01:02
data(format=xlsx,org=col,left=2) / TUN ZAN MAUR NIG MAR ZAM AFS EGY NAM BOS BRVM KEY FRA ALL USA CHINE
Note, however, that your final data point seems to be just 0's across the board, which I assume means that they were no longer keeping track, so you probably want to ignore that. (I would probably just delete it off the data set).
What exactly are your data? I assume something Covid related, but I can't really tell what (most of the series start high in 2020). The estimated VAR's tend to be unstable, which is why you end up with so few data points in the graphs for the rolling window analysis.
-
izymougoue2006
- Posts: 29
- Joined: Tue Apr 24, 2012 8:16 pm
Re: Diebold-Yilmaz, IJF 2012
hello Tom
Thanks for the relevant feedback and comments.
yes obviously my data is originally for stock prices during the covid-19 period. the data starts high in 2020 which can be explained by the stock market panic at the start of the pandemic.
I recall that the objective of this study is to see the transmission of volatility within the African stock markets and also some world stock markets.
Thanks for the relevant feedback and comments.
yes obviously my data is originally for stock prices during the covid-19 period. the data starts high in 2020 which can be explained by the stock market panic at the start of the pandemic.
I recall that the objective of this study is to see the transmission of volatility within the African stock markets and also some world stock markets.
Re: Diebold-Yilmaz, IJF 2012
But what are they? Why are they zero in the last period (for every country)? You can't just throw poorly prepped data into a VAR and hope you will get reasonable results.
-
izymougoue2006
- Posts: 29
- Joined: Tue Apr 24, 2012 8:16 pm
Re: Diebold-Yilmaz, IJF 2012
Countries are South Africa, Tunisia, Nigeria, BRVM, Zambia, Morocco, Mauritius, Tanzania, Egypt, Namibia, Botswana and Keyna and non-African countries are China, France, Germany and the United States.
I specify that the last year I removed it from my base. The fact that the last years are equal to zero is explained by the fact that when calculating the returns (before calculating the volatility) I had limited myself to the date of 30/12/2022. But after I calculated the volatility with the performance data (stopped at 30/12/2022) which makes the last year equal to zero.
I specify that the last year I removed it from my base. The fact that the last years are equal to zero is explained by the fact that when calculating the returns (before calculating the volatility) I had limited myself to the date of 30/12/2022. But after I calculated the volatility with the performance data (stopped at 30/12/2022) which makes the last year equal to zero.
Re: Diebold-Yilmaz, IJF 2012
These are supposed to be volatility estimates? Why are they not exploding in March 2020 when the stock market was crashing?
-
izymougoue2006
- Posts: 29
- Joined: Tue Apr 24, 2012 8:16 pm
Re: Diebold-Yilmaz, IJF 2012
YES of course these are volatility estimates.
I myself am surprised by the results what I am seeing which could explain the fact that the markets do not explode in March 2021.
Do you think it's a data problem?
Also, I calculated the volatility with excel.
If there are, can you tell me the codes that can calculate the volatility?
I myself am surprised by the results what I am seeing which could explain the fact that the markets do not explode in March 2021.
Do you think it's a data problem?
Also, I calculated the volatility with excel.
If there are, can you tell me the codes that can calculate the volatility?
Re: Diebold-Yilmaz, IJF 2012
How did you calculate the volatility using Excel? In the two DY papers, they calculate volatility using daily max and min's of the prices. Do you have those?
If you are doing some type of rolling estimates of the standard deviation of returns
(a) Something is going wrong, since they should be spiking at times when the returns are sharply negative. (Perhaps the Excel calculation is computing the sample standard deviation based upon squares around the mean of the short sample, which might cause a small "volatility" value if the returns are consistently negative during that range).
(b) Even if those are done correctly, they will have very different dynamics than the volatility estimates in the DY papers because they are based upon rolling samples and thus will (by construction) be quite persistent, while DY's are independently estimated in each period.
If you are doing some type of rolling estimates of the standard deviation of returns
(a) Something is going wrong, since they should be spiking at times when the returns are sharply negative. (Perhaps the Excel calculation is computing the sample standard deviation based upon squares around the mean of the short sample, which might cause a small "volatility" value if the returns are consistently negative during that range).
(b) Even if those are done correctly, they will have very different dynamics than the volatility estimates in the DY papers because they are based upon rolling samples and thus will (by construction) be quite persistent, while DY's are independently estimated in each period.
-
izymougoue2006
- Posts: 29
- Joined: Tue Apr 24, 2012 8:16 pm
Re: Diebold-Yilmaz, IJF 2012
I calculated the volatility on Excel.
well, I don't have the DY volatility calculation codes with me. Can you send them to me.
well, I don't have the DY volatility calculation codes with me. Can you send them to me.
Re: Diebold-Yilmaz, IJF 2012
The code is very simple (it's a one-line calculation, shown in both of the papers). But you have to have the daily max and min for each of the price series. It uses a formula for estimating the underlying variance of a (unit length) Brownian motion (the calculation of sigsq) from the range, which is then annualized (if it's a daily calculation) and scaled to percentages:izymougoue2006 wrote:I calculated the volatility on Excel.
well, I don't have the DY volatility calculation codes with me. Can you send them to me.
set sigsq = .361*(log(pmax)-log(pmin))^2
set vol = 100*sqrt(365*sigsq)
Re: Diebold-Yilmaz, IJF 2012
I'm going to guess that the formula you were using in Excel is taking a moving window variance estimate for the returns. There are two problems with that:
- A sample "variance" estimate is based upon variation around a sample mean. The volatility, however, is generally defined to be the variance of a non-drifting Brownian motion, so you would not want means subtracted. (Mean should be assumed zero). That way be why you aren't seeing a spike during the early Covid period since the sample variance is taken around negative means rather than zero.
- The moving window estimates will have (by construction) a great deal of persistence. Most of the dynamics in the VAR will going into unwinding that, so it's not clear whether the DY spillover statistic will show much besides that.