econ-ark / HARK

Heterogenous Agents Resources & toolKit
Apache License 2.0
315 stars 195 forks source link

IndexError when solving ConsPortfolioModel #1376

Open sbenthall opened 3 months ago

sbenthall commented 3 months ago

Trying to solve SequentialPortfolioConsumerType with the following parameters changed from the default:

CRRA=6.0,
DiscFac=0.9,
RiskyAvg=1.08,
RiskyStd=0.20,
PermShkStd=[0.1],
PermGroFac=[0.00],
UnempPrb=0.01
agent = SequentialPortfolioConsumerType(**agent_parameters)
agent.solve()

Results in this rather ugly and uninformative error: https://gist.github.com/sbenthall/efc4e2610b2a2fe6590d12abf49b78b4

Looks like there's no well-defined optimal share value? There probably should be a better error message for this.

mnwhite commented 3 months ago

The key bit is at the very bottom, pointing to line 681's use of np.argwhere. I haven't looked at the code around it, but my guess of what's going on there is that it's looking for the optimal portfolio share, and it does so with the following algorithm:

0) As long as the FOCs at share=0 and share=1 don't point to a corner solution... 1) Evaluate the FOC for share at a bunch of values between 0 and 1, and take the sign +/- 2) We want the FOC to be zero, which happens "between" + and - 3) Look for indices where the sign of the FOC flips from + to - 4) Grab the first one of those (there should only ever be one)

It's failing because np.argwhere is returning an empty set, so trying to grab the first element breaks. This shouldn't happen, because by the fact that we got into this section of code, we have FOC > 0 at 0 and FOC < 0 at 1, so a change in sign has to happen somewhere. I suspect the problem is PermGroFac = [0.0], which is an unexpected value in any of our models. It says that between any periods t and t+1, permanent income should be multiplied by zero: the agent earns labor income in one period and one period only. That means that projecting next period's mNrmNext = Rfree aNrmNow / (PermGroFac PermShk) = inf everywhere. That's problematic and will cause unexpected behavior.

On Thu, Feb 1, 2024 at 11:03 AM Sebastian Benthall @.***> wrote:

Trying to solve SequentialPortfolioConsumerType with the following parameters changed from the default:

CRRA=6.0, DiscFac=0.9, RiskyAvg=1.08, RiskyStd=0.20, PermShkStd=[0.1], PermGroFac=[0.00], UnempPrb=0.01

agent = SequentialPortfolioConsumerType(**agent_parameters) agent.solve()

Results in this rather ugly and uninformative error: https://gist.github.com/sbenthall/efc4e2610b2a2fe6590d12abf49b78b4

Looks like there's no well-defined optimal share value? There probably should be a better error message for this.

— Reply to this email directly, view it on GitHub https://github.com/econ-ark/HARK/issues/1376, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADKRAFOAUEWJYTU36RUKMFLYRO4FFAVCNFSM6AAAAABCVFHAQCVHI2DSMVQWIX3LMV43ASLTON2WKOZSGEYTEOBWG4YDKNI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

sbenthall commented 3 months ago

Oh, the problem is PermGroFac=[0.00],, which is of course not a 'good' value for this parameter.

On the other hand, I put that value in by mistake while playing around with things, and discovering the problem would have been easier with a more informative error.