Bug in SimPanelValues_TransPath_InfHorz

Thanks for the table

My runtimes are similar. It seems that there are problems with transition with interpolation: with no interpolation it converges but with interpilation it doesn’t (for the Guerrieri-Lorenzoni model).

should I take this as “better to set gridinterplayer=0 for transitions”?

1 Like

I think so: with no interpolation it converges nicely and the solution looks reasonable. This suggests that there is something unstable/incorrect with the interpolation command.

1 Like

GL2017 now converges with vfoptions.gridinterplayer=1.

But it is currently very very slow due to the change in convergence criteria for transition paths which implicitly massively increases the required accuracy; if you want to run GL2017 with grid interpolation layer I suggest setting transpathoptions.toleranceGEcondns=1e-3, else you’ll be waiting a while.

You can speed it up with the new ‘additional factors’.

I am hoping to update the GL2017 example soon with some better settings so it solves in reasonable times.

The reworking of the convergence criteria was the necessary first step in overhauling how the transition path updates are done, so hopefully some new faster and better algorithm choices are coming soon. I have completed the large amount of ground work that was required, the actual implementation should go fairly smoothly now.

I also did a lot of work on CoreInfHorzTests to improve the defaults for Howards, and on CoreInfHorzTPathTests to ensure the infinite horizon transition path codes are all working smoothly. Should make them much more reliable going forward.

2 Likes

Thanks Robert!

I have been looking to find faster algorithm to compute the transition and I found this code written by Ben Moll. On his website you can find the simple algorithm.

https://benjaminmoll.com/wp-content/uploads/2020/06/huggett_newton.m

The model is Huggett in continuous time. Using Newton instead of the simple method speeds up the transition by a lot. I don’t know if this is applicable also to discrete time models.

1 Like

Bang on suggestion. I’m literally halfway through coding this at the moment :smiley:

Actual Newton method is really slow because you have to solve n_p * T transition paths each time you want to build the Jacobian which Newton method would do every iteration, but you can use the Broyden method to avoid this (which is exactly what Moll’s code is doing). Broyden instead builds the Jacobian just once prior to the first iteration and then uses an approximate updating step each iteration.

PS. When you actually compute continuous time you have to discretize the time-step (Moll’s code calls the time step size ‘dt’), so anything you can do in one of discrete and continuous time always has something almost fully equivalent in the other.

2 Likes

Got Claude to write a brief explanation of exactly what Benjamin Moll’s transition path in Huggett (1993) model example codes are solving, and the differences between the three. Mainly so later if I decide to then it will be easy to build three toolkit examples that can be exactly compared to these to see things like accuracy, runtimes, and number of iterations.

The model

Continuous-time Huggett (1993) — Aiyagari–Bewley–Huggett with pure risk-sharing and no capital:

  • Income z \in \{z_1, z_2\} = \{0.1, 0.2\}, two-state Poisson, rates \lambda_1 (low→high) and \lambda_2 (high→low).
  • Agents hold a bond a paying r, CRRA \sigma = 2, \rho = 0.05, borrowing limit a \ge \underline{a} = -0.15 imposed as a state constraint (the dVb(1,:) = (z + r*amin)^(-s) boundary condition).
  • Bonds are in zero net supply, so equilibrium r is whatever makes S \equiv \int a \, g(a,z) \, da \, dz = 0.

Solved as HJB (backward, upwind finite differences, implicit) plus Kolmogorov Forward (forward, using the transpose of the same generator matrix A).

The experiment

An unanticipated permanent MIT shock at t = 0: \lambda_2 jumps from 0.5 (huggett_initial.m) to 0.8 (huggett_terminal.m), with \lambda_1 = 0.6 throughout. Good-income spells shorten from 2 years to 1.25; the stationary share in the low state rises from 0.5/1.1 = 45.5\% to 0.8/1.4 = 57.1\%. More income risk → stronger precautionary saving → lower equilibrium r in the new steady state. Agents learn the new \lambda_2 and the entire path \{r_t\} at t = 0, and have perfect foresight thereafter.

The three problems

1. Initial (huggett_initial.m). Stationary equilibrium at \lambda_2 = 0.5: bisect on r until S(r) = 0. Its only role in the transition is to deliver g_0 — the initial condition for the distribution, which is predetermined and cannot jump. (r00 is used only to draw the pre-shock segment of the plot.)

2. Terminal (huggett_terminal.m). Stationary equilibrium at \lambda_2 = 0.8. Delivers v_{st} — the terminal condition for the value function, which is forward-looking and does jump at t = 0 — and r_{st} as the initial guess for the path.

3. Transition (huggett_transition.m). A two-point boundary value problem on [0,T], with T = 20 and N = 100 nodes: find \{r_t\} such that

\rho v = u(c) + \partial_a v \cdot (z + r_t a - c) + \lambda_z (v_{-z} - v), \qquad v(\cdot, T) = v_{st}
\partial_t g = -\partial_a (s_t g) + \text{switching}, \qquad g(\cdot, 0) = g_0
\int a \, g_t \, da \, dz = 0 \quad \text{for all } t

Note how market clearing is actually imposed: the code computes dS(n), the change in aggregate wealth over each step, and drives that to zero. Since S(0) = 0 is inherited from the initial steady state, \dot{S}_t = 0 for all t is equivalent to S_t = 0. This works because the KFE conserves mass exactly, so the level condition never needs re-imposing. T must be long enough that the economy has effectively reached the terminal steady state by then.

The structural point: v depends on the future path of r, while g depends on the past — so you cannot iterate forward in time. You must guess the whole path, sweep backward for v (storing every A_t), then forward for g using those same A_t, and check market clearing.

What differs across the files

File Update on the r-path
huggett_transition.m Relaxation: r^{new} = r - \xi_t \odot dS, with \xi_t = 20(e^{-0.05t} - e^{-0.05N}) — hand-tuned, decaying in t so late periods move less. Robust-ish, slow, uses no derivative information.
huggett_newton.m + huggett_subroutine.m Treats F : \mathbb{R}^{100} \to \mathbb{R}^{100}, F(r) = dS(r), and solves F = 0. Jacobian at the initial guess by forward differences — 100 full transition solves, the expensive part — then dampened Broyden (\xi = 0.1) with rank-one updates J \leftarrow J + f \, dx' / (dx' dx). rank(J) is checked because a singular Jacobian signals the price path is not identified.
huggett_newton_myAD.m + huggett_subroutine_myAD.m Identical Newton scheme, but the 100 \times 100 Jacobian comes from forward-mode automatic differentiation in a single pass — exact rather than finite-differenced, and far cheaper. This is the real payoff of the AD version.

The subroutine is literally the inner loop of huggett_transition.m refactored to return dS as a residual vector, which is what makes it usable as F(x) for a root-finder.

2 Likes

This is interesting! I guess Ben Moll code is in Matlab… didn’t know Matlab have some routines for automatic differentiation. [I write this as a memo to myself to look into AD and Matlab.]

1 Like

It uses a custom AD implementation written by SeHyoun Ahn in matlab (there is some AD support in matlab, mostly for neural net models and the like, but that it not what Moll’s code uses).

1 Like

It would be indeed quite interesting to compare the Huggett transition in cts time by Ben Moll vs the equivalent model in discrete time by vfi toolkit.

I think the transition experiment is to increase the exogenous probability of moving from good to bad (in terms of labor productivity). In discrete time this would be a unexpected permanent change in one row of the Markov transition matrix for z (where z is idiosyncratic labor productivity).

The other obvious experiment is to consider an Aiyagari model and shock the TFP term.

1 Like

My preference goes for Huggett :slight_smile:

1 Like

Moll’s codes turn out to have a typo. I was building some tests to compare Moll’s transition path codes to VFI Toolkit codes (as an illustration). I came across a minor typo that appears in
huggett_newton.m: lines 60,64
huggett_newton_myAD.m: lines 55,59

It is very minor, Moll’s codes have:

x = x + xi*dx;                % step taken is xi*dx
J = J + f * dx'/(dx'*dx);     % update uses dx

The Broyden update should use the same size step for both, but currently uses xi*dx for one (with xi=0.1) and x for the other. [Minor enough to impact runtimes but still work fine, hence why it has gone unnoticed.]

Also, the AutoDiff approach won’t work for VFI Toolkit. The reason is that it requires using the closed-form of an FOC from the model to be able to implement.

2 Likes

Dear Robert,

Is there any update on the infinite horizon transition for Huggett model? I find Ben Moll’s code very fast but not so easy to extend or modify since continuous time is relatively challenging for me. I greatly favor the discrete time approach of the toolkit

Thanks!

1 Like

I’ve actually already pushed some stuff, if you point your AI at TransitionPath_InfHorz and tell it you want to change from GEnewprice=3 (shooting) to GEnewprice=2 (anderson acceleration) it should be capable of figuring it out. Seems to give a 5x speedup, sometimes more. From what I have seen so far this is the best of the new algorithms I’ve implemented.

I’m currently working on examples/explanations/documentation that should be public next week.

This is currently only implemented with InfHorz TPath, I need to then turn to doing FHorz TPath and the various PType versions. All takes quite a while as involves solving well over a hundred transition paths by the time I test out all the combos and see that they work over a range of settings.

2 Likes