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