Two-Asset-HANK Tutorial#

Again start with misc imports and load the package:

import jax.numpy as jnp
from grgrlib import figurator, grplot
import econpizza as ep # pizza
import matplotlib.pyplot as plt

# only necessary if you run this in a jupyter notebook:
%matplotlib inline

The provided example is the medium-scale two-asset model from the paper, which is again documented in the appendix. The YAML file can also be found in the examples folder. This model features a portfolio choice problem for households and all the bells ans whistles of the medium scale DSGE model.

example_hank2 = ep.examples.hank2
# parse model
hank2_dict = ep.parse(example_hank2)
# compile the model
hank2 = ep.load(hank2_dict)
(load:) Parsing done.
stst_result = hank2.solve_stst()
    Iteration   1 | max. error 3.64e+01 | lapsed 16.1393
(solve_stst:) Steady state found (19.409s). The solution converged.

Again, look at a discount factor shock and calculate the pefect foresight solution:

# this is a dict containing the steady state values
x0 = hank2['stst'].copy()
# setting a shock on the discount factor
x0['beta'] *= 1.01

But let us this time start with a linear IRFs, just because we can:

xlin, flags = hank2.find_path_linear(init_state=x0.values())
(get_derivatives:) Derivatives calculation done (13.100s).
(get_jacobian:) Jacobian accumulation and decomposition done (6.249s).
(find_path_linear:) Linear solution done (26.710s).
variables = 'y', 'C', 'y', 'pi', 'Rn', 'A', 'B', 'w', 'beta'
inds = [hank2['variables'].index(v) for v in variables]

figs, axs = figurator(3,3, figsize=(12,8))
_ = grplot(xlin[:30, inds], labels=variables, ax=axs)

Great. Finally, we can compare this with the fully nonlinear responses:

xst, flags = hank2.find_path(init_state=x0.values())
    Iteration  1 | fev.   1 | max. error 4.35e-01 | dampening 1.000
    Iteration  2 | fev.   3 | max. error 5.81e-03 | dampening 1.000
    Iteration  3 | fev.   4 | max. error 9.66e-07 | dampening 1.000
    Iteration  4 | fev.   5 | max. error 3.31e-10 | dampening 1.000 | lapsed 25.7429s
(find_path:) Stacking done (25.885s). The solution converged.
figs, axs = figurator(3,3, figsize=(12,8))
_ = grplot((xst[:30, inds], xlin[:30, inds]), labels=variables, ax=axs, legend=('nonlinear', 'linear'))
_ = axs[0].legend(fontsize=16)