# OLG Transition Path Error

**URL:** https://discourse.vfitoolkit.com/t/olg-transition-path-error/314
**Category:** Uncategorized
**Created:** [October 29, 2024, 6:53am UTC](https://discourse.vfitoolkit.com/t/olg-transition-path-error/314 "2024-10-29T06:53:07Z")
**Posts on this page:** 15
**Page:** 2

<div class="post-metadata">

### Author: ![robertdkirkby](https://discourse.vfitoolkit.com/user_avatar/discourse.vfitoolkit.com/robertdkirkby/32/287_2.png) [@robertdkirkby](https://discourse.vfitoolkit.com/u/robertdkirkby)
#### Post date: [January 13, 2025, 8:03am UTC](https://discourse.vfitoolkit.com/t/olg-transition-path-error/314/21 "2025-01-13T08:03:13Z")

</div>

I would set up a\_grid using the minimum value of gamma (here 0.1) that you plan to use.

This grid will mean some points are unused with gamma=0.2, but this is not a problem, just a little bit of a waste.

(so set up a\_grid using -(1-0.1)\*maxh, and then use this same grid with both gamma values; toolkit is not currently capable of handling that a\_grid changes with age/time-period)

---

<div class="post-metadata">

### Author: ![aledinola](https://discourse.vfitoolkit.com/letter_avatar_proxy/v4/letter/a/3ec8ea/32.png) [@aledinola](https://discourse.vfitoolkit.com/u/aledinola)
#### Post date: [January 14, 2025, 1:33am UTC](https://discourse.vfitoolkit.com/t/olg-transition-path-error/314/22 "2025-01-14T01:33:18Z")

</div>

Nice! I could try and finish the Chen (2010) replication if I find the time. I think his experiment is to eliminate social security as in the seminal work by Conesa and Krueger (1999)

---

<div class="post-metadata">

### Author: ![Shiki](https://discourse.vfitoolkit.com/letter_avatar_proxy/v4/letter/s/5fc32e/32.png) [@Shiki](https://discourse.vfitoolkit.com/u/Shiki)
#### Post date: [February 20, 2025, 4:35am UTC](https://discourse.vfitoolkit.com/t/olg-transition-path-error/314/23 "2025-02-20T04:35:52Z")

</div>

Hi Robert, I’m currently working on a housing portfolio model with mortgage contracts. There is an additional state variable to count the remaining periods of mortgage. I wonder does TransitionPath\_Case1\_FHorz.m work for three state variables?

---

<div class="post-metadata">

### Author: ![robertdkirkby](https://discourse.vfitoolkit.com/user_avatar/discourse.vfitoolkit.com/robertdkirkby/32/287_2.png) [@robertdkirkby](https://discourse.vfitoolkit.com/u/robertdkirkby)
#### Post date: [February 20, 2025, 3:24pm UTC](https://discourse.vfitoolkit.com/t/olg-transition-path-error/314/24 "2025-02-20T15:24:55Z")

</div>

I think that the answer is yes, you can use TransitionPath\_Case1\_FHorz() with three endogenous states [so length(n\_a)=3]. I’ve never tried.

Obviously runtimes might be an issue (might be too slow to be useful), but I guess you will find out 🙂

If it doesn’t run, let me know and I will try fix it.

What you cannot do yet is use divide and conquer (which would make it faster). Not sure if fastOLG will work or not (good odds it runs out of memory anyway; you can always try it).

PS. I’m assuming ‘housing portfolio model’ does not mean using a riskysset, if it does mean using a riskyasset then you cannot currently do this in transition paths.

---

<div class="post-metadata">

### Author: ![Shiki](https://discourse.vfitoolkit.com/letter_avatar_proxy/v4/letter/s/5fc32e/32.png) [@Shiki](https://discourse.vfitoolkit.com/u/Shiki)
#### Post date: [February 20, 2025, 9:15pm UTC](https://discourse.vfitoolkit.com/t/olg-transition-path-error/314/25 "2025-02-20T21:15:55Z")

</div>

I used a simple model to test it. The basic model is still from Chen (2010). Besides net deposit a and housing h, I add an ‘idle’ state variable o. It has only one grid value 0, so basically it does nothing. Households just keep choosing 0. The equilibrium prices are r and Tr. I examined the effect of change in alpha.

Here are [my codes](https://github.com/shiki-jiang/Three-State-Transition-Path-/blob/main/ThreeState_transition.m). The initial and final equilibrium have no problem but the transition path of all aggregate variables somehow become zero.

 ![Screenshot 2025-02-20 154811](https://discourse.vfitoolkit.com/uploads/default/original/1X/6b2f938ef5c7a625bcac8d1d2c73450fa92e4313.png)  
 ![Screenshot 2025-02-20 154900](https://discourse.vfitoolkit.com/uploads/default/original/1X/bbe7d92d02dec6683321e5d0e1237533c10f1e86.png)

When it iterates, it has the following output:  
ans =

```
0.0358 0.0887 NaN 0.0886
0.0355 0.0878 NaN 0.0878
0.0352 0.0870 NaN 0.0869
0.0349 0.0862 NaN 0.0861
0.0346 0.0853 NaN 0.0853
0.0343 0.0845 NaN 0.0844
0.0340 0.0837 NaN 0.0836
0.0337 0.0828 NaN 0.0827
0.0334 0.0820 NaN 0.0819
0.0331 0.0812 NaN 0.0811
0.0328 0.0803 NaN 0.0802
0.0325 0.0795 NaN 0.0794
0.0322 0.0787 NaN 0.0786
0.0319 0.0778 NaN 0.0777
0.0316 0.0770 NaN 0.0769
0.0313 0.0761 NaN 0.0761
0.0310 0.0753 NaN 0.0752
0.0307 0.0745 NaN 0.0744
0.0304 0.0736 NaN 0.0736
0.0301 0.0728 NaN 0.0727
0.0298 0.0720 NaN 0.0719
0.0295 0.0711 NaN 0.0711
0.0293 0.0703 NaN 0.0702
0.0290 0.0695 NaN 0.0694
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 NaN 0.0685
0.0287 0.0686 0.0287 0.0686

```

> Number of iterations on transition path: 1  
> Current distance between old and new price path (in L-Infinity norm): 0.000089  
> Current distance to convergence: 0.89 (convergence when reaches 1)

---

<div class="post-metadata">

### Author: ![robertdkirkby](https://discourse.vfitoolkit.com/user_avatar/discourse.vfitoolkit.com/robertdkirkby/32/287_2.png) [@robertdkirkby](https://discourse.vfitoolkit.com/u/robertdkirkby)
#### Post date: [March 15, 2025, 2:13am UTC](https://discourse.vfitoolkit.com/t/olg-transition-path-error/314/26 "2025-03-15T02:13:20Z")

</div>

Just pushed a fix to what was the problem (it didn’t actually calculate AggVars when length(n\_a)=3, and so just returned all zeros).

I don’t promise this means three assets in FHorz transition path works, I’ve never tested it. But what used to be the error is now gone (maybe there is a new one, maybe not).

---

<div class="post-metadata">

### Author: ![Shiki](https://discourse.vfitoolkit.com/letter_avatar_proxy/v4/letter/s/5fc32e/32.png) [@Shiki](https://discourse.vfitoolkit.com/u/Shiki)
#### Post date: [March 17, 2025, 6:02pm UTC](https://discourse.vfitoolkit.com/t/olg-transition-path-error/314/27 "2025-03-17T18:02:14Z")

</div>

Thanks Robert. Now it can produce the non-zero AggVars transition path.

 ![transition](https://discourse.vfitoolkit.com/uploads/default/original/1X/257a78918a26dd0356f39c61612433f17071eeab.png)

I have another question about the price path. In my test example, the price paths converge immediately. is it normal?

 ![transitionprice](https://discourse.vfitoolkit.com/uploads/default/original/1X/e5672871c7de3ae20d46b454e70541ae894967f7.png)

> Number of iterations on transition path: 1  
> Current distance between old and new price path (in L-Infinity norm): 0.000042  
> Current distance to convergence: 0.42 (convergence when reaches 1)

---

<div class="post-metadata">

### Author: ![robertdkirkby](https://discourse.vfitoolkit.com/user_avatar/discourse.vfitoolkit.com/robertdkirkby/32/287_2.png) [@robertdkirkby](https://discourse.vfitoolkit.com/u/robertdkirkby)
#### Post date: [March 17, 2025, 7:21pm UTC](https://discourse.vfitoolkit.com/t/olg-transition-path-error/314/28 "2025-03-17T19:21:47Z")

</div>

> I have another question about the price path. In my test example, the price paths converge immediately. is it normal?

No. It will only happen once the update of the transition path is less than the convergence tolerance.

If you want an easy test of whether your code likely works, try solving the transition path where ‘nothing happens’ (initial and final eqm are the same).

---

<div class="post-metadata">

### Author: ![aledinola](https://discourse.vfitoolkit.com/letter_avatar_proxy/v4/letter/a/3ec8ea/32.png) [@aledinola](https://discourse.vfitoolkit.com/u/aledinola)
#### Post date: [March 17, 2025, 8:06pm UTC](https://discourse.vfitoolkit.com/t/olg-transition-path-error/314/29 "2025-03-17T20:06:14Z")

</div>

Good suggestion @robertdkirkby. This is also what I always do to check the transition path.

Basically you compute only the initial steady state and then you set the final steady state equal to the initial one. Hence the guess for the interest rate path (and for other GE variables) is a constant sequence with elements equal to r\_ss, the interest rate in the initial/final steady state. Then you should converge almost immediately. If not, there is a bug in the code 🙂

---

<div class="post-metadata">

### Author: ![Shiki](https://discourse.vfitoolkit.com/letter_avatar_proxy/v4/letter/s/5fc32e/32.png) [@Shiki](https://discourse.vfitoolkit.com/u/Shiki)
#### Post date: [March 19, 2025, 12:08am UTC](https://discourse.vfitoolkit.com/t/olg-transition-path-error/314/30 "2025-03-19T00:08:40Z")

</div>

@robertdkirkby @aledinola Thanks for the suggestion. If I understand correctly, I should also keep alpha constant (my test model is to analyze the change of alpha), and since nothing changes, the transition path of prices (interest rate and transfer) will be horizontal lines?

---

<div class="post-metadata">

### Author: ![robertdkirkby](https://discourse.vfitoolkit.com/user_avatar/discourse.vfitoolkit.com/robertdkirkby/32/287_2.png) [@robertdkirkby](https://discourse.vfitoolkit.com/u/robertdkirkby)
#### Post date: [March 19, 2025, 1:15am UTC](https://discourse.vfitoolkit.com/t/olg-transition-path-error/314/31 "2025-03-19T01:15:00Z")

</div>

Yeah, exactly.

Being able to solve the ‘nothing happens’ transition path does not guarantee that your actual transition path will solve correctly, but if you cannot solve ‘nothing happens’ then you cannot solve your actual transition path. Plus the ‘nothing happens’ is very easy to debug because you know exactly what the answer is so you can see exactly what is going wrong.

Of course, the ‘nothing happens’ transition path is not of any actual interest itself, just tends to be a nice way to do a first debugging of code because no matter how complex the model, you can still easily see if it is getting things correct or not. Once you know you your code solves the ‘nothing happens’ transition path, then you can start solving the actual transition path you are interested in.

---

<div class="post-metadata">

### Author: ![Shiki](https://discourse.vfitoolkit.com/letter_avatar_proxy/v4/letter/s/5fc32e/32.png) [@Shiki](https://discourse.vfitoolkit.com/u/Shiki)
#### Post date: [August 20, 2026, 12:01am UTC](https://discourse.vfitoolkit.com/t/olg-transition-path-error/314/32 "2026-08-20T00:01:24Z")

</div>

Hi Robert,

recently I tried to redo the OLG transition path (using OLG Model 6 Stochastic OLG Model as the basic framework to analyze the change of [parameter alpha). I got the following error message:

> Error using gpuArray/reshape  
> Sparse gpuArray matrices are not supported for this function.  
> Error in AgentDist\_FHorz\_TPath\_SingleStep\_IterFast\_raw (line 21)  
> AgentDist\_tt=reshape(Gammatranspose\*AgentDist\_tt,[N\_a,(N\_j-1)\*N\_z]);

> Error in AgentDistOnTransPath\_Case1\_FHorz (line 632)  
> AgentDist=AgentDist\_FHorz\_TPath\_SingleStep\_IterFast\_raw(AgentDist,Policy\_aprimejz,N\_a,N\_z,N\_j,pi\_z\_J\_sim,II1,II2,exceptlastj,exceptfirstj,justfirstj,jequaloneDist);

> Error in transition\_test (line 218)  
> AgentDistPath=AgentDistOnTransPath\_Case1\_FHorz(StationaryDist\_init, jequaloneDist, PricePath, ParamPath, PolicyPath, AgeWeightParamNames,n\_d,n\_a,n\_z,N\_j,pi\_z,T,Params, transpathoptions, simoptions);

I use the following codes to calculate the path. It can generate the figure of the interest rate path, but not the agg variable K. I think they worked before.

> T=50;  
> ParamPath.alpha=0.4\* ones(T,1);  
> PricePath0.r=[linspace(p\_eqm\_init.r, p\_eqm\_final.r, floor(T/2))‘; p\_eqm\_final.r\* ones(T-floor(T/2),1)];  
> PricePath0.AccidentBeq=[linspace(p\_eqm\_init.AccidentBeq, p\_eqm\_final.AccidentBeq, floor(T/2))’; p\_eqm\_final.AccidentBeq_ones(T-floor(T/2),1)];  
> TransPathGeneralEqmEqns.capitalmarket = @(r,K,L,alpha,delta,A) r-alpha_ A\* (K^(alpha-1))\* (L^(1-alpha));  
> TransPathGeneralEqmEqns.bequests = @(AccidentalBeqLeft,AccidentBeq,n) AccidentalBeqLeft/(1+n)-AccidentBeq;

> vfoptions.divideandconquer=1;  
> vfoptions.level1n=11;  
> vfoptions.fastOLG=1;  
> transpathoptions.weightscheme=1;  
> transpathoptions.verbose=1;  
> transpathoptions.GEnewprice=3;  
> transpathoptions.GEnewprice3.howtoupdate={…  
> ‘capitalmarket’,‘r’,0,0.03;…  
> ‘bequests’,‘AccidentBeq’,1,0.05;…  
> };

> PricePath=TransitionPath\_Case1\_FHorz(PricePath0, ParamPath, T, V\_final, StationaryDist\_init, jequaloneDist,n\_d, n\_a, n\_z, N\_j, d\_grid,a\_grid,z\_grid, pi\_z, ReturnFn, FnsToEvaluate, TransPathGeneralEqmEqns, Params, DiscountFactorParamNames, AgeWeightParamNames, transpathoptions, simoptions, vfoptions);

> figure(1)  
> plot(0:1:T, [p\_eqm\_init.r,PricePath.r])  
> title(‘interest rate path for transtion’)

> [VPath,PolicyPath]=ValueFnOnTransPath\_Case1\_FHorz(PricePath, ParamPath, T, V\_final, Policy\_final, Params, n\_d, n\_a, n\_z, N\_j, d\_grid, a\_grid,z\_grid, pi\_z, DiscountFactorParamNames, ReturnFn, transpathoptions, vfoptions);

> AgentDistPath=AgentDistOnTransPath\_Case1\_FHorz(StationaryDist\_init, jequaloneDist, PricePath, ParamPath, PolicyPath, AgeWeightParamNames,n\_d,n\_a,n\_z,N\_j,pi\_z,T,Params, transpathoptions, simoptions);  
> AggVarsPath=EvalFnOnTransPath\_AggVars\_Case1\_FHorz(FnsToEvaluate,AgentDistPath,PolicyPath,PricePath,ParamPath, Params, T, n\_d, n\_a, n\_z, N\_j, d\_grid, a\_grid,z\_grid,transpathoptions, simoptions);

> figure(2)  
> plot(0:1:T, [AggVars\_init.K.Mean, AggVarsPath.K.Mean])  
> title(‘path of transtion for capital’)

---

<div class="post-metadata">

### Author: ![robertdkirkby](https://discourse.vfitoolkit.com/user_avatar/discourse.vfitoolkit.com/robertdkirkby/32/287_2.png) [@robertdkirkby](https://discourse.vfitoolkit.com/u/robertdkirkby)
#### Post date: [August 20, 2026, 12:33am UTC](https://discourse.vfitoolkit.com/t/olg-transition-path-error/314/33 "2026-08-20T00:33:24Z")

</div>

> Error using gpuArray/reshape  
> Sparse gpuArray matrices are not supported for this function.

Sparse gpuArray reshape was introduced in Matlab around 2025 or so, and you must be running an earlier version, hence the error. [I run R2026 so I never see this error.]

That said, my intention is to do the AgentDist on cpu matrices (runtime penalty is minor, and amount of memory available is typically much larger releasing what can otherwise be a bottleneck). I will clean this up tomorrow sometime (hopefully) so it is done on cpu matrices instead.

---

<div class="post-metadata">

### Author: ![robertdkirkby](https://discourse.vfitoolkit.com/user_avatar/discourse.vfitoolkit.com/robertdkirkby/32/287_2.png) [@robertdkirkby](https://discourse.vfitoolkit.com/u/robertdkirkby)
#### Post date: [August 21, 2026, 5:56am UTC](https://discourse.vfitoolkit.com/t/olg-transition-path-error/314/34 "2026-08-21T05:56:30Z")

</div>

I ran a couple of tests. Using the sparse gpu arrays for agent dist, instead of sparse cpu arrays, roughly halves the run times. [Note that agent dist takes only a small fraction of total runtimes, so the overall gain is not large.]

I think I will try and add a new simoptions that lets you choose whether to do the agent dist on the gpu or cpu. Will give people a little bit more power to set what suits them best.

Will mean that it takes me a few days to fix and get this done.

---

<div class="post-metadata">

### Author: ![robertdkirkby](https://discourse.vfitoolkit.com/user_avatar/discourse.vfitoolkit.com/robertdkirkby/32/287_2.png) [@robertdkirkby](https://discourse.vfitoolkit.com/u/robertdkirkby)
#### Post date: [August 24, 2026, 5:45am UTC](https://discourse.vfitoolkit.com/t/olg-transition-path-error/314/35 "2026-08-24T05:45:00Z")

</div>

@Shiki, I’ve just pushed a fix so you can use this [[added some gather() to the commands](https://github.com/vfitoolkit/VFIToolkit-matlab/commit/9e09dec089128dcee310aec2356fd1d3f2b6a189) so they will execute on cpu]. I will come back later and set up a simoptions to choose between gpu sparse and cpu sparse when I have more time (too busy with teaching right now).

[Previous page](https://discourse.vfitoolkit.com/t/olg-transition-path-error/314.md?page=1)
