sbenthall / SHARKFin

Simulating Heterogeneous Agents with Finance
6 stars 5 forks source link

AgentPopulation solution is sometimes returning a negative RiskyShare #160

Closed sbenthall closed 1 year ago

sbenthall commented 1 year ago

Under some conditions, the AgentPopulation solution's ShareFunc is returning a negative risky share from its ShareFunc.

Since we use this value to create the agents' target value of share ownership, this wreaks havoc on the simulation.

This is one way to reproduce the error with some standard scripts:

https://gist.github.com/sbenthall/d0b4b581c683a0e3bd0e10b59dd4011d

sbenthall commented 1 year ago

Please include an automated unit test along with the fix for this issue. A failing test that reproduces this error under simple, isolated conditions is a good contribution in its own right, as right now it's hard to know under what conditions the solution function has this error.

alanlujan91 commented 1 year ago
(sharkfin-dev) C:\Users\alujan\GitHub\alanlujan91\SHARKFin>python simulate/run_any_simulation.py --simulation Attention --seed 790 --quarters 3 --attention 0.99 --dphm 1500000 --p1 0.1 --p2 .1 --dividend_growth_rate 1.002 output/20221006_ras_d
Traceback (most recent call last):
  File "C:\Users\alujan\GitHub\alanlujan91\SHARKFin\simulate\run_any_simulation.py", line 10, in <module>
    from simulate.parameters import (
ModuleNotFoundError: No module named 'simulate'

How do I set this up?

sbenthall commented 1 year ago

Did you go through the installation steps in the README?

(If you did, and are still getting this error, that's a documentation problem I'll need to fix)

alanlujan91 commented 1 year ago

Yes, and can run tests locally and they all pass. but can't seem to run a simulation on command line

sbenthall commented 1 year ago

Dang. Try git pull master to get the most recent commit and then running the script again.

alanlujan91 commented 1 year ago

The trouble seems to be my environment not recognizing the subdirectory simulate as a module. This subdirectory is outside of the sharkfin subdirectory.

sbenthall commented 1 year ago

I agree with your analysis. I've made another change. Try:

alanlujan91 commented 1 year ago

great, that worked, I'll look into the bug now

sbenthall commented 1 year ago

This error happens sometimes when agents extrapolate RiskyShare solutions beyond the grid for which these functions have been evaluated.

A temporary fix, which is increasing the size of the solution grid to capture a broader span of values, has been implemented in #161. Documenting this issue is #162 .

There are several more robust solutions, which are now in other tickets: