[R-SIG-Finance] Kalman Filter + DLM Package in R
nserdar
snes1982 at hotmail.com
Fri Oct 26 01:22:02 CEST 2012
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.
More information about the R-SIG-Finance
mailing list