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 ā€” Function
euler_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

\[\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.

Inputs

  • m::RiskAdjustedLinearization: A solved instance of a risk-adjusted linearization
  • cā‚œ::Function: a function of (m, zā‚œ) that calculates consumption at state zā‚œ, given the state-space representation implied by m.
  • logSDFxR::Function: a Function evaluating $m_{t + 1} + r_{t + 1}$. The Function must take as input (m, zā‚œ, Īµā‚œā‚Šā‚, c), where m is a RiskAdjustedLinearization, zā‚œ is a state vector at which to evaluate, Īµā‚œā‚Šā‚ is a draw from the distribution of exogenous shocks, and c is a guess for consumption at zā‚œ implied by the conditional expectation in the Euler equation when calculated with a quadrature rule. Note that c can be either the consumption level or some transformation (e.g. log consumption), but the user should be consistent in the definition of the cā‚œ function with the guess c, 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 a Function with a single input, which is a shock Īµā‚œā‚Šā‚.
  • zā‚œ::AbstractVector: a state at which to evaluate the Euler equation error
  • shock_matrix::Abstractmatrix: a NĪµ Ɨ 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 the RiskAdjustedLinearization
  • summary_statistic::Function: a Function 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-in
  • return_soln::Bool: if true, return the solution to the nonlinear equation isntead of the error
  • kwargs: Any keyword arguments for nlsolve can be passed, too, e.g. ftol or autodiff since nlsolve is used to calculate the "true" consumption policy.
source
RiskAdjustedLinearizations.dynamic_euler_equation_error ā€” Function
dynamic_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.

  1. Simulate according to the risk-adjusted linearization time series for the state variables
  2. 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.
  3. 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 linearization
  • cā‚œ::Function: a function of (m, zā‚œ) that calculates consumption at state zā‚œ, given the state-space representation implied by m.
  • logSDFxR::Function: a Function evaluating $m_{t + 1} + r_{t + 1}$. The Function must take as input (m, zā‚œ, Īµā‚œā‚Šā‚, cā‚œ), where m is a RiskAdjustedLinearization, zā‚œ is a state vector at which to evaluate, Īµā‚œā‚Šā‚ is a draw from the distribution of exogenous shocks, and cā‚œ is the a guess for consumption at zā‚œ implied by the conditional expectation in the Euler equation when calculated with a quadrature rule.
  • š”¼_quadrature::Function: a quadrature rule whose single input is a Function 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 by endo_states (usually 1).
  • zā‚œ::AbstractVector: a state at which to evaluate the Euler equation error
  • shock_matrix::Abstractmatrix: a NĪµ Ɨ 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 the RiskAdjustedLinearization
  • summary_statistic::Function: a Function 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-in
  • kwargs: Any keyword arguments for nlsolve can be passed, too, e.g. ftol or autodiff since nlsolve is used to calculate the "true" consumption policy.
source

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 ā€” Function
gausshermite_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. If f(x) = x, then gausshermite_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 use
  • ns::AbstractVector{Int} or ns::NTuple{N, Int} where N: number of quadrature points to use in each dimension of the Gaussian random vector.
source