# SemiExo ValueFnIter internals question

**URL:** https://discourse.vfitoolkit.com/t/semiexo-valuefniter-internals-question/673
**Category:** Uncategorized
**Created:** [June 13, 2026, 5:49pm UTC](https://discourse.vfitoolkit.com/t/semiexo-valuefniter-internals-question/673 "2026-06-13T17:49:49Z")
**Posts on this page:** 2
**Page:** 1

<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: [June 13, 2026, 5:49pm UTC](https://discourse.vfitoolkit.com/t/semiexo-valuefniter-internals-question/673/1 "2026-06-13T17:49:49Z")

</div>

Today I find myself looking at `ValueFnIter_FHorz_RiskyAssetSemiExo_nod1_raw.m` and in particular, the fact that `EV` changes shape during the iterations in ways I haven’t seen before.

At line 262 (or thereabouts) we see

```auto
    EV=V(:,:,jj+1);

```

which is typical. A few lines later (inside the `d4 loop`) we see `EV` expanded by the transition matrix:

```auto
            EV=EV.*shiftdim(pi_bothz',-1);

```

which is still typical (simpler expansions such as `ValueFnIter_FHorz_raw.m` use `pi_z_J`).

When we look at the `V_Jplus1` case, we see what we expect: `EV` is derived from `V_Jplus1.*shiftdim(pi_bothz',-1)` on each iteration of the `d4` loop, meaning that all sorts of reshaping of `EV` later in the loop doesn’t come back to bite us.

However, as we iterate backwards through `j`, `EV` starts as we expect and is then reshaped on the first iteration of the `d4` loop to sometime quite larger that we then have to deal with on subsequent iterations. One thing that makes me suspicious are the tantalizing comments copy-pasted from the `V_Jplus1` case that are irrelevant to loops not using `V_Jplus1` at all. But if those comments have a shred of truth about how `EV` could be initialized or refined at the end of the loop so as to return to some smaller dimensions before going through its expansionary phase, it might indicate an optimization opportunity. If not, it would be helpful to fix the comments.

---

<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 14, 2026, 5:57am UTC](https://discourse.vfitoolkit.com/t/semiexo-valuefniter-internals-question/673/2 "2026-06-14T05:57:07Z")

</div>

I have added RiskyAsset to the [toolkit tests](https://github.com/vfitoolkit/vfitoolkitTests). But I haven’t yet got it running (everything else in tests all runs smoothly). I plan to do this in July.

If you spot a known bug, feel free to set up a pull request, but otherwise will wait until July and then get them all going properly. Right now riskyasset is very much the neglected cousin in the toolkit. Everything else has been getting the focus and polish over the last month.
