Standard Algorithms
Solving the Model
DSGE.gensys — Function.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, looseIf 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] = 1for existenceeu[2] = 1for uniquenesseu[1] = -1for existence only with not-s.c. zeu = [-2, -2]for coincident zeroseu = [-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.
Optimization
DSGE.csminwel — Function.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 functiongrad::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 tofon 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 iterationskwargs...: Other keyword arguments to be passed tofon each
function call
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).
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.
DSGE.hessizero — Method.hessizero(fcn::Function, x::Vector{T};
check_neg_diag::Bool=false,
verbose::Symbol=:none,
distr::Bool=true) where T<:AbstractFloatCompute Hessian of function fcn evaluated at x.
Arguments
check_neg_diag: Throw an error if any negative diagonal elements are detected.verbose: Print verbose outputdistr: Use available parallel workers to increase performance.
Sampling
DSGE.metropolis_hastings — Function.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 objectdata: Data matrix for observablescc0: 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.