# Bayesian Stochastic Factor Model

Preface: My knowledge is quite introductory to Bayesian analysis and statistical modeling so my problem might require re-framing and I could be trying to fit a round peg through a square hole.

I am trying to implement a single factor model where the factor parameter is time-varying and attempts to capture clustering. The stochastic vol example was somewhat helpful but this particular model has the parameter `beta(i)_p,t` and conditional posterior distributions depending on `beta(i)_p,t-1` and `beta(i-1)_p,t+1` where is `i` is the iteration step. Original Paper

The attached image provides a little more detail for the pricing model and priors. Any advice on implementing in PyMC3 and possible hyper-parameter distributions would be appreciated.

If I understand correctly, the iteration in the paper refer to each MCMC draw (using Gibbs sampler) right?
In that case, your problem could be breakdown to 2:

1. implement the Stochastic Factor model in PyMC3. I think you are on a right path of reading stochastic vol and rolling regression example, time-varying parameters could be implemented using a `theano.scan`, but in many case it could be implemented even without.
2. Gibbs sampler, this part is a bit more tricky, as you need experience of implementing sampler. But since you are trying to implement a special sampler, you can always extract the logp function from the model, and wrap it in a python control flow to do updates.

@junpenglao
Could you elaborate on point 2 more? It seems the model requires 2 logp functions correct?

Thank you!

No, you only have one logp function from a model. I think what you are looking at is conditional logp for Gibbs update.