# Tag Info

13

A simple google search should get your started: I like this one the best because it compares different packages: http://stat-www.berkeley.edu/~brill/Stat248/kalmanfiltering.pdf and here couple more: http://www.r-bloggers.com/the-kalman-filter-for-financial-time-series/ http://cran.r-project.org/web/packages/dlm/index.html http://cran.r-project.org/web/...

9

A great example of kalman filtering is in the Kyle Model. I have attached a presentation on the application of R to the kalman filter in the Kyle Model. http://www.rinfinance.com/RinFinance2009/presentations/microstructure-tutorial.pdf Basically in the Kyle Model, a market maker finds the likelihood an asset is ending up at a certain price given that a ...

8

In addition to getting the right transition model for the Kalman filter, the main obstacle to optimizing filter performance is to implement an optimal initialization. I use an iterative approach to initialize or "tune" the Kalman filter, known as adaptive tuning. I do this because I've found alternative methods of initializing the Kalman filter (...

6

Estimation of the initial states of R and particularly Q is indeed more of an art than science. The task at hand is to estimate the covariances. You have basically two main choices: Live with the fact that you will never be able to exactly pinpoint the covariance of noise in financial time series. The most often used approach is to pose the coveriance ...

6

There is no a "yes/no answer" to that question. Generally Kalman Filter tends to be better than linear regression, but everything depends on the data which you have, how you calibrate your model. I expect that you have used some library for estimating linear regression parameters. Now you need to think how will you "tune" Kalman filter - the constants F,...

5

We use KFilter. here is a link to their documentation page for you to peruse. If you share a bit more about how you want to use the filter then it may help us. However please note that suggest me a library questions are typically not on topic on any of the stack exchange sites To update the answer to include the function the user wanted.... Here is the ...

5

There is no magic in the Kalman Filter. The linear regression model usually assumes the coefficients follow a random walk and as such it essentially boils down to an estimation followed by exponential smoothing of the coefficients.

4

Consider historical observation dates $t_0 < t_1 < \cdots < t_n$. From the state variable equations \begin{align*} dZ_t^1&=-kZ_t^1dt+h_1dW_t^1+h_2dW_t^2,\\ dZ_t^2&=h_0dW_t^1. \end{align*} We obtain that, for $i=1, \ldots, n$, \begin{align*} Z_{t_i}^1 &= e^{-k \Delta t_i} Z_{t_{i-1}}^1 + h_1 \int_{t_{i-1}}^{t_i}e^{-k (t_i-s)}dW_s^1 + h_2 ...

4

Expanding on the answer by @ir7, here is some pykalman code/psuedocode to help get you started. This can be adjusted in many ways but I have left in some parameters to give you an idea. I left a documentation link at the bottom as well. The functions will setup Kalman Filters that are applied to your data and subsequently that data is fed to a regression ...

4

The following paper gives you a step-by-step presentation of how to use the Kalman filter in an application in a pricing model framework for a spot and futures market. Everything is explained using Excel: A Simplified Approach to Understanding the Kalman Filter Technique by T. Arnold, M. Bertus and J. M. Godbey

3

I recently blogged about this very topic. Essentially, there are 3 ways to estimate Q & R. approximate calculate variate estimate of error in a controlled environment if z doesn't change, calculate variance estimate of z if z does change, calculate variance of regression estimate of z guess use some constant multiplied by the identity matrix ...

3

If you have a linear/gaussian state space model and you're using a Kalman Filter, you can use maximum likelihood estimation or the EM algorithm. I personally prefer the former since you don't need to know anything about smoothing. If you use the EM, you do. If your observations are $z_1, \ldots, z_n$, then you can write down an innovations likelihood $$L(\... 3 This book goes through exactly this problem in quite detail (with C++ codes included). I've worked through it in the past, but can't sum it up off the top of my head. 2 Usually var(e_x), var(e_y) variances are calibrated by maximum likelihood from data similar as you want to calibrate your parameters \theta. Ratio var(e_x)/var(e_y) tells you what are changes in your time-series var(e_x)/var(e_y) is small: changes in time-series of observations are just noise and underlying state doesn't change much; var(e_x)/... 2 A good article on adaptive Kalman filter tuning is: Introduction to the Kalman Filter and Tuning its Statistics for Near Optimal Estimates and Cramer Rao Bound The authors present an adaptive approach, which means that you make initial estimates of the noise covariances, and iterate the Kalman filter and the noise covariance estimates until all the ... 2 This is definitely not a Kalman filter's issue: if you replace this line of code args <- eapply(env = env, FUN = function(x){ClCl(x)}) with this one args <- eapply(env = env, FUN = function(x){ClCl(x)})[Symbols] eapply() will keep the order of the original Yahoo query from quantmod. You can check and you will see each \beta_{t} matches about the ... 2 In the paper you cited in the question, the equation (1) is not the equation of state in kalman filter model, but an AR(3) estimated via OLS as shown in Stock & Watson (2002). What the authors estimated in the paper using the Kalman filter is the latent variables f_t,_h and the relative lags through which they estimated both the equation (1) and (2).... 2 I would suggest check out the Wikipedia page first and use more stylized notations. In your update equation mean(t) = mean(t-1) + K(t) * ( price(t) - mean(t-1) ) you are basically saying that your state process is mean(t) and price(t) is a measurement of mean(t). This doesn't sound legit On the other hand, you could have a mean reverting process$$\text{...

2

Rt in your notation is "filtered" variance R(t|t). The prediction of variance R(t+1|t) adds another term which is not guaranteed to be decreasing overtime. I think another critical assumption is Ve in your equation. How do you define Ve? For price series Ve as a proxy for volatility makes sense to be time-varying, and probably exhibit some auto-correlation....

2

One resource that has Kalman Filter and Smoother, and Expectation-Maximization algorithms for a Linear Gaussian Model is pykalman module. You can check out statsmodels module too.

1

The linear Kalman filter still minimises the mean squared error of the estimate even if noise are non-Gaussian white, it's just that in the Gaussian case you will have the full posterior distribution from the mean and covariance estimates alone. So in practice it wouldn't be absolutely necessary to test for Gaussian noise, and have the Kalman filter still '...

1

I've worked on this further and have the following thoughts: A better formulation of the state space equation (sse) is of the form: (Yes, the matrices don't conform in the typesetting above. Sorry.) The FKF package in R seems to force one to use the cumbersome formulation that I set out at the top. Matlab allows the briefer formulation set out ...

1

Yes, linear regression can be cast as a Kalman filter estimate. I believe, D. Simons book "Optimal State Estimation: .. " has all the details.

1

It is not about estimating those equations via PC. There are various methods to estimate the latent factor fth, one of which is principal components. They have asked us to use that. Series(z) in those equations is observed data so we use the estimated fth and observed z to perform the OLS as suggested AR(3) or ARMA(1,0,3) would make the residual series ...

1

Q1- for AR(1) only one 1 lag, ie burn in, should be sufficient. However, you could do 50 to feel comfortable. Q2- Matching the theoretical one is not a possibility Q3. (update) AIC/BIC tests on the simulated series can help select the best one. You can get the logL values from KF or estimate functions in Matlab.

Only top voted, non community-wiki answers of a minimum length are eligible