* * SV.RPF * Estimation of a stochastic volatility model by (approximate) * state-space methods * * RATS User's Guide, Example from Section 10.7. * 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 * compute meanx2=%digamma(0.5)-log(0.5) compute varx2 =%trigamma(0.5) * * The "gamma" and "phi" variables are very highly correlated when * phi is near 1, which makes estimation by general hill-climbing * procedures somewhat tricky. Instead, we reparameterize this to * use gammax=gamma(1-phi) in place of gamma. * set dlogp = log(usxuk{0}/usxuk{1}) * * Remove any deterministic components (in this case, just the CONSTANT). * linreg dlogp # constant set demean = %resids * * Save the start of the regression range * compute rstart=%regstart() * nonlin phi sw gammax set ysq = log(demean^2)-meanx2 * * Get initial guess values from ARMA(1,1) model * boxjenk(ar=1,ma=1,constant,noprint) 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 * compute phi=%beta(2),sw=-phi*varx2*(1+%beta(3)^2)/%beta(3)-(1+phi^2)*varx2 compute sw=%if(sw<0,.1,sw) compute gammax=%mean * * Estimate the unconstrained model * dlm(method=bfgs,sw=sw,sv=varx2,y=ysq,type=filter,c=1.0, \$ sx0=sw/(1-phi^2),x0=gammax,a=phi,z=gammax*(1-phi)) rstart * states * * Estimate the RW model * nonlin sw dlm(method=bfgs,sw=sw,sv=varx2,y=ysq,type=filter,c=1.0, \$ presample=diffuse,a=1.0,vhat=e,svhat=s) rstart * states