# Forward Filtering Backwards Sampling (FFBS) and Look-Ahead Bias

Assumptions / Context: Let's assume that I have data that can be modeled as a dynamic linear model. To estimate the parameters (e.g., covariance matrix of the state/system equation), I use a Gibbs sampling or other Markov Chain Monte Carlo procedure.

Problem: The problem is that to use the Gibbs sampler I use the FFBS algorithm which uses the entire history of the data series. Thus, if I want to test the accuracy of my model's predictions in the past I would be using a model fitted with data from the future. Therefore, there is look-ahead bias in the performance measures that I may calculate (e.g., mean squared error of the residuals).

My Initial Though Surely Inferior Thoughts: Assuming I have "point-in-time" data (e.g., I know when the data became available to modeler in the past), a "brute-force" way would be to estimate the model's parameters using data from period $1$ to $t-1$ and forecast the observation variable $y_{t}$ and repeat this procedure for all $t \in T$. So, if I had a univariate time series with 80 observations I would need to repeat this process 79 times (first for the data in period $t=1$, second for data from periods $t=1:2$, third for data from periods $t=1:3$, and so on). I would have 79 different models for this time series. Then, I would calculate some performance measure (e.g., Theil's U) using the residuals from my forecasts of $y_{t}$.

Questions: 1) Am I incorrect about the look-ahead bias created by the FFBS algorithm?, and 2) Does anybody know a way to efficiently estimate a State Space time series model using Bayesian techniques?

This question is a little old, but maybe it is still relevant. As far as I understand your question, if you have $T$ data available, and are trying to predict observations in the future, surely you're "cheating" if you're using the whole data to "predict" $y_{t}$ with $t<T$. Indeed, what you're doing there is smoothing, not prediction. As in other ML tasks, choose a given amount of training observations $T_{learn}<T$, then predict $y_{T_{learn}+k}$ (as far ahead in the future as you need) and evaluate performance. It seems to me that your setup is doing this: by sliding $T_{learn}$ you're learning more informed model and you should be able to show that your predictions get better.
If the parameters you are estimating do not vary over time, you may split the observed time series $y_{1:T}$ in two series, $y_{1:k}$ and $y_{k+1:T}$. Then you would apply MCMC on $y_{1:k}$ in order to sample from the posterior distribution of your parameters. After that, you could fix your parameters at some estimate taken from the posterior, e.g. the posterior mean or maximum, and evaluate the predictions on $y_{k+1:T}$.