Implementation Details

Alisdair McKay

«  A heterogeneous agent new Keynesian model   ::   Contents

Implementation Details

In the preceding material I have focussed on conveying the big picture of the algorithms. Now let’s add some details that make the algorithms faster or more accurate or actually operational.

Conflicting equations

Consider a model like the HANK application discussed here. If one keeps track of the distribution of households across levels of wealth and employment status, then one could compute the unemployment rate from the distribution of wealth. If you also include a law of motion for the unemployment rate

\[1-u_t = (1-\delta) (1-u_{t-1}) + H_t\]

among your equations, then you may encounter a non-existence problem because there are two sets of equations that govern the unemployment rate explicitly or implicitly. Whether or not this problem arises depends on the exact details of how you set up the other equations, but it is something to consider if you encounter non-existence.

How to set up the grids

The algorithms involve two user-defined grids (possibly the same). The grid \(A\) discretizes levels of savings in solving for the decision rule and grid \(B\) discretizes levels of current assets in simulating the distribution of wealth. The solution to this type of consumption-savings problem generally look like this:

In the region where the borrowing constraint is just about to bind, the decision rule displays substantial curvature while at higher levels of assets, the decision rule is nearly linear in current assets. In our linear Interpolation scheme, we will want many interpolation nodes in the region with curvature in order to accurately capture the shape of the function however in the nearly linear portion of the decision rule we will need very few interpolation nodes.

The shape of the savings policy rule also matters for the shape of the grid used to approximate the distribution of wealth. If the decision rule is linear, then aggregate savings will not be affected by how wealth is distributed in the population. That is, if \(g\) is linear, then we can pass the integral inside the decision rule

\[K' = \int g(a,e) d \Gamma(a,e) = \sum_e g(\int a d \Gamma(a,e), e)\]

and we need only keep track of the distribution of wealth over values of \(e\) and not across levels of assets \(a\). On the other hand, if \(g\) is non-linear with respect to \(a\) then aggregate savings will depend on how wealth is distributed across levels of \(a\). Similar logic implies that the more nonlinear is \(g\) the more carefully we want to track the distribution of wealth across levels of assets.

These considerations motivate designing the grids to have more points at low levels of savings because that is where the decision rule is more non-linear. At high levels of savings, we can simply use two points to define a line, which in practice means linearly extrapolating the decision rule beyond the end of the grid when necessary.

One approach to create an unevenly-spaced grid is to make an evenly spaced grid a pass it through a non-linear transfomration. For example:

gridmin, gridmax, gridsize = 0.0, 200.0, 201
grid = np.linspace(gridmin**(0.25), gridmax**(0.25), gridsize)**4

«  A heterogeneous agent new Keynesian model   ::   Contents