OLG Transition Path Error

Hi Robert,

I tried to use method in Aiyagari1994TransitionPath.m to OLGModel6 to see the impact of increasing in alpha. To make it run faster, I reduce the grid size, keep only 2 prices (r and Accbeq), and use only one shock (z).

vfiToolkit got initial and final equilibrium successfully, but when it ran PricePath=TransitionPath_Case1(), the following error appears:

Error using ReturnFnParamNamesFn (line 63)
The parameter agej must be scalar or age-dependent (check the size of this parameter; it is needed as an inputto the ReturnFn)
Error in TransitionPath_Case1 (line 282)
ReturnFnParamNames=ReturnFnParamNamesFn(ReturnFn,n_d,n_a,n_z,0,vfoptions,Parameters);
Error in transition_test (line 215)
PricePath=TransitionPath_Case1(PricePath0, ParamPath, T, V_final, StationaryDist_init, n_d, n_a, n_z, pi_z, d_grid,a_grid,z_grid, ReturnFn, FnsToEvaluate, TransPathGeneralEqmEqns, Params, DiscountFactorParamNames, transpathoptions);

I don’t understand the error message here since size(agej)=[1,81], which is the same as [1,Nj]. It should be age-dependent.

1 Like

If I understand correctly you used
PricePath=TransitionPath_Case1()
which is the infinite horizon model version.

What you need instead is
PricePath=TransitionPath_Case1_FHorz()
which is the finite-horizon model version.

The way everything works is otherwise much the same in terms of how to set things up.

[Much like Aiyagari model uses ValueFnIter_Case1() while OLG models use ValueFnIter_Case1_FHorz()]

[Since infinite-horizon models don’t understand N_j, you got that error.]

1 Like

PS. turn on vfoptions.divideandconquer=1 and transpathoptions.fastOLG=1 when you do the transition path. Will make it vastly faster.

[vfoptions.divideandconquer=1 requires that the model jas montone policy functions, and OLGModel6 will satisfy this. Actually you should also use this to speed up the stationary eqm calculations.]

I see. I changed to FHorz and get the new error:

Unrecognized function or variable ‘CreateReturnFnMatrix_Case1_Disc_fastOLG_DC1_Par2’.
Error in ValueFnIter_FHorz_TPath_SingleStep_fastOLG_DC1_raw (line 50)
ReturnMatrix_ii=CreateReturnFnMatrix_Case1_Disc_fastOLG_DC1_Par2(ReturnFn, n_d, n_z, N_j, d_gridvals, a_grid, a_grid(level1ii), z_gridvals_J, ReturnFnParamsAgeMatrix,1);

Error in ValueFnIter_Case1_FHorz_TPath_SingleStep_fastOLG (line 24)
[VKron, PolicyKron]=ValueFnIter_FHorz_TPath_SingleStep_fastOLG_DC1_raw(VKron,n_d,n_a,n_z, N_j, d_grid, a_grid, z_gridvals_J, pi_z_J, ReturnFn, Parameters, DiscountFactorParamNames, ReturnFnParamNames, vfoptions);

Error in TransitionPath_Case1_FHorz_shooting_fastOLG (line 235)
[V, Policy]=ValueFnIter_Case1_FHorz_TPath_SingleStep_fastOLG(V,n_d,n_a,n_z,N_j,d_grid, a_grid, z_gridvals_J, pi_z_J, ReturnFn, Parameters, DiscountFactorParamNames, ReturnFnParamNames, vfoptions);

Error in TransitionPath_Case1_FHorz (line 738)
PricePathOld=TransitionPath_Case1_FHorz_shooting_fastOLG(PricePathOld, PricePathNames, PricePathSizeVec, ParamPath, ParamPathNames, ParamPathSizeVec, T, V_final, AgentDist_init, jequalOneDist, n_d, n_a, n_z, N_j, d_grid,a_grid,z_gridvals_J, pi_z_J, ReturnFn, FnsToEvaluate, GeneralEqmEqns, Parameters, DiscountFactorParamNames, AgeWeights, ReturnFnParamNames, vfoptions, simoptions,transpathoptions);

Error in transition_test (line 215)
PricePath=TransitionPath_Case1_FHorz(PricePath0, ParamPath, T, V_final, StationaryDist_init, jequaloneDist,n_d, n_a, n_z, N_j, pi_z, d_grid,a_grid,z_grid, ReturnFn, FnsToEvaluate, TransPathGeneralEqmEqns, Params, DiscountFactorParamNames, AgeWeightsParamNames, transpathoptions, simoptions, vfoptions);

Seems that a function is missing, or maybe different name?

2 Likes

Oops sorry, was missing a file. Should be there now :slight_smile:

(I just overhauled this last week and has missed a file when pushing to github)

2 Likes

Thanks. Now it runs successfully. Also I wonder does it work for two assets model?

1 Like

Currently vfoptions.divideandconquer=1 for the transition path has only been coded for the case of just one endogenous state.

In principle a transition path with vfoptions.divideandconquer=0 and two endogenous states should work (I’ve never actually tried it) but it is likely both slow and very demanding of GPU memory.

If you specifically want to be doing an OLG transition path for a two asset model tell me and I will put coding it for vfoptions.divideandconquer=1 as a priority (currently it is not a priority for me. I don’t know how well it will work, in the sense it will work okay but might be very demanding of GPU memory given the fastOLG=1)

2 Likes

I’d appreciate if you could add that feature since I’m doing a research related to housing portfolio, which has two assets.
i did try to run it without using divideandconquer. It reports an error when I ran

PricePath=TransitionPath_Case1_FHorz(.)

The issue is from line 261 of TransitionPath_Case1_FHorz.m, it requires size(a_grid)==[N_a,1]. But N_a=prod(n_a), so if my assets grid n_a is [101,6], N_a becomes 606, while the size of stacked a_grid is [107,1].

1 Like

@Shiki If you are working on an OLG two-asset model with transition, I think the example based on K.Chen’s RED paper can be a useful reference

1 Like

Actually this afternoon I tried to incorporate transition path code to Chen(2010) sample codes, and get the same error. In the sample, n_a=[301,35], but TransitionPath_Case1_FHorz will check the size of inputs (line 260,261)

if ~all(size(a_grid)==[N_a, 1])
error(‘a_grid is not the correct shape (should be of size N_a-by-1) \n’)

In this case, LHS is [301+35,1] and RHS is [301*35,1], so it will stop running. I haven’t looked into the codes in details, not sure if it will cause problem if I change the calculation of N_a.

1 Like

The earlier error was my fault, should be all(size(a_grid)==[sum(n_a),1]). I hope to find time to fix this and run a test tomorrow.

[As I mentioned, while I think I coded for two assets, I have never run a test code before, so it is a little rough.]

1 Like

I was looking and realised that a transition path with two endogenous states is going to take more work than I thought.

I am pretty busy on some projects at the moment. Doing this is a moderate priority for me, but I suspect will happen in January (the two projects that need all my time both finish by late Dec). Hopefully I will be back here in early Jan to post that it works now :slight_smile:

2 Likes

Thanks, Robert. I’ll wait for the new update. And could you explain briefly how vfitoolkit calculate the price path from the initial price path?

1 Like

I added a brief description of how transition paths work to the VFI Toolkit Pseudo-Codes pdf

I copy paste it here for convenience


We consider a transition path of length T time periods. Solving for a transition path general equilibrium, we are looking for some path-of-parameters that are determined in general equilibrium, call them \Theta such that our general equilibrium equations equal zero in every time period, GEeqn(\Theta)=0. Note that at some level this is the same thing we did for a stationary equilibrium, except that now \Theta=\{\theta_1,....,\theta_T\} is a time-path of general-eqm parameters, rather than just parameters at a single point in time.

There are various algorithms for doing this (\textit{heteroagentoptions.fminalgo} determines which is used), but all of them essentially boil down to the following,
\begin{algorithmic}
\State Guess some initial \Theta^0 (time-path on general-equilibrium parameters)
\State Define GeneralEqmConditions=\infty
\While GeneralEqmConditions>tolerance
\State Solve backward, t=T-1,\dots,2,1 for the value fn and policy at each t (given current \theta^k_t)
\State Solve forward, t=1,2,\dots,T for the agent distribution (given current \theta^k_t and Policy_t we just found)
\State Solve the aggregate variables at each t (given current \theta_t^k and policy/agent dist we just found for t)
\State Evaluate GeneralEqmConditions=[GEeqn_1(AggVars_1,\theta_1^k), $GEeqn_1(AggVars_1,\theta_1^k),$$\dots,$ GEeqn_T(AggVars_T,\theta_T^k)] (evaluate general eqm eqns at each time period)
\State Update \Theta^{k+1} (in some way, likely based on \Theta^k and GeneralEqmConditions)
\EndWhile
\ \Return \theta
\end{algorithmic}
The difference between the different \textit{fminalgo} is how we update the \Theta. The most common way to update is as a shooting algorithm.

In a stationary equilibrium, parameters other than those parameters which were being determined in general equilibrium (the general equilibrium parameters) were all constant (in time) and kept in Parameters structure. When we solve transition paths, some parameters might vary over time, and this is done with the ParamPath (a path on exogenous parameters), while any other parameters not in this path are assumed to be constant at their values in Parameters structure. It is not described in algorithm above, but obviously we have to make sure to use the correct parameters in each time period.

It is important to solve backward for policy and forward for agent distribution. For convenience, aggregate variables and general eqm conditions are often solved forwards while doing agent distribution, but in principle how we deal with these (in terms of timing) is not important is most models (can be important if we use lagged/leading parameter values for something).

Whether the problem is finite or infinite-horizon value functions, and whether or not there are permanent types of different kinds of shocks is unimportant, in the sense that the above steps are all the same steps, just that the details of their implementation is changed.


PS. This looks a lot like how stationary general eqm is solved (for \theta^k, solve V and Policy, solve agent dist, evaluate agg vars, evaluate general eqm eqns, update \theta^{k+1}), just that now everything is a path instead of a value at a single point in time.

2 Likes