# 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.

## 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: