Seder,
Your question is a little unclear, so it's not possible to give you a precise answer. Could you clarify your question? It's also helpful if you briefly describe your application -- for example, tell us what time series are you modeling.
First, is phi a given? Or do you intend phi to be a parameter (and, hence, estimated by dlmMLE)?
Second, are alphabar and betabar given? Or are they parameters which must be estimated?
If alphabar, and betabar are given, I suggest recentering alpha and beta around alphabar and betabar: subtract alphabar from alpha, and subtract betabar from beta. That will greatly simplify the recursion equations for alpha and beta:
alpha[i,t] = phi*alpha[i,t] + W[i,1,t]
beta[i,t] = phi*beta[i,t] + W[i,2,t]
These equations fit easily into the state-space paradigm of DLM, and phi becomes just another parameter to estimate using buildCAPM and dlmMLE.
If alphabar and betabar are parameters, not givens, then the situation is a little more complicated: you will need to incorporate them into the G matrix of the DLM model and also incorporate them into buildCAPM for estimation by dlmMLE.
By the way, are you aware that you must have abs(phi) < 1.0? Otherwise these equations are not mean-reverting.
Finally, are you familiar with the Triantafyllopoulos-Montana model of mean-reverting spreads? Your state-space equations are very similar to theirs, so perhaps you could build on their work.
Paul Teetor, Elgin, IL USA
http://quanttrader.info/public
________________________________
From: nserdar
To: r-sig-finance@r-project.org
Sent: Thursday, October 25, 2012 6:22 PM
Subject: Re: [R-SIG-Finance] Kalman Filter + DLM Package in R
This is Kalman Filter random walk process code :
library(dlm)
buildCAPM<-function(u){
dlmModReg(rm,dV=exp(u[1]),dW=exp(u[2:3])) # rm market
}
outMLE<-dlmMLE(rt,parm=rep(0,3),buildCAPM) # rt return of indusrty
mod<-buildCAPM(outMLE$par)
outFilter<-dlmFilter(rt,mod)
mae<-mean(abs(outFilter$f)-rt) # MAE
mse<-mean(((outFilter$f)-rt)^2) #MSE
What I am asking how to modify this code as Kalman Filter Mean Reverting
For example:
R(it)= Alpha(it)+ Beta(it)R(mt)+ V(it)
KF Mean Reverting
Alpha(it)= Alphabar(i)+ phi* (Alpha(it-1)-Alphabar(i))+W(i1t)
Beta(it)= Betabar(i)+ phi* (Beta(it-1)-Betahabar(i))+W(i2t)
Regards,
Serdar
--
View this message in context: http://r.789695.n4.nabble.com/Kalman-Filter-DLM-Package-in-R-tp4647470p4647474.html
Sent from the Rmetrics mailing
list archive at Nabble.com.
_______________________________________________
R-SIG-Finance@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
[[alternative HTML version deleted]]