Bug in HeteroAgentStationaryEqm_InfHorz

I ran into a small issue using heteroagentoptions.constrainAtoB in HeteroAgentStationaryEqm_InfHorz.

In this GE solver path, the code checks

prod(heteroagentoptions.constrainAtoB)

before converting name-based constraints like {'tau_c'} into numeric indicator vectors. Since constrainAtoB is still a cell array at that point, MATLAB errors with:

Error using prod
Invalid data type. First argument must be numeric or logical.

This differs from some calibration/estimation paths where name-based constraints are converted before use. A small fix would be to either convert constrainAtoB before the prod(...) check, or replace that check with something that handles cell arrays, e.g. ~isempty(...) before conversion.

1 Like

Some comments need to be fixed as well

heteroagentoptions.constrainpositive={}; % names of parameters to constrained to be positive (gets converted to binary-valued vector below)
    heteroagentoptions.constrain0to1={}; % names of parameters to constrained to be positive (gets converted to binary-valued vector below)
    heteroagentoptions.constrainAtoB={}; % names of parameters to constrained to be positive (gets converted to binary-valued vector below)

By the way, to generate the error message, just add bounds to r in general equilibrium in the Aiyahari example

If you try this in the Aiyagari example, you will get an error

GEPriceParamNames = {'r'};

Params.r = 0.03;   % Initial guess, must lie strictly inside the bounds

heteroagentoptions.constrainAtoB = {'r'};
heteroagentoptions.constrainAtoBlimits = [-0.02, 0.08];

The error is

Error using prod
Invalid data type. First argument must be numeric or logical.

Should be fixed (bug + comments). Thanks for letting me know.

I built some tests for stationary general eqm commands as part of fixing

3 Likes