# How to tune Kalman filter's parameter?

I plan to use Kalman filter to estimate saving account amount.

However, I'm a bit lost at how to tune the filter's parameters.

Taking as the example from the Wikipedia page, basically there are three parameters.

P(0) can be set as (L, 0; 0, L), where L is a big number. This is fine, anyway P(k) shall converge.

R supposedly is a constant; it's suggested to be taken as covariance of z. Fine, thought Z is composed of x and v.

How about Q? From An Introduction to the Kalman Filter by Greg Welch and Gary Bishop, different values of Q seems seriously affect the converge of estimation.

Any suggestions on how to tune Q?

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 estimation as a least-squares problem, such as using ALS. Below ALS and a few related solutions to the problem. However, what makes your problem a lot easier is that you apply Kalman filters to a savings account. I do not know which exact method you use to model a savings account or what distributional properties it has. However, it looks and sounds a lot easier than applying Kalman filters to financial time series with potentially several Brownian motion components. A savings account "process" may have much more straight forward covariances which you can equip Q with.

Autocovariance Least-Squares (ALS) Package

A new autocovariance least-squares method for estimating noise covariances

A generalized autocovariance least-squares method for Kalman filter tuning

• Another solution is to relax the distributional assumptions that underlie Kalman filters and focus your efforts on techniques such as Particle Filters. I have to great success implemented Particle Filters in financial time series tracking as well as forecasting. However, a word of warning is that particle filter algorithms are extremely computationally expensive and hence they may not be applicable to real-time applications.
• appreciate your hints! Jul 18 '13 at 10:24
• +1 Are you working with Kalman filters yourself, Matt? Jul 18 '13 at 10:46
• I did but currently not. I work on something similar than particle filters but the algorithms are very expensive computationally. Digging into Cuda GPU programming in order to ease some matrix computations. Why, do you?
– Matt
Jul 18 '13 at 14:57
• @MattWolf: (a few years later... ;-) Still not, although I looked into the theory recently. I work with hidden markov models which are related. May 31 '15 at 14:52

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(\theta) = \prod_{t=1}^n p(\epsilon_t; \theta)$$ where $\epsilon_t = z_t - E(z_t|z_1, \ldots z_{t-1})$. Each $p(\epsilon_t;\theta)$ is Gaussian, and you can get them from a kalman filter iteration. However, they're usually really nonlinear in $\theta$.

Learning/fitting with particle filters is very difficult since you can't evaluate $L(\theta)$. Fortunately for you, it seems to be irrelevant. You don't need them in the linear gaussian case.

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 parameters converge to fixed values.

Something to be aware of is whether your data is stationary or non-stationary. If stationary, you have to use a different state equation than in the non-stationary case, and this affects the calculation of the noise covariances and initial state and state covariance.