Two-Asset-HANK Tutorial#

Again start with misc imports and load the package:

[1]:
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.

[2]:
example_hank2 = ep.examples.hank2
# parse model
hank2_dict = ep.parse(example_hank2)
# compile the model
hank2 = ep.load(hank2_dict)
Creating grid variables:
    ...adding exogenous Rouwenhorst-grid for 'skills' with objects 'skills_grid', 'skills_transition' and 'skills_stationary'.
    ...adding endogenous log-grid for 'b' named 'b_grid'.
    ...adding endogenous log-grid for 'a' named 'a_grid'.
(load:) Parsing done.
[3]:
stst_result = hank2.solve_stst()
    Iteration   1 | max. error 3.64e+01 | lapsed 5.9546
(solve_stst:) Steady state found (7.801s). The solution converged.

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

[4]:
# 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:

[5]:
xlin, flags = hank2.find_path_linear(init_state=x0.values())
(get_derivatives:) Derivatives calculation done (8.220s).
(get_jacobian:) Jacobian accumulation and decomposition done (3.638s).
(find_path_linear:) Linear solution done (72.328s).
[6]:
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)
../_images/tutorial_hank2_10_0.png

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

[7]:
xst, flags = hank2.find_path(init_state=x0.values())
    Iteration  1 | fev.   1 | error 4.35e-01 | inner 4.63e-07 | dampening 1.000
    Iteration  2 | fev.   3 | error 5.81e-03 | inner 8.09e-06 | dampening 1.000
    Iteration  3 | fev.   4 | error 9.66e-07 | inner 2.68e-08 | dampening 1.000
    Iteration  4 | fev.   5 | error 3.31e-10 | inner 2.28e-11 | dampening 1.000 | lapsed 7.2767s
(find_path:) Stacking done (7.370s). The solution converged.
[8]:
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)
../_images/tutorial_hank2_13_0.png