I am trying to implement bootstrap filter and I'm trying to understand it based on Bootstrap filter/ Particle filter algorithm(Understanding)
EDIT: Following is the example that I'm trying to solve:
Consider the stochastic volatility model
$$x_t | x_{t-1}\sim\mathcal{N}(x_t; \phi x_{t-1}, \sigma^2)$$ $$y_t | x_t\sim\mathcal{N}(y_t;0, \beta^2\exp(x_t))$$
where $x_t$ denotes the underlying latent volatility and $y_t$ the observed scaled log-returns calculated by $$y_t = 100[\log(s_t) − \log(s_{t-1})]$$
The $T = 500$ observations that we consider are log-returns during a two year period.
We would like to find an estimation for marginal filtering distribution at each time index $t = 1, ... , 𝑇$ using the bootstrap particle filter with $𝑁 = 500$ particles. I make the following assumption for the initial state $x_1$
$$x_1\sim\mathcal{N}(0,\frac{\sigma^2}{1-\phi^2})$$
The algorithm that I use is following:
(1) Initialization:
for i=1,..N, sample $x_1\sim\mathcal{N}(0,\frac{\sigma^2}{1-\phi^2})$
(2) Importance sampling step:
a. for i=1,.. N, sample $\tilde x_t | x_{t-1}\sim\mathcal{N}(x_t; \phi x_{t-1}, \sigma^2)$
b. evaluate $\tilde w_t^i \sim \mathcal{N}(y_t;0, \beta^2\exp(x_t))$
c. Normalize weights $w^{(i)}_{t}=\frac{\tilde{w}^{(i)}_{t}}{\sum_{i=1}^{N}\tilde{w}^{(i)}_{t}}$
(3) Resample:
a. Construct the cumulative sum of weights (CSW) by computing $c_i=c_{i-1}+w_t^i$
b. Let i = 1 and draw a starting point from the uniform distribution $u_1\sim U[0, 1/N]$
c. For j = 1, …, N, Move along the CSW by making $u_j=u_1+(j-1)/N$
d. While $u_j>c_i$ make $i=i+1$
e. Assign samples $x_t^j=x_t^i$
Is this a correct algorithm? what is marginal filtering distribution and mean of the filtering distribution?