Aggregate Shocks (beta functionality)

Heterogenous Agent models with Aggregate Shocks have arrived in VFI Toolkit. Beta functionality for now but already quite powerful and may be of interest to some. I expect this to become a full feature of the toolkit (no longer beta) toward the end of this year.

Here is link to a repo that contains slides I presented at CEF2026 that briefly explain what is being done (the key is Hanbaek Lee’s Matched-Expectations Path algorithm). The repo has codes for four examples
i) Krussell & Smith (1998)
ii) Uncertainty shocks
iii) Kitao (2008) with Aggregate Shocks (Entrepreneurial-Choice)
iv) Quasi-Hyperbolic Discounting in Krussell & Smith (1998)

Matched-Expectations Path is a global non-linear solution method. The codes for the Krussell & Smith (1998) take 25 seconds to run. This is meaningfully faster than every other existing global non-linear solution of this model, plus the code is vastly simpler.
[Structural Reinforcement Learning takes 37s, Deep Learning in the Sequence Space takes 1 minute, DeepHAM+Finite Difference takes 10 minutes, DeepHAM takes 59 minutes]

This is beta functionality because: (i) cannot yet handle decision variables, (ii) currently just solves and gives you the ‘generalized transition path’ which is the solution but also is a rather non-trivial object and there are not yet any commands for analyzing the results (e.g., to produce a generalized IRF).

3 Likes

On Slide 2, the last step should read “Repeat Steps 1-5”. You don’t want to reveal the punchline too soon :wink:

Regarding Slide 21 (getting more accurate grids)…my experiments with experience assets (De-Gaussing Experiments with ExpAsset) led me to discover the power of shaping the grid according to the expected evolution of the values in state space.

For example, I initially adopted the model of making a cubic state space for asset value when taking on debt. At first blush, it’s convenient because it allows lots of grid points where numbers are close to zero, and it maintains the sign of the argument on either side of the zero line. However, the shape of cubic evolution is nothing like the returns of compound interest, meaning I needed a large grid density to reasonably track the progress of my compounding asset. When I switched to a purely exponential grid (taking care to appropriately mirror and flip the debt side and the credit side), I could get accurate results with surprisingly small grids.

Here are notes I left myself for modeling a retirement account (based loosely on the KiwiSaver employee/employer contribution benefit scheme, so ks abbreviates KiwiSaver) coupled with an asset account (abbreviated a):

% ks=73 good for 2x ks_max, a_max @ 4 (but use 10 for employment shocks)
% ks=61 good for 3x ks_max, a_max @ 6
% ks=61 good for 3x ks_max, a_max @ 6
% ks=53 good for 6x ks_max, a_max @ 16
% ks=43 good for 16x ks_max, a_max @ 64
% ks=37 good for 32x ks_max, a_max @ 96
% ks=31 good for 64x ks_max, a_max @ 192
% ks=23 ok+ for 512x ks_max, a_max @ 1024
% ks=17 ok- for 2048x ks_max, a_max @ 2560
% ks=13 marginal for 4096x ks_max, a_max @ 4096

In other words, with 73 gridpoints, approximations from grid interpolation intrinsic to Experience Assets never had errors evolve above 2x the normal maximum contribution from j=1 to j=46 (the retirement age). As well, I never needed more than 4x w to hold the assets that agents banked alongside the assets liquidated from the KiwiSaver account into their asset account.

As you can see, when we get down to 23 gridpoints, we need some extraordinary headroom (512x the max contribution+growth amount) in the grid to keep the error terms from evaporating off the top. The fact that the assets enjoy a year-on-year growth factor means we don’t need to worry about errors that evaporate down through the bottom of the grid. In that case, we need a high ceiling (1024) on the asset value max.

In all these cases, I allocated 43-83 points to the asset grid, and let the power of an exponential grid allow agents to deposit very small amounts early in their lives and still be prepared for absolute windfalls when the rare maximum error term came due for one lucky agent.

With cubic grids, and especially with linear grids, hundreds or thousands of points would be needed to get the same accuracy. I would offer than any grid that expects to model assets whose expected value contains an exponential term,
exp(linspace(minval,log(maxval),n_gridpoints))-exp(minval)
is a good starting point if you want to start from zero and go up,
-exp(linspace(log(maxval),minval,n_gridpoints))-exp(minval)
is good if you want to go from zero to negative maxval, and of course the two can be joined seamlessly with unique([neg_gridvals,pos_gridvals]) if you want something running from negative to positive with a single zero value along the way. In any case, the choice of minval determines whether the curve begins with more flatness (minval < 0) or begins its rise quickly (minval >= 0).

Caveat: My testing principally focused on LifeCycle statistics of a variety of scenarios. I have not tried solving GE problems that may reveal yet other stability/accuracy problems.

Adaptive grids are clearly the future, but exactly how to do a nice general implementation is not yet clear to me.

1 Like