perfect_foresight_nonlinear: Perfect Foresight for Nonlinear DSGE Models

View source: R/perfect-foresight.R

perfect_foresight_nonlinearR Documentation

Perfect Foresight for Nonlinear DSGE Models

Description

Computes deterministic perfect foresight transition paths for nonlinear DSGE models using a stacked-time Newton solver (Juillard et al., 1998). Unlike the linearized perfect_foresight(), this function solves the full nonlinear equilibrium conditions simultaneously over the entire horizon, giving exact (up to Newton tolerance) paths even for large shocks.

Usage

perfect_foresight_nonlinear(
  model,
  params,
  shock_sd,
  shocks = NULL,
  initial = NULL,
  horizon = 40L,
  tol = 1e-08,
  max_iter = 50L,
  verbose = FALSE
)

Arguments

model

A dsgenl_model object.

params

Named numeric vector or list of free parameter values.

shock_sd

Named numeric vector of shock standard deviations with names matching model$variables$exo_state. Used only for the linearized warm-start step; the nonlinear solver uses shocks directly.

shocks

Shock path specification (same interface as perfect_foresight): a named list where each element is a numeric vector giving the shock values for that exogenous state over time, or a matrix of dimension horizon x n_exo with column names matching exogenous state names. Unspecified periods are zero.

Supports anticipated (news) shocks: because the nonlinear system is solved simultaneously over the whole horizon under perfect foresight, agents see the entire future shock path at t = 1 and react in advance. Place the shock value at the desired arrival period in the vector (e.g. list(Z = c(0, 0, 0, 0.1)) for a TFP shock announced at t=1 but arriving at t=4).

initial

Named numeric vector of initial DEVIATIONS from steady state for state variables. Defaults to zero (all states start at SS).

horizon

Integer. Number of periods to simulate. Default 40.

tol

Convergence tolerance (maximum absolute equation residual). Default 1e-8.

max_iter

Maximum Newton iterations. Default 50.

verbose

Logical. If TRUE, prints iteration progress. Default FALSE.

Details

The algorithm (Juillard et al., 1998) stacks the n \times T nonlinear equilibrium conditions into a single system and solves it by Newton's method. The Jacobian is block-bidiagonal (each period's equations depend only on the current and next-period variables) and is assembled numerically using forward finite differences. The block structure is exploited via block back-substitution, giving O(T n^3) cost per Newton step. Armijo backtracking stabilises convergence for large initial steps.

The initial state x_1 is pinned to steady_state + initial via equality constraints that replace the state equations at t=1. For t = T+1 the terminal condition v_{T+1} = \bar{v} (steady state) is imposed. The solver is warm-started from the linearized perfect_foresight() path, which is exact for small shocks and provides a good initial guess for large ones.

Value

A "dsge_perfect_foresight" object with the same fields as perfect_foresight, so all plot, print, and summary methods apply unchanged. Three extra fields are appended:

nonlinear

TRUE

newton_iters

Number of Newton iterations taken

converged

Logical; TRUE if max|R| < tol

References

Juillard, M., Laxton, D., McAdam, P. and Pioro, H. (1998). An algorithm competition: First-order iterations versus Newton-based techniques. Journal of Economic Dynamics and Control, 22, 1291–1318.

See Also

perfect_foresight for linearized paths, dsgenl_model for nonlinear model specification.

Examples

rbc <- dsgenl_model(
  "1/C = beta / C(+1) * (alpha * exp(Z) * K^(alpha-1) + 1 - delta)",
  "K(+1) = exp(Z) * K^alpha - C + (1 - delta) * K",
  "Z(+1) = rho * Z",
  observed = "C", endo_state = "K", exo_state = "Z",
  fixed = list(alpha = 0.33, beta = 0.99, delta = 0.025),
  start = list(rho = 0.9)
)
pf <- perfect_foresight_nonlinear(
  rbc, params = c(rho = 0.9), shock_sd = c(Z = 0.01),
  shocks = list(Z = 0.1), horizon = 40
)
plot(pf)


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