Skip to content

Commit

Permalink
fixing ConsIndShock and Lifecycle examples #943
Browse files Browse the repository at this point in the history
  • Loading branch information
sbenthall committed Feb 9, 2021
1 parent cde52b0 commit 4e0d3e7
Show file tree
Hide file tree
Showing 9 changed files with 516 additions and 238 deletions.
231 changes: 231 additions & 0 deletions examples/ConsIndShockModel/Finite Cyclical Test.ipynb

Large diffs are not rendered by default.

144 changes: 28 additions & 116 deletions examples/ConsIndShockModel/IndShockConsumerType.ipynb

Large diffs are not rendered by default.

89 changes: 69 additions & 20 deletions examples/ConsIndShockModel/KinkedRconsumerType.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions examples/ConsIndShockModel/KinkedRconsumerType.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
# format_version: '1.2'
# jupytext_version: 1.2.4
# kernelspec:
# display_name: Python 3
# display_name: econ-ark-3.8
# language: python
# name: python3
# name: econ-ark-3.8
# ---

# %% [markdown]
Expand Down Expand Up @@ -214,7 +214,7 @@
# Now let's plot the distribution of (normalized) assets $a_t$ for the current population, after simulating for $500$ periods; this should be fairly close to the long run distribution:

# %%
plt.plot(np.sort(KinkyExample.state_now['aNrmNow']), np.linspace(0.0, 1.0, KinkyExample.AgentCount))
plt.plot(np.sort(KinkyExample.state_now['aNrm']), np.linspace(0.0, 1.0, KinkyExample.AgentCount))
plt.xlabel("End-of-period assets")
plt.ylabel("Cumulative distribution")
plt.ylim(-0.01, 1.01)
Expand Down
62 changes: 46 additions & 16 deletions examples/ConsIndShockModel/PerfForesightConsumerType.ipynb

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions examples/ConsIndShockModel/PerfForesightConsumerType.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
# format_version: '1.2'
# jupytext_version: 1.2.4
# kernelspec:
# display_name: Python 3.7 econ-ark
# display_name: econ-ark-3.8
# language: python
# name: econ-ark
# name: econ-ark-3.8
# ---

# %% [markdown]
Expand Down Expand Up @@ -285,10 +285,12 @@
# %% pycharm= {"name": "#%%\n"}
PFexample.initializeSim()
PFexample.simulate(80)
PFexample.state_prev['aNrmNow'] += -5.0 # Adjust all simulated consumers' assets downward by 5
PFexample.state_prev['aNrm'] += -5.0 # Adjust all simulated consumers' assets downward by 5
PFexample.simulate(40)

plt.plot(np.mean(PFexample.history['mNrm'], axis=1))
plt.xlabel("Time")
plt.ylabel("Mean normalized market resources")
plt.show()

# %%
90 changes: 39 additions & 51 deletions examples/ConsumptionSaving/example_ConsIndShock.ipynb

Large diffs are not rendered by default.

102 changes: 84 additions & 18 deletions examples/LifecycleModel/LifecycleModel.ipynb

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions examples/LifecycleModel/LifecycleModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
# extension: .py
# format_name: percent
# format_version: '1.2'
# jupytext_version: 1.2.3
# jupytext_version: 1.2.4
# kernelspec:
# display_name: Python 3
# display_name: econ-ark-3.8
# language: python
# name: python3
# name: econ-ark-3.8
# language_info:
# codemirror_mode:
# name: ipython
Expand All @@ -22,7 +22,7 @@
# name: python
# nbconvert_exporter: python
# pygments_lexer: ipython3
# version: 3.7.6
# version: 3.8.7
# ---

# %% [markdown]
Expand Down Expand Up @@ -80,7 +80,7 @@
LifeCyclePop.unpack('cFunc') # Expose the consumption rules

# Which variables do we want to track
LifeCyclePop.track_vars = ['aNrmNow','pLvl','mNrm','cNrm','TranShkNow']
LifeCyclePop.track_vars = ['aNrm','pLvl','mNrm','cNrm','TranShk']

LifeCyclePop.T_sim = 120 # Nobody lives to be older than 145 years (=25+120)
LifeCyclePop.initializeSim() # Construct the age-25 distribution of income and assets
Expand Down Expand Up @@ -130,7 +130,7 @@ def savingRateFunc(SomeType, m):

for t in range(1,LifeCyclePop.T_cycle+1):
#aLvlGro_hist[0] = 0 # set the first growth rate to 0, since there is no data for period 0
aLvlGroNow = np.log(LifeCyclePop.history['aNrmNow'][t]/LifeCyclePop.history['aNrmNow'][t-1]) # (10000,)
aLvlGroNow = np.log(LifeCyclePop.history['aNrm'][t]/LifeCyclePop.history['aNrm'][t-1]) # (10000,)

# Call the saving rate function with test value for
SavingRate = savingRateFunc(LifeCyclePop, LifeCyclePop.history['mNrm'][t] )
Expand All @@ -140,10 +140,10 @@ def savingRateFunc(SomeType, m):
# Create elements of matrix list
matrix_list = [0 for number in range(7)]
matrix_list[0] = t
matrix_list[1] = LifeCyclePop.history['aNrmNow'][t]
matrix_list[1] = LifeCyclePop.history['aNrm'][t]
matrix_list[2] = LifeCyclePop.history['cNrm'][t]
matrix_list[3] = LifeCyclePop.history['TranShkNow'][t]
matrix_list[4] = LifeCyclePop.history['TranShkNow'][t-1]
matrix_list[3] = LifeCyclePop.history['TranShk'][t]
matrix_list[4] = LifeCyclePop.history['TranShk'][t-1]
matrix_list[5] = aLvlGroNow
matrix_list[6] = SavingRate

Expand All @@ -155,8 +155,8 @@ def savingRateFunc(SomeType, m):

# %% {"code_folding": [0]}
# Construct the level of assets A from a*p where a is the ratio to permanent income p
LifeCyclePop.history['aLvlNow'] = LifeCyclePop.history['aNrmNow']*LifeCyclePop.history['pLvl']
aGro41=LifeCyclePop.history['aLvlNow'][41]/LifeCyclePop.history['aLvlNow'][40]
LifeCyclePop.history['aLvl'] = LifeCyclePop.history['aNrm']*LifeCyclePop.history['pLvl']
aGro41=LifeCyclePop.history['aLvl'][41]/LifeCyclePop.history['aLvl'][40]
aGro41NoU=aGro41[aGro41[:]>0.2] # Throw out extreme outliers


Expand Down

0 comments on commit 4e0d3e7

Please sign in to comment.