# How does Kalman filtering of beta in pairs trading model work in R?

Could anyone show how this could be done in R? The dlm package seems to be a good start, but I can't really find any good examples to learn from.

Currently I have two timeseries of the closing prices for two stocks. I then do a rolling regression that gives me the corresponding timeseries of the beta between the two stocks.

How would I go about to implement a Kalman filter for this beta?

-

Have you checked out the vingette for DLM by Petris?

Incidentally, Petris also has an R-book on the DLM package which includes estimation of beta as an example.

-
That's seems to be a nice book to reference. I found these two pdfs explaining kalman filtering too: first, second –  c00kiemonster Nov 11 '11 at 0:33
If you want to learn Kalman filtering in general I think a good text is Rene Carmona's Statistical Analysis of Financial Data: amazon.com/Statistical-Analysis-Financial-Data-S-PLUS/dp/… –  Quant Guy Nov 11 '11 at 1:48