simulate_occbin: Simulate with Occasionally Binding Constraints

View source: R/occbin.R

simulate_occbinR Documentation

Simulate with Occasionally Binding Constraints

Description

Computes deterministic transition paths under piecewise-linear occasionally binding constraints using an iterative shadow-shock method.

Usage

simulate_occbin(
  x,
  constraints,
  shocks = NULL,
  initial = NULL,
  horizon = 40L,
  max_iter = 100L,
  tol = 1e-08,
  in_sd = FALSE
)

Arguments

x

A solved DSGE model object (dsge_solution, dsge_fit, or dsge_bayes), or a Dynare model imported with read_dynare that has an occbin_constraints block. For an imported model the constraints come from the file and the model is solved with the piecewise-linear regime algorithm of Guerrieri and Iacoviello (2015), as in Dynare's occbin_solver; shocks are raw innovations (default: the file's shocks(surprise) block) treated as surprises, and constraints, initial, tol and in_sd are not used.

constraints

A list of constraints. Each element can be:

  • An obc_constraint object (from obc_constraint())

  • A character string like "r >= 0" (parsed automatically)

shocks

Deterministic shock specification (as in perfect_foresight). Named list or matrix.

initial

Named numeric vector of initial state deviations from steady state. Default NULL (start at SS).

horizon

Integer. Simulation horizon. Default 40.

max_iter

Integer. Maximum OccBin iterations. Default 100.

tol

Numeric. Convergence tolerance for shadow shocks. Default 1e-8.

in_sd

Logical. If TRUE, shock values are in standard deviations. Default FALSE.

Details

The algorithm iteratively:

  1. Simulates the path with current shadow shocks

  2. Identifies periods where constraints are violated

  3. Computes shadow shocks to enforce constraints at binding periods

  4. Removes shadow shocks at non-binding periods

  5. Repeats until the binding regime stabilises

This captures the feedback effect of constraint enforcement on future dynamics through the state transition.

Value

An object of class "dsge_occbin" containing:

states

Matrix of state deviations (constrained path)

controls

Matrix of control deviations (constrained path)

states_unc

Matrix of state deviations (unconstrained path)

controls_unc

Matrix of control deviations (unconstrained path)

binding

Logical matrix (horizon x n_constraints) of binding indicators

shadow_shocks

Matrix of shadow shocks applied

n_iter

Number of OccBin iterations to convergence

converged

Logical: did the algorithm converge?

constraints

List of constraint objects

steady_state

Steady state values if available

horizon

Simulation horizon

state_names

State variable names

control_names

Control variable names

Examples

# Simple NK model with ZLB
nk <- dsge_model(
  obs(pi ~ beta * lead(pi) + kappa * x),
  unobs(x ~ lead(x) - (r - lead(pi) - g)),
  obs(r ~ psi * pi + u),
  state(u ~ rhou * u),
  state(g ~ rhog * g),
  fixed = list(beta = 0.99, kappa = 0.1, psi = 1.5),
  start = list(rhou = 0.5, rhog = 0.5)
)
sol <- solve_dsge(nk, params = list(rhou = 0.5, rhog = 0.5),
                  shock_sd = c(u = 0.5, g = 0.5))
obc <- simulate_occbin(sol,
  constraints = list("r >= 0"),
  shocks = list(g = -0.05),
  horizon = 40)
plot(obc)


dsge documentation built on Sept. 25, 2026, 5:08 p.m.