set.seed(111)
nobs = 80; # n is often larger than 1000 in practice.
mu = 0; phi = 0.97; sigma_eta = 0.3; rho = -0.3;
h = 0; Y = c();
for(i in 1:nobs){
eps = rnorm(1, 0, 1)
eta = rho*sigma_eta*eps + sigma_eta*sqrt(1-rho^2)*rnorm(1, 0, 1)
y = eps * exp(0.5*h)
h = mu + phi * (h-mu) + eta
Y = append(Y, y)
}
npart = 1000
asv_apf(mu, phi, sigma_eta, rho, Y, npart)
Run the code above in your browser using DataLab