simulate_perfect_foresight: Perfect-foresight simulation of an imported Dynare model

View source: R/dynare-perfect-foresight.R

simulate_perfect_foresightR Documentation

Perfect-foresight simulation of an imported Dynare model

Description

Solves the model's deterministic path exactly as Dynare's perfect_foresight_setup + perfect_foresight_solver (or simul) do, using the file's initval, endval, histval and steady statements and its deterministic shocks (with periods/values), and complementarity conditions from mcp equation tags (Dynare's lmmcp option, e.g. a zero lower bound).

Usage

simulate_perfect_foresight(
  x,
  periods = NULL,
  shocks = NULL,
  params = NULL,
  lmmcp = NULL,
  tol = 1e-10,
  max_iter = 100L
)

Arguments

x

A model imported with read_dynare().

periods

Number of simulation periods. Defaults to the file's perfect_foresight_setup(periods = ), simul(periods = ) or periods statement.

shocks

Optional matrix (or data frame) of exogenous values by period (rows 1, 2, ...) with columns named after shocks, replacing the file's deterministic shocks for those shocks.

params

Optional named parameter values overriding the calibration.

lmmcp

Logical: treat equations tagged mcp as complementarity conditions (Dynare's lmmcp option). Defaults to TRUE when a perfect_foresight_solver command of the file uses lmmcp; without it Dynare ignores the tags.

tol

Convergence tolerance on the largest equation residual.

max_iter

Maximum number of Newton iterations.

Value

An object of class "dsge_dynare_pf": a list with path (a matrix of the endogenous variables, one row per period from the initial condition(s) to the terminal one(s), as Dynare's oo_.endo_simul transposed), exo (the exogenous path, as oo_.exo_simul), periods, initial and terminal (steady states or initial/terminal values), converged, iterations and max_residual.

Examples

m <- read_dynare(text = "
  var c k;
  varexo a;
  parameters alpha beta delta;
  alpha = 0.33; beta = 0.99; delta = 0.025;
  model;
    1/c = beta/c(+1) * (alpha * exp(a(+1)) * k^(alpha - 1) + 1 - delta);
    k = exp(a) * k(-1)^alpha + (1 - delta) * k(-1) - c;
  end;
  initval; a = 0; k = 30; c = 2.3; end;
  steady;
  endval; a = 0.1; end;
  steady;
  perfect_foresight_setup(periods = 100);
  perfect_foresight_solver;
")
pf <- simulate_perfect_foresight(m)
head(pf$path)

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