############################################################################################ # Stochastic volatility # Individual move algorithm for log-volatilities # Random walk Metropolis ############################################################################################ # # HEDIBERT FREITAS LOPES # Associate Professor of Econometrics and Statistics # The University of Chicago Booth School of Business # 5807 South Woodlawn Avenue # Chicago, Illinois, 60637 # Email : hlopes@ChicagoGSB.edu # URL: http://faculty.chicagobooth.edu/hedibert.lopes/research/ # ############################################################################################ svol.rw = function(y,mu,phi,tau2,h0,h,vh){ eta2 = c(rep(tau2/(1+phi^2),n-1),tau2) eta = sqrt(eta2) coef1 = (1-phi)/(1+phi^2)*mu coef2 = phi/(1+phi^2) for (t in 1:n){ if (t==n){ mut = mu + phi*h[t-1] }else{ if (t==1){ mut = coef1 + coef2*(h[2]+h0) }else{ mut = coef1 + coef2*(h[t+1]+h[t-1]) } } ht = rnorm(1,h[t],vh) num = dnorm(ht,mut,eta[t],log=TRUE)+dnorm(y[t],0,exp(ht/2),log=TRUE) den = dnorm(h[t],mut,eta[t],log=TRUE)+dnorm(y[t],0,exp(h[t]/2),log=TRUE) lacc = min(0,num-den) if (log(runif(1))