Please see the attached algorithm for an implementation of a Kalman Filter in the analysis of time series data. The Kalman filter is an efficient recursive filter that estimates the state of a linear dynamic system from a series of noisy measurements. Like the Hidden Markov Model, the Kalman Filter develops an underlying Bayesian model, but the state space of the variables is continuous (as opposed to discrete with a HMM) and where all latent and observed variables have Gaussian distributions.
In this example, we apply the filter to the prices of Apple and Google. Please post if you have insight on how to improve the model or extend it to more securities!