Hi Tony,
there are two possible ways to enforce the budget constraint. In most of the example codes it is simply done via the grid on assets (the same grid applies to assets and next period assets). For example, we could set asset grid,
n_a=501; % Number of points to use for asset grid
a_grid=linspace(0,15,n_a)';
Because this grid has a minimum of zero, we are implicitly enforcing that a_{t+1}>=0.
The other alternative would be to use the return function. Say we have the grid
a_grid=linspace(-3,15,n_a)';
we could add the following lines to the return function
if aprime<0
F=-Inf;
end
Because the return to choosing aprime<0 is minus infinity we would never choose it, which is effectively the same thing as making it impossible to choose (mathematically it is the same).
Which of the two should you use? If you know the value of the borrowing constaint (zero in your example) before you start then hardcoding it into the grid is the best approach. Notice that the second approach ‘wastes’ all the points on the asset grid that are below zero. Sometimes though you want to vary the borrowing constraint, for example maybe people without houses cannot borrow but people with houses can borrow (using the house as collateral), in which case the second approach of using the return function to enforce the constraint is likely better.
PS. The asset grid above is not very good because it has evenly spaced points. We know (from theory and experience) that the value function will have more curvature near the borrowing constraint. And for a given number of grid points we will get more accurate results if we put more points where there is most curvature (intuitively, high curvature means the first derivative is changing a lot, and so the choices, which are determined at the margin/by equating derivatives, are sensitive to changes in this region). So a better grid would be
a_grid=15*(linspace(0,1,n_a).^3)';
(this is also from 0 to 15, the power of three means more will be near 0; a higher power would distribute them even more towards zero; note that you could add/subtract if you want the minimum grid point to be something other than zero)
PPS. All grids must be column vectors. Hence the ’ on the linspace.
PPPS. Obviously all of these grids are enforcing a maximum of 15. As long as this number is ‘large enough’ it doesn’t matter. How big exactly ‘large enough’ is will depend on the model.