以下のサイトを参考に学習

Estimating time series models by state space methods in Python: Statsmodels

サブクラスでローカルレベルモデル作成

the loglike method returns a single number, and can be evaluated at various sets of parameters

The filter method returns an object from which filter output can be retrieved.

The smooth method returns an object from which smoother output can be retrieved.

the simulation_smoother method returns an object that can be used to simulate state or disturbance vectors via the simulate method.

ARMA(1,1) model

Notice that here the state dimension is 2 but the dimension of the state disturbance is only 1; this is represented in the code by setting K_states=2 but k_posdef=1.

Also demonstrated is the possibility of specifying the Kalman filter initialization in the class construction call with the argument initialization='stationary'.

Maximum Likelihood Estimation

Direct approach

The code below demonstrates how to apply maximum likelihood estimation to the LocalLevel class defined in the previous section for the Nile dataset. In this case, because we have not bothered to define good starting parameters, we use the Nelder-Mead algorithm that can be more robust than BFGS although it may converge more slowly.

Integration with Statsmodels

最尤法でパラメータ求めてカルマンフィルタかけてみる

Parameter transformations