Diagnostics
To assess the quality of a risk-adjusted linearization, diagnostic tests should be run. In particular, as Lopez et al. (2018) discuss at length, whenever forward difference equations arise (e.g. the equation for the log wealth-consumption ratio in our implementation of Wachter (2013)), there are infinitely many ways to write the expectational equations. Assuming computational costs do not become too significant, users should add as many expectational equations as needed to maximize the accuracy of the risk-adjusted linearization.
The best accuracy test is comparing the risk-adjusted linearization to the true nonlinear solution, but this test requires this solution to be available. In many cases (e.g. high dimensions), neither analytical nor numerical methods can deliver the true solution. To address this problem, economists have developed a variety of accuracy tests that only involve the chosen approximation method and quadrature.
The most popular diagnostics revolve around the Euler equation. RiskAdjustedLinearizations.jl implements wrapper functions for performing two of these Euler equation diagnostics. The first is the so-called "Euler equation errors" test proposed by Judd (1992). The second is the so-called "dynamic Euler equation errors" test proposed by Den Haan (2009). We defer the reader to these articles for explanations of the theory behind these tests. A good set of slides on accuracy tests are these ones by Den Haan.
The wrapper functions in RiskAdjustedLinearizations.jl are euler_equation_error
and dynamic_euler_equation_error
. See the Coeurdacier, Rey, and Winant (2011) script for an example of how to use these functions.
RiskAdjustedLinearizations.euler_equation_error
ā Functioneuler_equation_error(m, cā, logSDFxR, š¼_quadrature, zā = m.z;
c_init = NaN, return_soln = false, kwargs...)
euler_equation_error(m, cā, logSDFxR, š¼_quadrature, shock_matrix, zā = m.z;
c_init = NaN, summary_statistic = x -> norm(x, Inf), burnin = 0,
return_soln = false, kwargs...)
calculates standard Euler equation errors, as recommended by Judd (1992). The first method calculates the error at some state zā
, which defaults to the stochastic steady state. The second method simulates the state vector from an initial state zā
(defaults to stochastic steady state) given a sequence of drawn shocks, evaluates the Euler equation errors, and returns some summary statistic of the errors specified by the keyword summary_statistic
.
The Euler equation is
where $m_{t + 1} = \log(M_{t + 1})$ is the log stochastic discount factor and $r_{t + 1} = \log(R_{t + 1})$ is the risk free rate.
Inputs
m::RiskAdjustedLinearization
: A solved instance of a risk-adjusted linearizationcā::Function
: a function of(m, zā)
that calculates consumption at statezā
, given the state-space representation implied bym
.logSDFxR::Function
: aFunction
evaluating $m_{t + 1} + r_{t + 1}$. TheFunction
must take as input(m, zā, Īµāāā, c)
, wherem
is aRiskAdjustedLinearization
,zā
is a state vector at which to evaluate,Īµāāā
is a draw from the distribution of exogenous shocks, andc
is a guess for consumption atzā
implied by the conditional expectation in the Euler equation when calculated with a quadrature rule. Note thatc
can be either the consumption level or some transformation (e.g. log consumption), but the user should be consistent in the definition of thecā
function with the guessc
, i.e. both should return the same transformation of consumption (e.g. both should return the level).š¼_quadrature::Function
: a quadrature rule whose single input is aFunction
with a single input, which is a shockĪµāāā
.zā::AbstractVector
: a state at which to evaluate the Euler equation errorshock_matrix::Abstractmatrix
: aNĪµ Ć T
matrix of shocks drawn from the distribution of exogenous shocks.
Keywords
c_init::Number
: an initial guess to be used when solving the "true" consumption policy using quadrature. The default is the consumption policy according to theRiskAdjustedLinearization
summary_statistic::Function
: aFunction
used to compute a summary statistic from the ergodic set of Euler equation errors. The default is the maximum absolute error.burnin::Int
: number of periods to drop as burn-inreturn_soln::Bool
: if true, return the solution to the nonlinear equation isntead of the errorkwargs
: Any keyword arguments fornlsolve
can be passed, too, e.g.ftol
orautodiff
sincenlsolve
is used to calculate the "true" consumption policy.
RiskAdjustedLinearizations.dynamic_euler_equation_error
ā Functiondynamic_euler_equation_error(m, cā, logSDFxR, š¼_quadrature, endo_states, n_aug,
shock_matrix, zā = m.z; c_init = NaN, summary_statistic = x -> norm(x, Inf),
burnin = 0, return_soln = false, kwargs...)
calculates dynamic Euler equation errors, as proposed in Den Haan (2009). The Euler equation is
$math \begin{aligned} 0 = \log \mathbb{E}_t \exp(m_{t + 1} + r_{t + 1}) = \log \mathbb{E}_t[M_{t + 1} R_{t + 1}], \end{aligned}$
where $m_{t + 1} = \log(M_{t + 1})$ is the log stochastic discount factor and $r_{t + 1} = \log(R_{t + 1})$ is the risk free rate.
The dynamic errors are computed according the following algorithm.
- Simulate according to the risk-adjusted linearization time series for the state variables
- Using the time series from 1, compute time series for consumption and some state variable (usually capital) that can ensure budget constraints hold and markets clear when computing consumption by applying quadrature.
- Generate a second "implied" time series for consumption and the "capital" state variable, starting from the same initial state as 2. Repeat the following steps at each time period. (i) Compute the conditional expectation in the Euler equation using quadrature to obtain implied consumption. (ii) Use budget constraint/market-clearing to compute implied capital.
By default, dynamic_euler_equation_error
returns some summary statistic of the errors specified by the keyword summary_statistic
.
Inputs
m::RiskAdjustedLinearization
: A solved instance of a risk-adjusted linearizationcā::Function
: a function of(m, zā)
that calculates consumption at statezā
, given the state-space representation implied bym
.logSDFxR::Function
: aFunction
evaluating $m_{t + 1} + r_{t + 1}$. TheFunction
must take as input(m, zā, Īµāāā, cā)
, wherem
is aRiskAdjustedLinearization
,zā
is a state vector at which to evaluate,Īµāāā
is a draw from the distribution of exogenous shocks, andcā
is the a guess for consumption atzā
implied by the conditional expectation in the Euler equation when calculated with a quadrature rule.š¼_quadrature::Function
: a quadrature rule whose single input is aFunction
with a single input, which is a shockĪµāāā
.endo_states::Function
: augments the state variables in the risk-adjusted linearization, usually with one additional variable, which represents capital or assets.n_aug::Int
: number of extra state variables added byendo_states
(usually 1).zā::AbstractVector
: a state at which to evaluate the Euler equation errorshock_matrix::Abstractmatrix
: aNĪµ Ć T
matrix of shocks drawn from the distribution of exogenous shocks.
Keywords
c_init::Number
: an initial guess to be used when solving the true consumption policy using quadrature. The default is the consumption policy according to theRiskAdjustedLinearization
summary_statistic::Function
: aFunction
used to compute a summary statistic from the ergodic set of Euler equation errors. The default is the maximum absolute error.burnin::Int
: number of periods to drop as burn-inkwargs
: Any keyword arguments fornlsolve
can be passed, too, e.g.ftol
orautodiff
sincenlsolve
is used to calculate the "true" consumption policy.
To make running diagnostics even easier, we also provide user-friendly functions for calculating Gauss-Hermite quadrature when shocks are Gaussian. Extensions of Gauss-Hermite quadrature rules for non-Gaussian shocks (e.g. Poisson disaster risk) should be straightforward to implement by mirroring the implementation in RiskAdjustedLinearizations.jl.
RiskAdjustedLinearizations.gausshermite_expectation
ā Functiongausshermite_expectation(f, Ī¼, Ļ, n = 10)
gausshermite_expectation(f, Ī¼, Ī£, n = 10)
gausshermite_expectation(f, Ī¼, Ī£, ns)
calculates the expectation of a function of a Gaussian random variable/vector. The first method evalulates $\mathbb{E}[f(X)]$ where $X \sim N(\mu, \sigma)$, while the other two methods evaluate $\mathbb{E}[f(X)]$ where $X \sim \mathcal{N}(\mu, \Sigma)$ and $\Sigma$ is diagonal. The latter two methods differ in that the first assumes the same number of quadrature points in every dimension while the second does not.
Inputs
f::Function
: some function of a random variable. Iff(x) = x
, thengausshermite_expectation(f, Ī¼, Ļ)
calculates the mean of $N(\mu, \sigma)$ using 10-point Gauss-Hermite quadrature.Ī¼::Number
orĪ¼::AbstractVector
: mean of the Gaussian random variable/vector.Ļ::Number
: standard deviation of the Gaussian random variable.Ī£::AbstractVector
: diagonal of the variance-covariance matrix of the Gaussian random vector.n::Int
: number of quadrature points to usens::AbstractVector{Int}
orns::NTuple{N, Int} where N
: number of quadrature points to use in each dimension of the Gaussian random vector.