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. |