Algorithms

Standard Algorithms

Solving the Model

DSGE.gensysFunction.
gensys(Γ0, Γ1, c, Ψ, Π)
gensys(Γ0, Γ1, c, Ψ, Π, div)
gensys(F::LinearAlgebra.GeneralizedSchur, c, Ψ, Π)
gensys(F::LinearAlgebra.GeneralizedSchur, c, Ψ, Π, div)

Generate state-space solution to canonical-form DSGE model.

System given as

Γ0*y(t) = Γ1*y(t-1) + c + Ψ*z(t) + Π*η(t),

with z an exogenous variable process and η being endogenously determined one-step-ahead expectational errors.

Returned system is

y(t) = G1*y(t-1) + C + impact*z(t) + ywt*inv(I-fmat*inv(L))*fwt*z(t+1)

Returned values are

G1, C, impact, fmat, fwt, ywt, gev, eu, loose

If z(t) is i.i.d., the last term drops out.

If div is omitted from argument list, a div>1 is calculated.

Return codes

  • eu[1] = 1 for existence
  • eu[2] = 1 for uniqueness
  • eu[1] = -1 for existence only with not-s.c. z
  • eu = [-2, -2] for coincident zeros
  • eu = [-3, -3] if a LAPACKException is thrown while computing the Schur decomposition

Notes

We constrain Julia to use the complex version of the schurfact routine regardless of the types of Γ0 and Γ1, to match the behavior of Matlab. Matlab always uses the complex version of the Schur decomposition, even if the inputs are real numbers.

source

Optimization

DSGE.csminwelFunction.
csminwel(fcn::Function, grad::Function, x0::Vector, H0::Matrix=1e-5.*eye(length(x0)), args...;
         xtol::Real=1e-32, ftol::Float64=1e-14, grtol::Real=1e-8, iterations::Int=1000,
         store_trace::Bool = false, show_trace::Bool = false, extended_trace::Bool = false,
         verbose::Symbol = :none, rng::AbstractRNG = MersenneTwister(0), kwargs...)

Minimizes fcn using the csminwel algorithm.

Arguments

  • fcn::Function : The objective function
  • grad::Function : The gradient of the objective function. This argument can be omitted if

an analytical gradient is not available, which will cause a numerical gradient to be calculated.

  • x0::Vector: The starting guess for the optimizer

Optional Arguments

  • H0::Matrix: An initial guess for the Hessian matrix – must be

positive definite. If none is given, then a scaled down identity matrix is used.

  • args...: Other positional arguments to be passed to f on each

function call

Keyword Arguments

  • ftol::{T<:Real}=1e-14: Threshold for convergence in terms of change

in function value across iterations.

  • iterations::Int=100: Maximum number of iterations
  • kwargs...: Other keyword arguments to be passed to f on each

function call

source
DSGE.optimize!Function.
optimize!(m::AbstractModel, data::Matrix;
          method::Symbol       = :csminwel,
          xtol::Real           = 1e-32,  # default from Optim.jl
          ftol::Float64        = 1e-14,  # Default from csminwel
          grtol::Real          = 1e-8,   # default from Optim.jl
          iterations::Int      = 1000,
          store_trace::Bool    = false,
          show_trace::Bool     = false,
          extended_trace::Bool = false,
          verbose::Symbol      = :none)

Wrapper function to send a model to csminwel (or another optimization routine).

source

Hessian Approximation

DSGE.hessian!Method.
hessian!(m::AbstractModel, x::Vector{T}, data::AbstractArray;
         verbose::Symbol = :none) where {T<:AbstractFloat}

Compute Hessian of DSGE posterior function evaluated at x.

source
DSGE.hessizeroMethod.
hessizero(fcn::Function, x::Vector{T};
          check_neg_diag::Bool=false,
          verbose::Symbol=:none,
          distr::Bool=true) where T<:AbstractFloat

Compute Hessian of function fcn evaluated at x.

Arguments

  • check_neg_diag: Throw an error if any negative diagonal elements are detected.
  • verbose: Print verbose output
  • distr: Use available parallel workers to increase performance.
source

Sampling

metropolis_hastings(propdist::Distribution, m::AbstractModel,
    data::Matrix{T}, cc0::T, cc::T; verbose::Symbol = :low) where {T<:AbstractFloat}

Implements the Metropolis-Hastings MCMC algorithm for sampling from the posterior distribution of the parameters.

Arguments

  • propdist: The proposal distribution that Metropolis-Hastings begins sampling from.
  • m: The model object
  • data: Data matrix for observables
  • cc0: Jump size for initializing Metropolis-Hastings.
  • cc: Jump size for the rest of Metropolis-Hastings.

Optional Arguments

  • verbose: The desired frequency of function progress messages printed to standard out. One of:
   - `:none`: No status updates will be reported.
   - `:low`: Status updates provided at each block.
   - `:high`: Status updates provided at each draw.
source

State Space Filters and Smoothers

See StateSpaceRoutines.jl.