2.15.3. Nonlinear filtering

When a DSGE model is solved with a higher-order perturbation (or otherwise has a nonlinear state-space representation), the regime-switching Kalman/Hamilton filter of Filtering and decompositions no longer applies. RISE then uses a sigma-point filter for regime-switching nonlinear state-space models, following [Binning and Maih, 2015].

When the nonlinear filter is used

filter (and, through it, estimate, forecast with conditioning, the historical decomposition, …) picks the algorithm automatically from the solution:

  • solve_order == 1 – the linear regime-switching Kalman/Hamilton filter (a fast constant-parameter variant when there is a single regime, no occasionally-binding constraint, and no real-time information);

  • solve_order >= 2 – a nonlinear sigma-point filter (the default is the switching divided-difference filter).

Nonlinear filtering with real-time information is not supported (RISE raises an error).

Choosing the filter

Three sigma-point filters are available; the divided-difference filter is the default, the other two are selected by passing them as the filtering algorithm via kf_user_algo (they all share the standard filter signature, so they can be plugged in directly):

% default: switching divided-difference filter
[fkst, LogLik] = filter(m);

% switching unscented Kalman filter
[fkst, LogLik] = filter(m, 'kf_user_algo', 'switching_unscented_kalman_filter');

% switching cubature Kalman filter
[fkst, LogLik] = filter(m, 'kf_user_algo', 'switching_cubature_kalman_filter');

The same option can be passed to estimate (it changes which filter computes the likelihood that is maximised).

Options

The filtering options apply equally to the linear and nonlinear cases (see Filtering and decompositions and help dsge/filter); the ones most relevant here:

  • kf_filtering_level [0|1|2|{3}]0 likelihood only; 1 + the filtered (one-step-ahead) series; 2 + the updated series; 3 + the smoothed series.

  • kf_ergodic [{true}|false], kf_init_variance, kf_user_init – how the state and regime probabilities are initialised.

  • kf_presample [{0}|integer] – observations to discard before evaluating the likelihood.

  • kf_householder_chol [{false}|true] – return the Cholesky factor when taking the Householder transformation; primarily used by the divided-difference filter.

User-defined nonlinear filter

A filter of your own can be supplied through kf_user_algo – a function (or function name, or cell {name, extra-args...}) with signature [LogLik, Incr, retcode, Filters] = myFilter(syst, y, U, z, options). If it needs information beyond what RISE passes, prefix the name with * so RISE first calls it as myFilter(modelObject, struct) to let it fetch what it needs. See Extending the DSGE functionalities.

The available sigma-point filters

Switching divided-difference filter

switching_divided_difference_filter - filter for nonlinear regime-swiching models

[loglik,Incr,retcode,Filters]=switching_divided_difference_filter(...
 syst,y,U,z,options)

Args:

  • syst [struct]: structure containing:

    • PAI00 [vector]: initial probability distributions of regimes

    • a [cell]: initial conditions in each regime

    • Qfunc [function handle]: transition matrix generator

    • ff [function handle]: ft=ff(rt,xt,et), where rt is the regime, xt is the vector of state variables and et the vector of shocks

    • P [cell]: initial covariance matrix of the states in each regime

    • H [cell]: Measurement error covariance matrices in each regime

    • SIGeta [cell]: Covariance matrix of structural shocks.

  • y [matrix]: ny x T matrix of data

  • U [[]|matrix]: ndx x T matrix of exogenous data

  • z [function handle|logical|vector]: linear connection of the observables to the state.

  • include_in_likelihood [logical]: selector of increments to include in the likelihood calculation

  • options [struct]: structure with various options

Returns:

  • loglik [scalar]: log likelihood

  • Incr [vector]: increments of elements going into the likelihood

  • retcode [{0}|integer]: flag for problems.

  • Filters [struct]: Filtered, updated and smoothed variables

Note:

Example:

See also

switching_cubature_kalman_filter, switching_unscented_kalman_filter

Switching unscented Kalman filter

switching_unscented_kalman_filter - filter for nonlinear regime-swiching models

[loglik,Incr,retcode,Filters]=switching_unscented_kalman_filter(...
 syst,data_y,U,z,options)

Args:

  • syst [struct]: structure containing:

    • PAI00 [vector]: initial probability distributions of regimes

    • a [cell]: initial conditions in each regime

    • Qfunc [function handle]: transition matrix generator

    • ff [function handle]: ft=ff(rt,xt,et), where rt is the regime, xt is the vector of state variables and et the vector of shocks

    • P [cell]: initial covariance matrix of the states in each regime

    • H [cell]: Measurement error covariance matrices in each regime

    • SIGeta [cell]: Covariance matrix of structural shocks.

  • data_y [matrix]: ny x T matrix of data

  • U [[]|matrix]: ndx x T matrix of exogenous data

  • z [function handle|logical|vector]: linear connection of the observables to the state.

  • include_in_likelihood [logical]: selector of increments to include in the likelihood calculation (temporarily disabled)

  • options [struct]: structure with various options

Returns:

  • loglik [scalar]: log likelihood

  • Incr [vector]: increments of elements going into the likelihood

  • retcode [{0}|integer]: flag for problems.

  • Filters [struct]: Filtered, updated and smoothed variables

Note:

Example:

See also

switching_cubature_kalman_filter, switching_divided_difference_filter

Switching cubature Kalman filter

switching_unscented_kalman_filter - filter for nonlinear regime-swiching models

[loglik,Incr,retcode,Filters]=switching_unscented_kalman_filter(...
 syst,data_y,U,z,options)

Args:

  • syst [struct]: structure containing:

    • PAI00 [vector]: initial probability distributions of regimes

    • a [cell]: initial conditions in each regime

    • Qfunc [function handle]: transition matrix generator

    • ff [function handle]: ft=ff(rt,xt,et), where rt is the regime, xt is the vector of state variables and et the vector of shocks

    • P [cell]: initial covariance matrix of the states in each regime

    • H [cell]: Measurement error covariance matrices in each regime

    • SIGeta [cell]: Covariance matrix of structural shocks.

  • data_y [matrix]: ny x T matrix of data

  • U [[]|matrix]: ndx x T matrix of exogenous data

  • z [function handle|logical|vector]: linear connection of the observables to the state.

  • include_in_likelihood [logical]: selector of increments to include in the likelihood calculation (temporarily disabled)

  • options [struct]: structure with various options

Returns:

  • loglik [scalar]: log likelihood

  • Incr [vector]: increments of elements going into the likelihood

  • retcode [{0}|integer]: flag for problems.

  • Filters [struct]: Filtered, updated and smoothed variables

Note:

Example:

See also

switching_divided_difference_filter, switching_unscented_kalman_filter