# Deterministic Simulation Non-Convergence

**URL:** <https://forum.dynare.org/t/deterministic-simulation-non-convergence/12199>\
**Category:** Perfect foresight simulations\
**Created:** [31 July 2018 14:11 UTC](https://forum.dynare.org/t/deterministic-simulation-non-convergence/12199 "2018-07-31T14:11:05Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![M.No](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@M.No](https://forum.dynare.org/u/M.No)\
**Post date:** [31 July 2018 14:11 UTC](https://forum.dynare.org/t/deterministic-simulation-non-convergence/12199/1 "2018-07-31T14:11:05Z")

</div>

I have a model, building on Ghironi and Melitz (2005) where the stochastic simulation solve with no issues, and produces sensible responses, but with the deterministic simulation, no matter how many periods I try to simulate over (I’ve tried up to 20000), the results do not converge with any size of shock \>0.

Model\_Diagnostics detects no obvious problems with the mod file, and the B-K conditions are satisfied (both rank and eigenvalues\>1=forward looking variables).

I’ve tried reducing the model down to its most simple form possible, with no improvements.

Any help would be much appreicated.

[MNInterW.mod](https://forum.dynare.org/uploads/default/original/2X/9/99cf2f94a962cf1021828f759244050ab16250db.mod) (23.8 KB)

---

<div class="post-metadata">

**Author:** ![stepan-a](https://forum.dynare.org/user_avatar/forum.dynare.org/stepan-a/32/6652_2.png) [@stepan-a](https://forum.dynare.org/u/stepan-a)\
**Post date:** [31 July 2018 17:00 UTC](https://forum.dynare.org/t/deterministic-simulation-non-convergence/12199/2 "2018-07-31T17:00:13Z")

</div>

At least one file is missing. The code is crashing because `WorkingSteady.mat` is missing.

Best,  
Stéphane.

---

<div class="post-metadata">

**Author:** ![M.No](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@M.No](https://forum.dynare.org/u/M.No)\
**Post date:** [1 August 2018 07:16 UTC](https://forum.dynare.org/t/deterministic-simulation-non-convergence/12199/3 "2018-08-01T07:16:41Z")

</div>

Apologies, here is the code without the call to an external file:  
[MNInterW.mod](https://forum.dynare.org/uploads/default/original/2X/b/bb1c33e0e41bde705afa199cc4346cf96e62d1e9.mod) (23.3 KB)

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [2 August 2018 15:13 UTC](https://forum.dynare.org/t/deterministic-simulation-non-convergence/12199/4 "2018-08-02T15:13:22Z")

</div>

Have you tried what happens with very small shocks? Does it work then?

---

<div class="post-metadata">

**Author:** ![M.No](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@M.No](https://forum.dynare.org/u/M.No)\
**Post date:** [2 August 2018 15:44 UTC](https://forum.dynare.org/t/deterministic-simulation-non-convergence/12199/5 "2018-08-02T15:44:10Z")

</div>

I’ve tried with very small shocks and the simulation still fails to converge - homotopy fails as well - the only stage of the homotopy that ‘suceeds’ is when the shock size is small enough that dynare treats it as 0 when solving the model. e.g for a 0.1% shock to TFP in one industry this is the output (with maxit =10, given that the error doesn’t change after iteration 3):

MODEL SIMULATION:

Iter: 1, err. = 0.0001, time = 1.805  
WARNING : Failed to find a solution to the linear system.  
Iter: 2, err. = 0.00022364, time = 0.529  
WARNING : Failed to find a solution to the linear system.  
Iter: 3, err. = 0.00022365, time = 0.551  
WARNING : Failed to find a solution to the linear system.  
Iter: 4, err. = 0.00022365, time = 0.516  
WARNING : Failed to find a solution to the linear system.  
Iter: 5, err. = 0.00022365, time = 0.377  
WARNING : Failed to find a solution to the linear system.  
Iter: 6, err. = 0.00022365, time = 0.339  
WARNING : Failed to find a solution to the linear system.  
Iter: 7, err. = 0.00022365, time = 0.34  
WARNING : Failed to find a solution to the linear system.  
Iter: 8, err. = 0.00022365, time = 0.411  
WARNING : Failed to find a solution to the linear system.  
Iter: 9, err. = 0.00022365, time = 0.358  
WARNING : Failed to find a solution to the linear system.  
Iter: 10, err. = 0.00022365, time = 0.37  
WARNING : Failed to find a solution to the linear system.

## Total time of simulation: 21.293. Maximum number of iterations is reached (modify option maxit).

Simulation of the perfect foresight model failed!  
Switching to a homotopy method…

Iter. | Lambda | status | Max. residual  
++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
1 | 0.50000 | failed | 5.000000e-05  
2 | 0.25000 | failed | 2.500000e-05  
3 | 0.12500 | failed | 1.250000e-05  
4 | 0.06250 | succeeded | 6.250000e-06  
5 | 0.12500 | failed | 1.250000e-05  
6 | 0.09375 | succeeded | 9.375000e-06  
7 | 0.12500 | failed | 1.250000e-05  
8 | 0.10938 | failed | 1.093750e-05  
9 | 0.10156 | failed | 1.015625e-05  
10 | 0.09766 | succeeded | 9.765625e-06  
11 | 0.10156 | failed | 1.015625e-05  
12 | 0.09961 | succeeded | 9.960938e-06  
13 | 0.10156 | failed | 1.015625e-05  
14 | 0.10059 | failed | 1.005859e-05  
15 | 0.10010 | failed | 1.000977e-05  
16 | 0.09985 | succeeded | 9.985352e-06  
17 | 0.10010 | failed | 1.000977e-05  
18 | 0.09998 | succeeded | 9.997559e-06  
19 | 0.10010 | failed | 1.000977e-05  
20 | 0.10004 | failed | 1.000366e-05  
21 | 0.10001 | failed | 1.000061e-05  
22 | 0.09999 | succeeded | 9.999084e-06  
23 | 0.10001 | failed | 1.000061e-05  
++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Failed to solve perfect foresight model

As soon as homotopy trys a lambda of 0.1 or greater, the step fails.

I’ve also tried very small shocks to each of the exogenous variables on their own, and again the simulation fails to converge.

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [11 August 2018 11:43 UTC](https://forum.dynare.org/t/deterministic-simulation-non-convergence/12199/6 "2018-08-11T11:43:14Z")

</div>

That is strange. Could you please provide the most recent version of the file?

---

<div class="post-metadata">

**Author:** ![M.No](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@M.No](https://forum.dynare.org/u/M.No)\
**Post date:** [13 August 2018 07:59 UTC](https://forum.dynare.org/t/deterministic-simulation-non-convergence/12199/7 "2018-08-13T07:59:48Z")

</div>

I have manged to work around the issue, by using a slightly different approach to the derivation of the model, so the file posted above is still the most recent version of the model with this issue. However, I am still unclear as to the theoretical reason why a model would run stochastically, and fullfil all of the BK conditions, and yet not converge deterministically, even with a large number of periods and very small shocks.

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [18 August 2018 15:21 UTC](https://forum.dynare.org/t/deterministic-simulation-non-convergence/12199/8 "2018-08-18T15:21:28Z")

</div>

I also do not understand how this can happen. @stepan-a @MichelJuillard Do you have any idea?

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [16 November 2018 11:10 UTC](https://forum.dynare.org/t/deterministic-simulation-non-convergence/12199/9 "2018-11-16T11:10:33Z")

</div>

The problem in your model is that the Jacobian of the contemporaneous endogenous variables is singular. This is not a problem for the stochastic solver, but it is a problem for the way the perfect foresight simulations are conducted.

---

<div class="post-metadata">

**Author:** ![fuyangzhao](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/41988e/32.png) [@fuyangzhao](https://forum.dynare.org/u/fuyangzhao)\
**Post date:** [17 March 2021 03:03 UTC](https://forum.dynare.org/t/deterministic-simulation-non-convergence/12199/10 "2021-03-17T03:03:33Z")

</div>

Dear Prof Pfeifer,  
I encounter similar problem. It works fine under stochastic case. But perfect foresight simulations always fail.  
Could you be more specific about “Singularity of Jacobian of the contemporaneous endogenous variables”? How can I avoid such singularity?

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [17 March 2021 10:56 UTC](https://forum.dynare.org/t/deterministic-simulation-non-convergence/12199/11 "2021-03-17T10:56:41Z")

</div>

See [Perfect foresight simulation always failed](https://forum.dynare.org/t/perfect-foresight-simulation-always-failed/17651)

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [17 March 2021 14:05 UTC](https://forum.dynare.org/t/deterministic-simulation-non-convergence/12199/12 "2021-03-17T14:05:23Z")

</div>

For future reference, the `debug`-option should be able to provide some insights starting with Dynare 4.7.  
See [perfect foresight: provide debugging information for singular Jacobian (!1834) · Merge Requests · Dynare / dynare · GitLab](https://git.dynare.org/Dynare/dynare/-/merge_requests/1834)

---

<div class="post-metadata">

**Author:** ![fuyangzhao](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/41988e/32.png) [@fuyangzhao](https://forum.dynare.org/u/fuyangzhao)\
**Post date:** [18 March 2021 00:41 UTC](https://forum.dynare.org/t/deterministic-simulation-non-convergence/12199/13 "2021-03-18T00:41:54Z")

</div>

I saw. Thank you so much!
