Harvey, Ruiz, Shephard(1994) MV Stochastic Volatil

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

Harvey, Ruiz, Shephard(1994) MV Stochastic Volatil

Unread post by TomDoan »

This provides replication files for Harvey, Ruiz and Shephard(1994), "Multivariate Stochastic Variance Models", Review of Economic Studies, vol 61, no. 2, pp 247-264. This uses state-space approximations for the log squared returns, extending the techniques used in univariate models to a multivariate setting. In their model, the log variances evolve as individual random walks, but with a correlated increment and a correlated measurement error.
univariate.rpf
Univariate models
(4.46 KiB) Downloaded 1253 times
multivariate.rpf
Multivariate models
(7.33 KiB) Downloaded 1153 times
xrates.xls
Data file
(66.92 KiB) Downloaded 1248 times
pls
Posts: 19
Joined: Sat Mar 22, 2014 2:24 pm

Re: Harvey, Ruiz, Shephard(1994) MV Stochastic Volatil

Unread post by pls »

With regard to the multivariate stochastic volatility program, which I am applying to a 2 variable model, I have two questions.
1) Can I incorporate two exogenous variables in the equations for the stochastic volatilities of the two variables? The coefficients of the exogenous variables also have to be estimated by the state space model. Where would the change occur in the code?
2) I would like to output the stochastic volatilities and covariance. How can I do this?
Thanks.
The code which I extracted from the Harvey, Ruiz and Shephard multivariate program and modified slightly for 2 variables is as follows:

Code: Select all

compute meanx2=%digamma(0.5)-log(0.5)
compute varx2 =%trigamma(0.5)
*
*  Create the adjusted log squared return series
*
dec vect[series] w(2)
set dlogp = log(price/price{1})
diff(center) dlogp / demean
set w(1) = log(demean**2)-meanx2
set dlogp = log(ADMD/ADMD{1})
diff(center) dlogp / demean
set w(2) = log(demean**2)-meanx2

*
dec packed rhosd(1,1) sigetaf(2,2)
dec symm   sv(2,2)
*
* %rhosw combines the packed lower triangular "rho" matrix with the
* known variances of the components to give the full covariance matrix.
* The sigma eta matrix is easier to estimate in square root form so it
* is also a packed lower triangle. This also makes the estimation
* process more similar to the factor method later.
*
function %rhosw
type symm %rhosw
local integer i j
dim %rhosw(2,2)
ewise %rhosw(i,j)=%if(i==j,varx2,varx2*rhosd(i-1,j))
end
*
function %ltouterxxF
type symm %ltouterxxF
local rect lt(2,2)
local integer i j
ewise lt(i,j)=%if(i>=j,sigetaf(i,j),0.0)
compute %ltouterxxF=lt*tr(lt)
end
*
* sigmaeps backs out the covariance matrix of epsilon from the estimate
* for eta
*
function %sigmaeps
type symm %sigmaeps
*
local integer i j n
local real    rhowork rho factor
local parmset rootf
*
dim %sigmaeps(2,2)
do i=1,2
   compute %sigmaeps(i,i)=%pi**2/2.0
   do j=1,i-1
      nonlin(parmset=rootf) rho
      compute rho=rhosd(i-1,j)
      find(noprint,parmset=rootf) root rhosd(i-1,j)-rhowork
         compute rhowork=0.0
         compute factor=2.0*rho**2
         do n=1,100
            compute rhowork=rhowork+factor/n
            compute factor=factor*n/(n+.5)*rho**2
         end do n
         compute rhowork=rhowork*2.0/%pi**2
      end find
      compute %sigmaeps(i,j)=rho*%pi**2/2.0
   end do j
end do i
end
*
* The estimates of the sigmaeta matrix that we get are somewhat
* different from those in the paper, and the likelihood (after adjusting
* for the constants) is higher here. It appears that the maximization
* algorithm used in doing the paper ran up against the invertibility
* boundary (note the .99 in the (2,4) slot in the correlation matrix for
* eta), and either stalled out or hit a slightly lower local maximum.
*
nonlin rhosd sigetaf
compute [rect] c=%identity(2)
compute rhosd=%const(0.0)
compute sigetaf=%sqrt(%diag(||0.001,0.001||))
dlm(y=%xt(w,t),c=c,startup=%(sv=%rhosw(),sw=.001*%ltouterxxF()),sw=sw,sv=sv,$
  presample=diffuse,condition=1,method=bfgs,iters=100) 2 *
*
* Get the covariance matrix for epsilon
*
compute sigmaeps=%sigmaeps()
*
* Show the correlation matrices for epsilon and eta
*
disp %cvtocorr(sigmaeps)
disp %cvtocorr(sw)
*
* Table 4 analysis. Because the estimated sigmaeta is quite a bit
* different, these results are as well. The eigenvectors shown in this
* table are actually scaled by the square roots of eigenvalues as is
* done in table 5, so there is no need for a separate table.
*
eigen(scale) sw eigval eigvect
report(action=define)
report(atrow=1,atcol=1) "(a)"	"Eigenvalues" eigval
report(atrow=2,atcol=2) "Eigenvectors" eigvect
report(atrow=6,atcol=2) "Percentage of Variance" eigval/%sum(eigval)
*
eigen(scale) %cvtocorr(sw) eigval eigvect
report(atrow=8,atcol=1) "(b)"	"Eigenvalues" eigval
report(atrow=9,atcol=2) "Eigenvectors" eigvect
report(atrow=13,atcol=2) "Percentage of Variance" eigval/%sum(eigval)
report(action=show)
*
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Harvey, Ruiz, Shephard(1994) MV Stochastic Volatil

Unread post by TomDoan »

pls wrote:With regard to the multivariate stochastic volatility program, which I am applying to a 2 variable model, I have two questions.
1) Can I incorporate two exogenous variables in the equations for the stochastic volatilities of the two variables? The coefficients of the exogenous variables also have to be estimated by the state space model. Where would the change occur in the code?
You would need to figure out what exactly you mean. First off, the state-space model is in log variance, not the variance. A shift in the log isn't too hard, while a shift in the variance itself isn't. However, there's also the question of what the exogenous shift does? Is it a shift in the evolution of the log variance (so it would enter the state equation using a Z option) or a shift in the measurement equation (which would use the MU option).
pls wrote: 2) I would like to output the stochastic volatilities and covariance. How can I do this?
If that's what you want, this may be the wrong model. Those are very non-linear functions of what the model estimates.
pls
Posts: 19
Joined: Sat Mar 22, 2014 2:24 pm

Re: Harvey, Ruiz, Shephard(1994) MV Stochastic Volatil

Unread post by pls »

Suppose the exogenous variables enter the log variances in the z's. Is there any way to obtain the separate coefficients of the exogenous variables and the t statistics for these coefficients?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Harvey, Ruiz, Shephard(1994) MV Stochastic Volatil

Unread post by TomDoan »

Sure. Perron and Wada (for instance) has a Z formula which estimates a coefficient on a dummy variable shift.
bekkdcc
Posts: 34
Joined: Wed Feb 24, 2016 4:21 am

Re: Harvey, Ruiz, Shephard(1994) MV Stochastic Volatil

Unread post by bekkdcc »

Dear Tom,

I have a mean model and can not be able to decide where I shouldput it, correctly. I used GARCH12_1.RPF for my model.

I want to estimate SV model with a mean equation

y(t)=y(t-1)+x(t-1)+z(t-1)+sqrt(h(t))v(t)
logh(t)=.......
....
for example
y is usxuk usxger
x is usxger
z is usxjpn

* GARCH12_1.RPF
* Stochastic volatility model, estimated by state-space approximation.
*
* From Harvey, Ruiz and Shephard(1994), "Multivariate Stochastic
* Variance Models", Review of Economic Studies, vol 61, no. 2, pp
* 247-264.
*
open data xrates.xls
data(format=xls,org=columns) 1 946 usxuk usxger usxjpn usxsui
*
* meanx2=mean of log chi-square,varx2=variance of log chi-square.
* These are exact (rather than rounded) values.
*
compute meanx2=%digamma(0.5)-log(0.5)
compute varx2 =%trigamma(0.5)
*
set dlogp = 100.0*log(usxuk{0}/usxuk{1})
diff(center) dlogp / demean

set dlogp1 = 100.0*log(usxger{0}/usxger{1})
set dlogp2 = 100.0*log(usxjpn {0}/usxjpn {1})

garch(exp,nomean,hseries=hgarch) / demean
*
set ysq = log(demean^2)-meanx2-log(dlogp1^2)-log(dlogp2^2)
*
* Get initial guess values from an ARMA(1,1) model
*
boxjenk(ar=1,ma=1,constant) ysq
*
* phi is taken directly as the AR(1) coefficient. The variance sw is
* backed out by matching first order autocorrelations in the MA term.
* gamma is chosen to reproduce the mean of the ysq series
*
nonlin phi sw gammax
compute gammax=%beta(1)
compute phi=%beta(2)
compute sw=-phi*varx2*(1+%beta(3)^2)/%beta(3)-(1+phi^2)*varx2
compute sw=%if(sw<0,.1,sw)
*
* Estimate the unconstrained model
*
dlm(y=ysq,sw=sw,sv=varx2,c=1.0,a=phi,z=gammax*(1-phi),$
presample=ergodic,method=bfgs,type=filter) 2 * states



But I can not be sure if this is true, or how can I re-write these bold places?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Harvey, Ruiz, Shephard(1994) MV Stochastic Volatil

Unread post by TomDoan »

I'm a bit confused by this.

y(t)=y(t-1)+x(t-1)+z(t-1)+sqrt(h(t))v(t)

Do you mean that literally---that is, the coefficients on y{1}, x{1} and z{1} are all 1's? If that's true, then the ysq in the state-space approximation is

log(y-y{1}-x{1}-z{1})^2-meanx2

You don't need to de-mean anything, since I assume you intend that that linear combination has mean zero.
Post Reply