1.66667

1.7 | 3 ratings Rate this file 190 downloads (last 30 days) File Size: 41.15 KB File ID: #18172

Estimation and Simulation of State Space (Kalman Filter) Models with Matlab

by Marcelo Perlin

 

01 Jan 2008 (Updated 09 Sep 2008)

Code covered by BSD License  

Functions and Scripts for Simulation and Estimation of State Space models

Download Now | Watch this File

File Information
Description

This toolbox was designed to simulate and fit linear state space models.

The main literature I used for this particular package is Kim and Nelson (1999).

A state space model (without non stochastic coefficients) is given by:

y(t)=beta(t)*x(t)'+e(t)
beta(t)=u+F*beta(t-1)+v(t)

e(t)~N(0,R)
v(t)~N(0,Q)

Where x(t) is a vector of size (1,k), beta(t), u and v(t) are vectors with size [1,k] and F, Q are matrices of size [k,k]. More details about the model can be found at the reference.

The main advantage of this package is that the fitting function lets you build your own state space model by changing the input option optionsSpec. Please check the pdf document and the example scripts at the zip file for instructions of how to use it.

Some comments about the fitting code:

• So far it doesn’t handle autoregressive processes between series of the beta matrix. In other works, at the F matrix, the only estimated coefficients are in the diagonal (all non diagonal elements are zero).

• The model is estimated by Gaussian maximum likelihood with the function fminsearch. I also played around with fminunc(), but there was no improvement over fminsearch when it comes to robustness and speed.

• So far the code doesn’t handle state space models with mixture of non stochastic and stochastic coefficients, that is, when you want some variables to have stochastic coefficients and others not in the same model.

References
KIM, C., J., NELSON, C., R. (1999) “State Space Model with Regime Switching: Classical and Gibbs-Sampling Approaches with Applications” The MIT press.

_______________

[simSpec_Out]=kalmanSim(nr,Coeff)

Function for Simulation of a State Space Model

INPUT:
      nr - number of observations to be simulated
      Coeff - Coefficients of the model (check Example_Script_1_Sim for
      instructions of how to use this input)

OUTPUT:
      simSpec_Out - A structure with the simulated state space series
      and also the simulated regressors

_______________

[specOut]=kalmanFit(dep,indep,optionsSpec)

Function for Estimation of a state space model by means of kalman filter

INPUT:
      dep - dependent variable

      indep - independent variable with regressor (aka independent variables)

      optionsSpec - (optional, default='e'). A options structure for defining your own state space model. Please check the pdf document in the zip file for instruction of how to use. The script Example_Script_2_kalmanFit.m also shows that.

OUTPUT:
      specOut - A structure with the coefficients, final log likelihood,
 latent variables, among other things.

Required Products Optimization Toolbox
Statistics Toolbox
MATLAB release MATLAB 7.2 (R2006a)
Zip File Content  
Other Files
State_Space_Models_FEX/Example_FEX.mat,
State_Space_Models_FEX/Example_Script_1_kalmanFit.m,
State_Space_Models_FEX/Example_Script_1_kalmanSim.m,
State_Space_Models_FEX/Example_Script_1_kalmanSim_and_kalmanFit.m,
State_Space_Models_FEX/Example_Script_2_kalmanFit.m,
State_Space_Models_FEX/Example_Script_2_kalmanSim.m,
State_Space_Models_FEX/Example_Script_2_kalmanSim_and_kalmanFit.m,
State_Space_Models_FEX/Example_Script_3_kalmanFit.m,
State_Space_Models_FEX/Example_Script_4_kalmanFit.m,
State_Space_Models_FEX/m_Files/fixParam.m,
State_Space_Models_FEX/m_Files/getparam0_rollOLS.m,
State_Space_Models_FEX/m_Files/kalmanFit.m,
State_Space_Models_FEX/m_Files/kalmanLik.m,
State_Space_Models_FEX/m_Files/kalmanSim.m,
State_Space_Models_FEX/The_State_Space_Fitting_Function.pdf
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
29 Jan 2008 Miles P

And the point is??? One is better off downloading the Kalman filter tutorial script here on file exchange. Dont waste your time with this.

06 May 2008 Nick Firoozye

I have to agree with the first commenter. What's the point? There are much more complete Kalman filter packages around (e.g., The SSM Toolbox). This merely does the same in a more limited way.
At the same time, the author is quoting Kim and Nelson. The only justification for using this package would be that it actually implements all of the Gauss codes from Kim-Nelson (i.e., SSMs with Regime Shift and heteroskedasticity, and the same in a Bayesian framework).

Unfortunately, there is a significant amount of work to be done (i.e., only about 20% of the total task has been completed).

07 May 2008 Marcelo P.

I agree with some of your points. When it comes to compare it to SSM toolbox, there is really no comparison at all. SSM is much more complete and far more developed than mine. My point with this submission was just to publish a simple, self contained, user friendly toolbox for simulation and estimation of linear state space models in matlab.
When it comes to expanding the package for MS effects and heterokesdasticity, I have no plans for doing it in the moment but, I'll keep it in mind. Cheers.

23 Jun 2008 abdelhakim deboucha  
Please login to add a comment or rating.
Updates
02 Jan 2008

Fixed a bug and changed a few other things

03 Jan 2008

Fixed equation at description

18 Feb 2008

Changed some things to keep it more organized. Nothing special.

03 Apr 2008

Change calculation of starting coefficients by removing the MC procedure and adopting a rolling regression approach. Also fixed a couple of bugs.

09 Sep 2008

Added a few things in pdf document

Tag Activity for this File
Tag Applied By Date/Time
finance Marcelo Perlin 22 Oct 2008 09:41:13
modeling Marcelo Perlin 22 Oct 2008 09:41:13
analysis Marcelo Perlin 22 Oct 2008 09:41:13
kalman filter Marcelo Perlin 22 Oct 2008 09:41:13
statistics Marcelo Perlin 22 Oct 2008 09:41:13
econometrics Marcelo Perlin 22 Oct 2008 09:41:13
state space Marcelo Perlin 22 Oct 2008 09:41:13
probability Cristina McIntire 07 Nov 2008 11:35:44
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com