[R] Help with kalman-filterd betas using the dlm package
spencerg
spencer.graves at prodsyse.com
Tue May 12 23:16:00 CEST 2009
Have you worked through "vignette('dlm')"? Vignettes are nice
because they provide an Adobe Acrobat Portable Document Format (pdf)
file with a companion R script file, which you can get as follows:
(dlm. <- vignette('dlm'))
Stangle(dlm.$file)
The first of these two lines opens the "pdf" file. The second
creates a file "dlm.R" in the working directory (getwd()) containing the
R commands discussed in the "pdf" file.
If I remember correctly, your question is answered in this vignette.
You may also be interested in a book that is soon to appear about
this package: Petris, Petrone, and Campagnoli (2009) Dynamic Linear
Models with R (Springer;
http://www.amazon.com/Dynamic-Linear-Models-R-Use/dp/0387772375/ref=sr_1_4?ie=UTF8&s=books&qid=1242162708&sr=1-4),
scheduled to ship in late June. If you have long-term interest in this
subject, as I suspect you may, you might find this book interesting and
useful.
Hope this helps.
Spencer Graves
tom81 wrote:
> Hi all R gurus out there,
> Im a kind of newbie to kalman-filters after some research I have found that
> the dlm package is the easiest to start with. So be patient if some of my
> questions are too basic.
>
> I would like to set up a beta estimation between an asset and a market index
> using a kalman-filter. Much littarture says it gives superior estimates
> compared to OLS estimates. So I would like to learn and to use the filter.
>
> I would like to run two types of kalman-filters, one with using a
> random-walk model (RW) and one with a stationary model, in other worlds the
> transition equition either follow a RW or AR(1) model.
>
> This is how I think it would be set up;
>
> I will have my time-series Y,X, where Y is the response variable
>
> this setup should give me a RW process if I have understood the example
> correctly
> mydlmModel = dlmModReg(X) + dlmModPoly(order=1)
>
> and then run on the dlm model
> dlmFilter(Y,mydlmModel )
>
> but setting up a AR(1) process is unclear, should I use dlmModPoly or the
> dlmModARMA to set up the model.
>
> And at last but not the least, how do I set up a proper build function to
> use with dlmMLE to optimize the starting values.
>
> Regards Tom
>
More information about the R-help
mailing list