perfect_foresight: Perfect Foresight / Deterministic Transition Paths

View source: R/perfect-foresight.R

perfect_foresightR Documentation

Perfect Foresight / Deterministic Transition Paths

Description

Simulate deterministic transition paths for DSGE models under perfect foresight. Supports temporary shocks, permanent shocks, and initial condition experiments using the linearized solution.

Usage

perfect_foresight(
  x,
  shocks = NULL,
  initial = NULL,
  horizon = 40L,
  params = NULL,
  shock_sd = NULL,
  in_sd = FALSE
)

Arguments

x

A solved DSGE model object. Can be a dsge_solution (from solve_dsge), dsge_fit (from estimate), or dsge_bayes (from bayes_dsge).

shocks

Deterministic shock specification. Can be:

  • A named list where each element is a numeric vector giving the shock path for that shock variable (e.g., list(u = c(1, 0, 0))). Unnamed periods after the vector ends are treated as zero.

  • A matrix of dimension horizon x n_shocks with column names matching shock names.

Shock values are in units of the shock variable (not standard deviations). If NULL (default), no shocks are applied (useful with initial to study convergence from displaced initial conditions).

Multi-period shock paths. A non-scalar vector specifies a sequence of shocks hitting at successive periods, e.g. shocks = list(u = c(0, 0, 0, 1, 0, 0)) simulates a shock of size 1 arriving at t = 4. Note that the linearized perfect-foresight path uses the recursive policy function x_{t+1} = H x_t + M \varepsilon_{t+1}, so each shock is treated as a period-by-period surprise (agents do not react in advance). For true anticipated / news shocks where agents adjust at t = 1 in expectation of a future shock, use perfect_foresight_nonlinear(): the stacked-time Newton solver respects forward-looking expectations and correctly captures anticipation.

initial

Named numeric vector of initial state deviations from steady state. Names must match state variable names. Unspecified states default to zero. Default is NULL (all states start at steady state).

horizon

Integer. Number of periods to simulate. Default 40.

params

Named numeric vector of parameters. Required only when x is a model object that has not been solved. For solved objects, parameters are extracted automatically.

shock_sd

Named numeric vector of shock standard deviations. Used only when x is a model object. Default NULL.

in_sd

Logical. If TRUE, shock values in shocks are interpreted as multiples of the shock standard deviation. Default FALSE (shocks are in level units).

Details

The deterministic transition path is computed using the linearized state-space representation:

x_{t+1} = H x_t + M \varepsilon_{t+1}

y_t = G x_t

where x_t are state deviations from steady state, y_t are control deviations, and \varepsilon_t are deterministic shocks.

This uses the first-order linearized solution, so results are approximate for large shocks. For small to moderate shocks, the linearized paths are accurate.

Value

An object of class "dsge_perfect_foresight" containing:

states

Matrix (horizon x n_states) of state deviations from SS

controls

Matrix (horizon x n_controls) of control deviations

state_levels

Matrix of state levels (SS + deviation), if SS available

control_levels

Matrix of control levels, if SS available

steady_state

Named numeric vector of steady-state values

shock_path

Matrix (horizon x n_shocks) of applied shocks

initial

Named vector of initial state deviations

horizon

Integer horizon

state_names

Character vector of state names

control_names

Character vector of control names

shock_names

Character vector of shock names

H

State transition matrix used

G

Policy matrix used

M

Shock impact matrix used

Examples

# Simple AR(1) model
mod <- dsge_model(
  obs(p ~ x),
  state(x ~ rho * x),
  start = list(rho = 0.9)
)
sol <- solve_dsge(mod, params = list(rho = 0.9), shock_sd = c(x = 0.01))

# One-time shock at period 1
pf <- perfect_foresight(sol, shocks = list(x = 0.01), horizon = 40)
plot(pf)

# Displaced initial condition
pf2 <- perfect_foresight(sol, initial = c(x = 0.05), horizon = 40)
plot(pf2)

# Anticipated (news) shock: known at t=1, hits at t=5
pf3 <- perfect_foresight(sol,
  shocks  = list(x = c(0, 0, 0, 0, 0.01)),
  horizon = 40)
plot(pf3)


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