Skip to content

Take 3: OLG Model14 mixed horizon fixes#57

Open
MichaelTiemann wants to merge 14 commits intovfitoolkit:masterfrom
MichaelTiemann:OLGModel14-mixed-horizon-fixes
Open

Take 3: OLG Model14 mixed horizon fixes#57
MichaelTiemann wants to merge 14 commits intovfitoolkit:masterfrom
MichaelTiemann:OLGModel14-mixed-horizon-fixes

Conversation

@MichaelTiemann
Copy link
Contributor

These changes allow OLGModel14 to find the equilibrium we've seen before. It remains a bit wide (equations getting to about +/- 1-6%, not three sig figs of zeros), but I don't think that's the fault of these changes.

As you will see below, I've added comments in places to make it more clear that the changes are not as big as they appear. There are also more comments in the recent individual commits making up these changes.

Current GE prices: 
	r:   0.0500 
	pension:   0.4003 
	AccidentBeq:   0.0300 
	G:   0.1001 
	w:   1.0008 
	firmbeta:   0.9822 
	D:   0.2001 
	P0:   1.0007 
	Lhscale:   0.3002 
Current aggregate variables: 
	L_h:   0.2091 
	S:   0.9748 
	PensionSpending:   0.0614 
	PayrollTaxRevenue:   0.0419 
	AccidentalBeqLeft:   0.0088 
	CapitalGainsTaxRevenue:  -0.0252 
	Output:   0.2791 
	L_f:   0.1813 
	K:   0.3584 
	DividendPaid:   0.2077 
	Sissued:   0.1561 
	CorpTaxRevenue:   0.0266 
Current GeneralEqmEqns: 
	sharemarket: -0.025199 
	labormarket: 0.027858 
	pensions: 0.019560 
	bequests: -0.021386 
	govbudget: 0.058649 
	firmdiscounting: 0.041048 
	dividends: -0.007601 
	ShareIssuance: 0.026597 
	CapitalOutputRatio: -0.052991 
Warning: The permanent type mass weights must sum to one (PTypeDistParamNames points to weights that do not sum to one) 
> In [StationaryDist_Case1_FHorz_PType](matlab:matlab.lang.internal.introspective.errorDocCallback('StationaryDist_Case1_FHorz_PType', 'C:\GitHub\VFIToolkit-matlab\StationaryDist\FHorz\PType\StationaryDist_Case1_FHorz_PType.m', 56)) ([line 56](matlab: opentoline('C:\GitHub\VFIToolkit-matlab\StationaryDist\FHorz\PType\StationaryDist_Case1_FHorz_PType.m',56,0)))
In [OLGModel14](matlab:matlab.lang.internal.introspective.errorDocCallback('OLGModel14', 'C:\GitHub\IntroToOLGModels\OLGModel14.m', 295)) ([line 295](matlab: opentoline('C:\GitHub\IntroToOLGModels\OLGModel14.m',295,0))) 
LifeCycleProfiles_FHorz_Case1_PType: Ignoring the 2-th PType, firm because it is infinite horizon 
Following are some aggregates of the model economy: 
Output: Y=    0.28 
Aggregate TFP: Y=    1.17 
Capital-Output ratio (firm side): K/Y=    1.28 
Total asset value (HH side): P*S=    1.10 
Total firm value (firm side): Value of firm= 8800.00 
Consumption-Output ratio: C/Y=    1.03 
Government-to-Output ratio: G/Y=    0.36 
Wage: w=    1.00 
Elapsed time is 1573.569201 seconds.

OLGModel14 attempts to solve a GE for households (with finite horizons) and firms (with infinite horizons).  While there are plenty of functions for solving for one type of horizon or another, we must make some accommodations for mixtures of the two.
Given there is already some code in the FHorz cases for the occasional infinite horizon, I attempted to flesh that out until the GE could be solved without throwing errors.
I took the liberty of keeping InfHorz grids named without the _J suffix, just so we'd get an error if we sent the wrong parameters to the wrong function.
I also saw what appeared to be minor drifts in the implementations of the two types of functions, and I copy/pasted what appeared to be the more elaborated code to the side that seemed to be missing it.
As an alternative to getInterpMatrix function, use the value exp(-500) as a zero-like value.  When added to any "normal" floating point value it will read as zero, and when multiplied by an +/-Inf value it will preserve the +/-Inf value instead of converting it to NaN (which happens when multiplied by actual zero).

Also, give a warning when Howards-greedy is given a `ReturnMatrix` containing an infinite value (it cannot handle that).  And clean up some typos we found.
Return to resolving OLGModel14 changes needed to run.  To wit:

HeteroAgentStationaryEqm_Case1_FHorz_PType: add some clarifying comments about how we have moved code around to reduce duplication between FHorz and InfHorz cases that can be mixed together (as OLGModel14 does).

HeteroAgentStationaryEqm_Case1_PType: Mostly clean and comment.  Also remove error message related to no implemented functionality.  Is it now implemented?

ValueFnIter_nod_HowardGreedy_raw: if we should call this function without ever evaluating the return function (because `maxiter` was zero or some such, then `Ftemp` would never have been initialized.  I restored the test for non-finite values inside the loop because testing a matrix that's `n_a` by `n_z` is relatively cheap, and it's very valuable for people to see the moment the bad value pops up (for easier debugging).
MichaelTiemann added a commit to MichaelTiemann/OLG-Electrify that referenced this pull request Feb 8, 2026
Adapted changes from ElectrifyHousehold into Electrify (the OLG model).  Requires this  Pull Request to work: vfitoolkit/VFIToolkit-matlab#57
In my particular case, the toolkit was trying to allocate overly large arrays when `lowmemory==2` was selected.  Specifically:

```
DiscountedEV=DiscountFactorParamsVec*repelem(EV,N_d1,N_a1,1);
```

Replicated a large `EV` N_d1 times N_a1 times is unnecessary, as the loop for `lowmemory==2` doesn't use all of EV, but iterates across the `z`s (as well as the `e`s.

I noticed that other ExpAsset codes already had the fixes I am proposing herein (namely, replicate based on `EV(:,:,z_c)` rather than all of EV and then selecting the `z` elements from that).  I also noticed that other codes had optimizations like lifting some array constructions out of loops, etc.  I attempted to therefore coalesce the best of all across all in this directory.  There's obviously more work to be done for more code cases, but I thought I'd start with this bite-sized chunk.

Normally I'd create a fresh branch for these changes and a clean pull request.  But I need these changes in the OLGModel14-mixed-horizon-fixes branch, which might need a while before its merged.  So I'm leaving it to you to decide whether you want to `git cherry-pick` this commit and merge into the main branch ahead of that decision.
This change implements support for CustomModelStats when `heteroagentoptions` has PType specifiers (i.e., `heteroagentoptions.household.CustomModelStats`).  In this implementation, we can support CustomModelStats for each different PType, separately.  This is a simple case because each PType is only either FHorz or InfHorz.

It does not yet support a overarching PType implementation whereby a single CustomModelStats can see all PTypes at once.  This case is more difficult, as different PTypes can have different horizons, thus a universal CustomModelStats function would have to unpack that before calling magical subfunctions.
@robertdkirkby
Copy link
Contributor

Is it possible to split this pull request into parts?

I am happy to merge the changes to:
LifeCycleProfiles_FHorz_Case1_PType
ValueFnIter_nod_HowardGreedy_raw

But I want to take some more time to look over the others.

If you can put this two as a separate pull request I am happy to just merge that directly.

@MichaelTiemann
Copy link
Contributor Author

I can look at doing so when I return from a trip in about a week's time. I don't have a computer I can use for this purpose while I'm travelling, alas.

@MichaelTiemann
Copy link
Contributor Author

See PR #61 and PR #62.

@MichaelTiemann MichaelTiemann changed the title Take 2: OLG Model14 mixed horizon fixes Take 3: OLG Model14 mixed horizon fixes Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants