4.15. Occasionally binding constraints (OccBin)¶
Dynare allows simulating models with up to two occasionally-binding constraints by relying on a piecewise linear solution as in Guerrieri and Iacoviello (2015). It also allows estimating such models employing either the inversion filter of Cuba-Borda et al. (2019) or the piecewise Kalman filter of Giovannini et al. (2021). To trigger computations involving occasionally-binding constraints requires

defining and naming the occasionally-binding constraints using an occbin_constraints block
specifying the model equations for the respective regimes in the model block using appropriate equation tags.
potentially specifying a sequence of surprise shocks using a shocks(surprise) block
setting up OccBin simulations or estimation with occbin_setup
triggering a simulation with occbin_solver or running estimation or calib_smoother.
All of these elements are discussed in the following.

Block: occbin_constraints ;

The occbin_constraints block specifies the occasionally-binding constraints. It contains one or two of the following lines:

name 'STRING'; bind EXPRESSION; [relax EXPRESSION;] [error_bind EXPRESSION;] [error_relax EXPRESSION;]

STRING is the name of constraint that is used to reference the constraint in relax / bind equation tags to identify the respective regime (see below). The bind expression is mandatory and defines a logical condition that is evaluated in the baseline/steady state regime to check whether the specified constraint becomes binding. In contrast, the relax expression is optional and specifies a logical condition that is evaluated in the binding regime to check whether the regime returns to the baseline/steady state regime. If not specified, Dynare will simply check in the binding regime whether the bind expression evaluates to false. However, there are cases where the bind expression cannot be evaluated in the binding regime(s), because the variables involved are constant by definition so that e.g. the value of the Lagrange multiplier on the complementary slackness condition needs to be checked. In these cases, it is necessary to provide an explicit condition that can be evaluated in the binding regime that allows to check whether it should be left.

Note that the baseline regime denotes the steady state of the model where the economy will settle in the long-run without shocks. For that matter, it may be one where e.g. a borrowing constraint is binding. In that type of setup, the bind condition is used to specify the condition when this borrowing constraint becomes non-binding so that the alternative regime is entered.

Three things are important to keep in mind when specifying the expressions. First, feasible expressions may only contain contemporaneous endogenous variables. If you want to include leads/lags or exogenous variables, you need to define an auxiliary variable. Second, Dynare will at the current stage not linearly approximate the entered expressions. Because OccBin will work with a linearized model, consistency will often require the user to enter a linearized constraint. Otherwise, the condition employed for checking constraint violations may differ from the one employed within model simulations based on the piecewise-linear model solution. Third, in contrast to the original OccBin replication codes, the variables used in expressions are not automatically demeaned, i.e. they refer to the levels, not deviations from the steady state. To access the steady state level of a variable, the STEADY_STATE() operator can be used.

Finally, it's worth keeping in mind that for each simulation period, OccBin will check the respective conditions for whether the current regime should be left. Small numerical differences from the cutoff point for a regime can sometimes lead to oscillations between regimes and cause a spurious periodic solution. Such cases may be prevented by introducing a small buffer between the two regimes, e.g.

occbin_constraints;
name 'ELB'; bind inom <= iss-1e-8; relax inom > iss+1e-8;
end;
The error_bind and error_relax options are optional and allow specifying numerical criteria for the size of the respective constraint violations employed in numerical routines. By default, Dynare will simply use the absolute value of the bind and relax inequalities. But occasionally, user-specified expressions perform better.

Example

occbin_constraints;
    name 'IRR'; bind log_Invest-log(steady_state(Invest))<log(phi); relax Lambda<0;
    name 'INEG'; bind log_Invest-log(steady_state(Invest))<0;
end;
IRR is a constraint for irreversible investment that becomes binding if investment drops below its steady state by more than 0.025 percent in the non-binding regime. The constraint will be relaxed whenever the associated Lagrange multiplier Lambda in the binding regime becomes negative. Note that the constraint here takes on a linear form to be consistent with a piecewise linear model solution

The specification of the model equations belonging to the respective regimes is done in the model block, with equation tags indicating to which regime a particular equation belongs. All equations that differ across regimes must have a name tag attached to them that allows uniquely identifying different versions of the same equation. The name of the constraints specified is then used in conjunction with a bind or relax tag to indicate to which regime a particular equation belongs. In case of more than one occasionally-binding constraint, if an equation belongs to several regimes (e.g. both constraints binding), the constraint name tags must be separated by a comma. If only one name tag is present, the respective equation is assumed to hold for both states of the other constraint.

Example

[name='investment',bind='IRR,INEG']
(log_Invest - log(phi*steady_state(Invest))) = 0;
[name='investment',relax='IRR']
Lambda=0;
[name='investment',bind='IRR',relax='INEG']
(log_Invest - log(phi*steady_state(Invest))) = 0;
The three entered equations for the investment condition define the model equation for all four possible combinations of the two constraints. The first equation defines the model equation in the regime where both the IRR and INEG constraint are binding. The second equation defines the model equation for the regimes where the IRR constraint is non-binding, regardless of whether the INEG constraint is binding or not. Finally, the last equation defines the model equation for the final regime where the IRR constraint is binding, but the INEG one is not.

Block: shocks(surprise) ;
Block: shocks(surprise,overwrite);

The shocks(surprise) block allows specifying a sequence of temporary changes in the value of exogenous variables that in each period come as a surprise to agents, i.e. are not anticipated. Note that to actually use the specified shocks in subsequent commands like occbin_solver, the block needs to be followed by a call to occbin_setup.

The block mirrors the perfect foresight syntax in that it should contain one or more occurrences of the following group of three lines:

var VARIABLE_NAME;
periods INTEGER[:INTEGER] [[,] INTEGER[:INTEGER]]...;
values DOUBLE | (EXPRESSION)  [[,] DOUBLE | (EXPRESSION) ]...;
Example (with vector values and overwrite option)

shockssequence = randn(100,1)*0.02;

shocks(surprise,overwrite);
var epsilon;
periods 1:100;
values (shockssequence);
end;
Command: occbin_setup ;
Command: occbin_setup(OPTIONS...);

Prepares a simulation with occasionally binding constraints. This command will also translate the contents of a shocks(surprise) block for use in subsequent commands.

In order to conduct estimation with occasionally binding constraints, it needs to be prefaced by a call to occbin_setup to trigger the use of either the inversion filter or the piecewise Kalman filter (default). An issue that can arise in the context of estimation is a structural shock dropping out of the model in a particular regime. For example, at the zero lower bound on interest rates, the monetary policy shock in the Taylor rule will not appear anymore. This may create a problem if there are then more observables than shocks. The way to handle this issue depends on the type of filter used. The first step is to set the data points for the zero interest rate period to NaN. For the piecewise Kalman filter, the standard deviation of the associated shock needs to be set to 0 for the corresponding periods using the heteroskedastic_shocks block. This avoids stochastic singularity. However, this approach does not work for the inversion filter as the heteroskedastic_shocks block does not do anything here. For the inversion filter, as many shocks as observables are required at each point in time. Dynare assumes a one-to-one mapping between the declared shocks in varexo and declared observables in varobs. For example, if the second declared observable is NaN in a given period, Dynare will drop the second declared shock.

Warning
If there are missing values, it is imperative for the inversion filter that the declaration order of shocks and observables is conformable. Sticking with our example, if the nominal interest is the second varobs and is set to NaN, the inversion filter will drop the second declared shock. If that second declared shock is, e.g., a TFP shock, it will be dropped instead of the intended monetary policy shock.
Note that models with unit roots will require the user to specify the diffuse_filter option as otherwise Blanchard-Kahn errors will be triggered. For the piecewise Kalman filter, the initialization steps in the diffuse filter will always rely on the model solved for the baseline regime, without checking whether this is the actual regime in the first period(s).

Example

occbin_setup(likelihood_inversion_filter,smoother_inversion_filter);
estimation(smoother,heteroskedastic_filter,...);
The above piece of code sets up an estimation employing the inversion filter for both the likelihood evaluation and the smoother, while also accounting for heteroskedastic_shocks using the heteroskedastic_filter option.

Be aware that OccBin has largely command-specific options, i.e. there are separate options to control the behavior of OccBin when called by the smoother or when computing the likelihood. These latter commands will not inherit the options potentially previously set for simulations.

Options

Simulation options

simul_periods = INTEGER
Number of periods of the simulation. Default: 100.
simul_maxit = INTEGER
Maximum number of iterations when trying to find the regimes of the piecewise solution. Default: 30.
simul_check_ahead_periods = INTEGER
Number of periods for which to check ahead for return to the baseline regime. This number should be chosen large enough, because OccBin requires the simulation to return to the baseline regime at the end of time. Default: 200.
simul_reset_check_ahead_periods
Allows to reset simul_check_ahead_periods to its specified value at the beginning of each simulation period. Otherwise, the original value may permanently increase endogenously at some point due to regimes that last very long in expectations. This may considerably slow down convergence in subsequent periods. Default: not enabled.
simul_reset_regime_in_new_period
simul_reset_regime_in_new_period = BOOLEAN
Disable the default feature that the guess regime in period $t+1$ equals the 1-step-ahead expected regime in period $t$. This can improve convergence when the expected regime is inconsistent with the regime triggered by new shocks in $t+1$. Default: not enabled.
simul_max_check_ahead_periods = INTEGER
If set to a finite number, it enforces the OccBin algorithm to check ahead only for the maximum number of periods (i.e. when we want agents to be myopic beyond some future period) instead of potentially endogenously increasing simul_check_ahead_periods ever further. Default: Inf.
simul_curb_retrench
Instead of basing the initial regime guess for the current iteration on the last iteration, update the guess only one period at a time. This will slow down the iterations, but may lead to more robust convergence behavior. Default: not enabled.
simul_periodic_solution
Accept a periodic solution where the solution alternates between two sets of results across iterations, i.e. is not found to be unique. This is sometimes caused by spurious numerical errors that lead to oscillations between regiems and may be prevented by allowing for a small buffer in regime transitions. Default: not enabled.
simul_periodic_solution_threshold = INTEGER
Maximum difference allowed between regimes in the periodic loop. A value of 1 means the duration of a constrained regime can change by at most 1 period; otherwise, the periodic solution is rejected. Default: 1.
simul_periodic_solution_strict
simul_periodic_solution_strict = BOOLEAN
Enforce strict acceptance of a periodic solution consistent with simul_periodic_solution_threshold. When disabled, a periodic solution is accepted if at least one forward path of regimes within the periodic loop does not violate constraints in expectation. Default: true.
simul_debug
Provide additional debugging information during solving. Default: not enabled.
Smoother options

smoother_periods = INTEGER
Number of periods employed during the simulation when called by the smoother (equivalent of simul_periods). Default: 100.
smoother_maxit = INTEGER
Maximum number of iterations employed during the simulation when called by the smoother (equivalent of simul_maxit). Default: 30.
smoother_check_ahead_periods = INTEGER
Number of periods for which to check ahead for return to the baseline regime during the simulation when called by the smoother (equivalent of simul_check_ahead_periods). Default: 200.
smoother_max_check_ahead_periods = INTEGER
If set to a finite number, it enforces the OccBin algorithm to check ahead only for the maximum number of periods (i.e. when we want agents to be myopic beyond some future period) instead of potentially endogenously increasing smoother_check_ahead_periods ever further. Equivalent of simul_max_check_ahead_periods. Default: Inf.
smoother_curb_retrench
Have the smoother invoke the simul_curb_retrench option during simulations. Default: not enabled.
smoother_periodic_solution
Accept periodic solution where solution alternates between two sets of results (equivalent of simul_periodic_solution). Default: not enabled.
smoother_max_check_ahead_periods = INTEGER
If set to a finite number, it enforces the OccBin algorithm to check ahead only for the maximum number of periods (i.e. when we want agents to be myopic beyond some future period) instead of potentially endogenously increasing likelihood_check_ahead_periods ever further. Equivalent of simul_max_check_ahead_periods. Default: Inf.
smoother_inversion_filter
Employ the inversion filter of Cuba-Borda et al. (2019) when running the smoother. The underlying assumption is that the system starts at the steady state. In this case, the inversion filter will provide the required smoother output. Default: not enabled.
smoother_piecewise_kalman_filter
Employ the piecewise Kalman filter of Giovannini et al. (2021) when running the smoother. Default: enabled.
smoother_plot
Plot linear vs piecewise linear smoothed shock estimates. Default: enabled.
smoother_first_period_occbin_update = INTEGER
First period in which PKF filter steps are used when running the smoother. If greater than 1, linear Kalman filter steps are used before this period. Default: 1.
smoother_max_number_of_iterations = INTEGER
Maximum number of smoother iterations that attempt to find a consistent sequence of shocks and regimes. Default: 10.
Likelihood computation options

likelihood_periods = INTEGER
Number of periods employed during the simulation when computing the likelihood (equivalent of simul_periods). Default: 100.
likelihood_maxit = INTEGER
Maximum number of iterations employed during the simulation when computing the likelihood (equivalent of simul_maxit). Default: 30.
likelihood_check_ahead_periods = INTEGER
Number of periods for which to check ahead for return to the baseline regime during the simulation when computing the likelihood (equivalent of simul_check_ahead_periods). Default: 200.
likelihood_curb_retrench
Have the likelihood computation invoke the simul_curb_retrench option during simulations. Default: not enabled.
likelihood_periodic_solution
Accept periodic solution where solution alternates between two sets of results (equivalent of simul_periodic_solution). Default: not enabled.
likelihood_inversion_filter
Employ the inversion filter of Cuba-Borda et al. (2019) when estimating the model. Default: not enabled.
likelihood_piecewise_kalman_filter
Employ the piecewise Kalman filter of Giovannini et al. (2021) when estimating the model. Note that this filter is incompatible with univariate Kalman filters, i.e. kalman_algo=2,4. Default: enabled.
likelihood_max_kalman_iterations
Maximum number of iterations of the outer loop for the piecewise Kalman filter. Default: 10.
Piecewise Kalman filter and particle filter options

filter_use_relaxation
Triggers relaxation within the guess and verify algorithm used in the update step of the piecewise Kalman filter. When old and new guess regime differ to much, use a new guess closer to the previous guess. In case of multiple solutions, tends to provide an occasionally binding regime with a shorter duration (typically preferable). Specifying this option may slow down convergence. Default: not enabled.
filter_particle_draw_states_from_empirical_density
filter_particle_draw_states_from_empirical_density = BOOLEAN
When using the particle filter, draw state particles from the empirical density of past draws. Default: true.
filter_particle_state_importance_sampling_pkf_init
filter_particle_state_importance_sampling_pkf_init = BOOLEAN
Use the piecewise Kalman filter proposal density in the particle filter's state-importance-sampling step. Default: enabled.
filter_particle_state_importance_sampling_logpost_crit_threshold = DOUBLE
Log-posterior critical threshold between PKF and PPF data density estimates above which additional robustness checks for PPF filter step are triggered.

Default: 5.
filter_particle_state_importance_sampling_slice_override_iteration = INTEGER
Number of importance sampling iterations (sequential Monte Carlo iterations) before resorting to slice sampling for state update.

Default: 100.
filter_particle_state_importance_sampling_slice_burnin = INTEGER
Burn-in iterations for slice sampling in state importance sampling. Default: 10.
filter_particle_initial_state_ergodic_simul
filter_particle_initial_state_ergodic_simul = BOOLEAN
Draw initial states from an ergodic simulation when initializing the particle filter. Default: false.
filter_particle_diagnostics
filter_particle_diagnostics = BOOLEAN
Trigger diagnostic tests/plots for the particle filter state update. Default: false.
filter_particle_diagnostics_graph_periods = INTEGER_VECTOR
Select specific critical periods for which to run the diagnostic tests. Default: empty.
filter_particle_diagnostics_nograph
filter_particle_diagnostics_nograph = BOOLEAN
Disable diagnostic graphs. Default: true.
filter_particle_number_of_particles  = INTEGER
Number of particles used by the particle filter. Default: 127.
filter_particle_number_of_shocks_per_particle = INTEGER
Number of shock draws per particle. Default: 1.
filter_particle_state_draws   = NUMERICAL_VECTOR
Provide a fixed set of state draws for particle filtering. Default: empty (draw internally).
particle_filtering
particle_filtering = BOOLEAN
Activate the particle filter branch within OccBin filtering. Default: false.
filter_particle_use_pkf_updated_state_threshold = INTEGER
Threshold controlling when to re-use PKF-updated states in the particle filter. Default: 1.
filter_init_periods_using_particles
filter_init_periods_using_particles = BOOLEAN
This triggers particle filtering only for initial periods, in an otherwise standard PKF likelihood evaluation. Since state uncertainty is larger in first periods, this may be enough to robustify estimates when constraints are binding at the beginning of the sample. The algorithm automatically swithes to PKF (no particles) once all constraints become slack for the first time. Default: false.
Posterior importance sampling

posterior_importance_sampling
posterior_importance_sampling = BOOLEAN
Enables posterior importance sampling of estimated parameters/shocks starting from a previous MCMC estimation. For example after MCMC estimation with linear model, re-sample posterior draws using the piecewise Kalman filter (pkf) or the piecewise particle filter (ppf). Or, after estimating with piecewise Kalman filter, run this with piecewise particle filter. Given that the piecewise Kalman filter is more computationally intensive than the standard Kalman filter and that the piecewise particle filter more costly than the piecewise Kalman filter, this allows for faster robustness checks regarding the possible bias of the estimation when using the original (KF or PKF) filter. This requires mh results from previous estimation to be present in metropolis folder

Default: false.
posterior_importance_sampling_filter = QUOTED_STRING
Sets the new filter to be used for importance sampling. Values are:

'pkf'

Uses the piecewise Kalman filter.

'ppf'

Uses the piecewise particle filter.

Default: 'pkf'.
posterior_importance_sampling_orig_filter = QUOTED_STRING
Indicates the filter used for original posterior draws. Values are:

'linear'

'pkf'

Default: 'linear'.
posterior_importance_sampling_sub_draws = INTEGER
Sets the number of sub-draws to be used for evaluating posterior kernel with new filter and subsequent importance sampling. Default: the one specified with sub_draws.
posterior_importance_sampling_orig_dname = FILENAME
Sets the results folder if it is not the default one. Default: current dirname.
posterior_importance_sampling_orig_fname = FILENAME
Sets the name of the original model, in case it is different from current one. Default: current FNAME.
Output

The paths for the exogenous variables are stored into options_.occbin.simul.SHOCKS.

Command: occbin_solver ;
Command: occbin_solver(OPTIONS...);

Computes a simulation with occasionally-binding constraints based on a piecewise-linear solution.

Note that occbin_setup must be called before this command in order for the simulation to take into account previous shocks(surprise) blocks.

Options

simul_periods = INTEGER
See simul_periods.
simul_maxit = INTEGER
See simul_maxit.
simul_check_ahead_periods = INTEGER
See simul_check_ahead_periods.
simul_reset_check_ahead_periods
See simul_reset_check_ahead_periods.
simul_max_check_ahead_periods
See simul_max_check_ahead_periods.
simul_curb_retrench
See simul_curb_retrench.
simul_debug
See simul_debug.
Output

The command outputs various objects into oo_.occbin.
MATLAB/Octave variable: oo_.occbin.simul.piecewise

Matrix storing the simulations based on the piecewise-linear solution. The variables are arranged by column, in order of declaration (as in M_.endo_names), while the the rows correspond to the simul_periods.
MATLAB/Octave variable: oo_.occbin.simul.linear

Matrix storing the simulations based on the linear solution, i.e. ignoring the occasionally binding constraint(s). The variables are arranged column by column, in order of declaration (as in M_.endo_names), while the the rows correspond to the simul_periods.
MATLAB/Octave variable: oo_.occbin.simul.shocks_sequence

Matrix storing the shock sequence employed during the simulation. The shocks are arranged column by column, with their order in M_.exo_names stored in oo_.occbin.exo_pos. The the rows correspond to the number of shock periods specified in a shocks(surprise) block, which may be smaller than simul_periods.
MATLAB/Octave variable: oo_.occbin.simul.regime_history

Structure storing information on the regime history, conditional on the shock that happened in the respective period (stored along the rows). type is equal to either smoother or simul, depending on whether the output comes from a run of simulations or the smoother. The subfield regime contains a vector storing the regime state, while the the subfield regimestart indicates the expected start of the respective regime state. For example, if row 40 contains [1,0] for regime2 and [1,6] for regimestart2, it indicates that - after the shock in period 40 has occurred - the second constraint became binding (1) and is expected to revert to non-binding (0) after six periods including the current one, i.e. period 45.
MATLAB/Octave variable: oo_.occbin.simul.ys

Vector of steady state values
Command: occbin_graph [VARIABLE_NAME...];
Command: occbin_graph(OPTIONS...) [VARIABLE_NAME...];

Plots a graph comparing the simulation results of the piecewise-linear solution with the occasionally binding contraints to the linear solution ignoring the constraint.

Options

noconstant
Omit the steady state in the graphs.
Command: occbin_write_regimes ;
Command: occbin_write_regimes(OPTIONS...);

Write the information on the regime history stored in oo_.occbin.simul.regime_history or oo_.occbin.smoother.regime_history into an Excel file stored in the FILENAME/Output folder.

Options

periods = INTEGER
Number of periods for which to write the expected regime durations. Default: write all available periods.
filename = FILENAME
Name of the Excel file to write. Default: FILENAME_occbin_regimes.
simul
Selects the regime history from the last run of simulations. Default: enabled.
smoother
Selects the regime history from the last run of the smoother. Default: use simul.