# Default vfoptions for VFI

**URL:** https://discourse.vfitoolkit.com/t/default-vfoptions-for-vfi/579
**Category:** Uncategorized
**Created:** [January 26, 2026, 7:01pm UTC](https://discourse.vfitoolkit.com/t/default-vfoptions-for-vfi/579 "2026-01-26T19:01:52Z")
**Posts on this page:** 15
**Page:** 1

<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 26, 2026, 7:01pm UTC](https://discourse.vfitoolkit.com/t/default-vfoptions-for-vfi/579/1 "2026-01-26T19:01:52Z")

</div>

I would like to review some parameter choices for default settings in VFI, `ValueFnIter_Case1`.

I noticed that `vfoptions.maxiter=Inf;` Not sure this is a good choice. With Howard improvement, usually if the VFI does not converge after, say, 100 iterations, then there is probably a bug or something wrong with the model. I realized this while doing a GE search. At some point the GE got stuck and I found that it had got stuck in the VFI. So I set the max no of iterations equal to 100 and it hit the upper bound. Luckily, the distance was about 0.0000001162 but still larger than the tolerance.  
So I have two proposals:

- Set the default for maxiter equal to something like 100 or 500 or 1000, but **certainly not Inf**!
- Make the VFI display a warning (not an error) if the iteration limit is reached. This is **really important** to find potential bugs

```auto
if currdist>Tolerance
    fprintf('Total no. of VF iter: %d \n',tempcounter-1)
    fprintf('currdist: %.10f \n',currdist)
    warning('VFI has not converged successfully!')
end

```

Thanks!

**Update**  
I checked the code for the distribution and it is fine. There is a sensible upper limit `simoptions.maxit=10^6`, and a warning is displayed if convergence fails.

---

<div class="post-metadata">

### Author: ![MichaelTiemann](https://discourse.vfitoolkit.com/user_avatar/discourse.vfitoolkit.com/michaeltiemann/32/220_2.png) [@MichaelTiemann](https://discourse.vfitoolkit.com/u/MichaelTiemann)
#### Post date: [January 26, 2026, 7:48pm UTC](https://discourse.vfitoolkit.com/t/default-vfoptions-for-vfi/579/2 "2026-01-26T19:48:17Z")

</div>

As I mentioned elsewhere, the bug in convergence is likely due to an error in the ReturnMatrix, specifically the value -Inf (which Howards-greedy doesn’t handle). I have a PR pending that checks for that condition and gives an error. It looks like this:

```auto
        if any(~isfinite(Ftemp))
            error("Howards-greedy doesn't work for non-finite return values; rerun with `vfoptions.howardsgreedy=0;`")
        end

```

Robert also committed changes that make `vfoptions.howardsgreedy==0` the default, which might also protect you from errors. If you observe a failure to converge with normal Howards improvement, it’s likely an error that should be reported so it can be fixed or diagnosed in better ways.

I also agree that setting `vfoptions.maxiter=Inf` is a bit aggressive. Hmm…

---

<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 26, 2026, 9:08pm UTC](https://discourse.vfitoolkit.com/t/default-vfoptions-for-vfi/579/3 "2026-01-26T21:08:33Z")

</div>

> [@MichaelTiemann](#):
>
> to an error in the ReturnMatrix, specifically the value -Inf (which Howards-greedy doesn’t handle).

This is an important point, but I’m not sure I fully understand.

Let’s conside the case without a d variable: the return matrix is the 3-dimensional array F(a',a,z). In most cases, it will have lots of -Inf corresponding to combinations of (a',a,z) that violate feasibility. The Howard algorithm iterates on the Bellman equation “fixing” the optimal policy, that is,

$  
V\_{n+1}(a,z) = F(g(a,z),a,z)+\beta \sum\_{z’} V\_n(g(a,z),z’) \pi(z,z’)  
$

where g is the policy function for the future endogenous state a'. Clearly, if F(g(a,z),a,z)=- \infty for some (a,z), this is a problem: it means that there are no feasible choices for that particular (a,z) in the state space. In the context of the textbook consumption-savings problem, it means that the optimal value of savings a' gives negative consumption.

Therefore, if the model is well-specified, cases where F(g(a,z),a,z)=- \infty should never happen. Please let me know if I miss something.

---

<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 26, 2026, 11:28pm UTC](https://discourse.vfitoolkit.com/t/default-vfoptions-for-vfi/579/4 "2026-01-26T23:28:10Z")

</div>

> [@aledinola](#):
>
> Therefore, if the model is well-specified, cases where F(g(a,z),a,z)=- \infty should never happen.

True. But VFI Toolkit does not require the model to be “well-specified” in this sense. Reason is that it is easier to just let the user solve the model without having to go through all the work of making the model well specified.

Some examples:  
(i) you want to solve a firm model where zero assets give -Inf, is easier if you can still set up a\_grid to have 0 in it, without having to only allow tiny asset values.  
(ii) a model with an endogenous borrowing constraint that will be determined in eqm. You can set up a\_grid=-10:1:100, and then in general eqm it turns out that the borrowing limit is -5, so the values for assets of -10 to -6 will all give -Inf (depends a bit but you get the idea).  
Of course in both cases it is possible to set up the model so that it is well-specified and this won’t happen (in the first case it is trivial). But often it is just easier to solve the model than to put in the work to get it well-specified. Specifically the runtime losses from not setting it to be well-specified can be much smaller than the amount of work it would require to convert to a well-specified model.

Hence why the toolkit is designed to handle the model even if it is not well-specified and gets V=-Inf at some points in the state space.

---

<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 27, 2026, 12:23am UTC](https://discourse.vfitoolkit.com/t/default-vfoptions-for-vfi/579/5 "2026-01-27T00:23:53Z")

</div>

Just pushed to github.

Changed default to `vfoptions.maxiter=10^4`

Added warnings when ends because you reach max iterations, rather than convergence.

Added warnings to Howards-greedy when any(~isfinite(Ftemp)), where Ftemp is F(g(a,z),a,z). Only looks at the final iteration (not every iteration) so as to not hurt run times (hopefully just the final is sufficient). [same as Michael suggested, just at the end rather than in each iteration]

---

<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 27, 2026, 12:42am UTC](https://discourse.vfitoolkit.com/t/default-vfoptions-for-vfi/579/6 "2026-01-27T00:42:45Z")

</div>

@aledinola speaking of defaults, the default is currently

```auto
if ~isfield(vfoptions,'howardssparse')
        if N_a>1200 && N_z>100 && vfoptions.gridinterplayer==0
            vfoptions.howardssparse=1; % Do Howards iteration using a sparse matrix (rather than indexing). Sparse is only faster for bigger models.
        else
            vfoptions.howardssparse=0;
        end
    end

```

I noticed you did some more howardssparse implementations for grid interpolation layer with postGI. Could/should this default be changed now to eliminate the `&& vfoptions.gridinterplayer==0` ?

---

<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 27, 2026, 12:50am UTC](https://discourse.vfitoolkit.com/t/default-vfoptions-for-vfi/579/7 "2026-01-27T00:50:34Z")

</div>

Yes, that’s correct.

---

<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 27, 2026, 12:53am UTC](https://discourse.vfitoolkit.com/t/default-vfoptions-for-vfi/579/8 "2026-01-27T00:53:16Z")

</div>

Quick question: where do the warnings at the end show up? Do I have to update also the sparse version of Inf horizon?

---

<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 27, 2026, 1:02am UTC](https://discourse.vfitoolkit.com/t/default-vfoptions-for-vfi/579/9 "2026-01-27T01:02:09Z")

</div>

The sparse version is Howards iteration isn’t it? Only Howards Greedy needs the warning, not Howards iteration.

---

<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 27, 2026, 1:06am UTC](https://discourse.vfitoolkit.com/t/default-vfoptions-for-vfi/579/10 "2026-01-27T01:06:45Z")

</div>

> [@aledinola](#):
>
> Yes, that’s correct.

Cool. Have updated the default vfoptions.

---

<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 27, 2026, 1:13am UTC](https://discourse.vfitoolkit.com/t/default-vfoptions-for-vfi/579/11 "2026-01-27T01:13:03Z")

</div>

Yes, but I mean the warning regarding lack of convergence i.e. max iteration limit hit. Actually I saw you have already added this.

---

<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 28, 2026, 3:18pm UTC](https://discourse.vfitoolkit.com/t/default-vfoptions-for-vfi/579/12 "2026-01-28T15:18:56Z")

</div>

For the purpose of doing some tests, is there a way to disable the Howard algo in infinite horizon? My guess would be to set

vfoptions.maxhowards=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: [January 28, 2026, 5:50pm UTC](https://discourse.vfitoolkit.com/t/default-vfoptions-for-vfi/579/13 "2026-01-28T17:50:25Z")

</div>

Yes. I think even  
`vfoptions.maxhowards=0;`

This controls the maximum number of iterations during which Howards is used, after this as long as you have not yet reached vfoptions.maxiter you will continue to do standard VFI iterations just without using Howards (iteration or greedy depending on other settings).

---

<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: [June 8, 2026, 9:30am UTC](https://discourse.vfitoolkit.com/t/default-vfoptions-for-vfi/579/14 "2026-06-08T09:30:56Z")

</div>

I have found a case where the VFI did not converge in a model with

- Infinite horizon
- Refinement
- Pure discretization  
The relevant function is  
`ValueFnIter_InfHorz_nod_raw`  
The code displayed the warning

```auto
Warning: Value fn iteration has stopped due to reaching the maximum number of iterations (not due to convergence); can
be set by vfoptions.maxiter. 

```

I checked the last distance and it was very small, close to the tolerance crit of 1e-9, so I am not worried. But to find this extra information I had to debug the code. I propose to change the message in case of non convergence from the existing

```auto
if tempcounter>=maxiter
    warning('Value fn iteration has stopped due to reaching the maximum number of iterations (not due to convergence); can be set by vfoptions.maxiter.')
end

```

to the more informative

```auto
if currdist > Tolerance
    warning(['Value fn iteration has stopped due to reaching the maximum number of iterations ', ...
             '(not due to convergence); can be set by vfoptions.maxiter. ', ...
             'Last currdist = %.16g; tolerance = %.16g.'], ...
             currdist, Tolerance)
end

```

This change could be applied to other infinite horizon VFI files, of course.

To sum up, the aim of this change is the following: when the VFI does not converge, it is important to check the `currdist` and how far you are from the numerical tolerance. Sometimes you are close enough so that it is not a big concern, other times if your currdist is high, then there is something wrong.

I sent PR: [Improve infinite-horizon VFI max-iteration warnings by aledinola · Pull Request #106 · vfitoolkit/VFIToolkit-matlab · GitHub](https://github.com/vfitoolkit/VFIToolkit-matlab/pull/106)

---

<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: [June 9, 2026, 4:08am UTC](https://discourse.vfitoolkit.com/t/default-vfoptions-for-vfi/579/15 "2026-06-09T04:08:58Z")

</div>

Looks good, clean improvement. Merged 😃
