示例#1
0
dr = time_iteration(hmodel.agent, maxit=100, verbose=True)
sol = improved_time_iteration(hmodel.agent, dr0=dr, verbose=True)
dr = sol.dr

# %%

from dolo.algos.ergodic import ergodic_distribution

μ = ergodic_distribution(hmodel.agent, dr)[1]

from matplotlib import pyplot as plt

plt.plot(μ.data.ravel())

# %%

from dolark.equilibrium import find_steady_state

eq = find_steady_state(hmodel, verbose=True, dr0=dr)

# %%

from matplotlib import pyplot as plt

plt.plot(eq.μ)

# %%

# %%
示例#2
0
def test_steady_state_non_ex_ante_ha():
    hmodel = HModel("ayiagari.yaml")
    eq = find_steady_state(hmodel)
    hmodel = HModel("bfs_2017.yaml")
    eq = find_steady_state(hmodel)
示例#3
0
groot("examples")

from dolark import HModel

# %%
hmodel1 = HModel("ayiagari.yaml")
print(hmodel1.name)

hmodel2 = HModel("ayiagari_betadist.yaml")
print(hmodel2.name)

hmodel3 = HModel("bfs_2017.yaml")
print(hmodel3.name)
# %%
eq1 = find_steady_state(hmodel1)
eq2 = find_steady_state(hmodel2)
eq3 = find_steady_state(hmodel3)
# %%
hmodel = HModel("prototype.yaml")
eq = find_steady_state(hmodel)
# %%
# Decision rules
# Aiyagari
from matplotlib import pyplot as plt

s = eq1.dr.endo_grid.nodes
plt.plot(s, eq1.dr(0, s), color="black")
plt.plot(s, s, linestyle="--", color="black")
# %%
# Aiyagari with beta
示例#4
0
def test_steady_state_ex_ante():
    hmodel = HModel("ayiagari_betadist.yaml")
    eq = find_steady_state(hmodel)
示例#5
0
def test_with_agg_states():
    hmodel = HModel("prototype.yaml")
    eq = find_steady_state(hmodel)
示例#6
0
import dolark
from dolark import HModel  # The model is written in yaml file, HModel is used to read the yaml file
from dolark.equilibrium import find_steady_state
from dolark.perturbation import perturb
from dolo import time_iteration, improved_time_iteration
from matplotlib import pyplot as plt
import numpy as np

#HModel reads the yaml file
aggmodel = HModel('Aiyagari.yaml')
aggmodel

# check features of the model
aggmodel.features

eq = find_steady_state(aggmodel)
eq

#plot the wealth distribution
s = eq.dr.endo_grid.nodes(
)  # grid for states (i.e the state variable--wealth in this case)
plt.plot(s, eq.μ.sum(axis=0), color='black')
plt.grid()
plt.title("Wealth Distribution")

# You can also check the steady state values of all variables
eq.as_df()

# define the dataframe
df = eq.as_df()
示例#7
0
dr = sol.dr

#%%

from dolo.algos.ergodic import ergodic_distribution
μ = ergodic_distribution(hmodel.agent, dr)[1]

#%%

from matplotlib import pyplot as plt
plt.plot(μ.data.ravel())

#%%

from dolark.equilibrium import find_steady_state
eqs = find_steady_state(hmodel, dr0=dr, verbose='full', return_fun=False)

#%%

m0 = hmodel.calibration['exogenous']
y0 = hmodel.calibration['aggregate']
p0 = hmodel.calibration['parameters']

(m0, y0, hmodel.projection(m0, y0, p0))

# %%

from matplotlib import pyplot as plt
from dolo import tabulate

tab = tabulate(hmodel.agent, dr, "m")
示例#8
0
print(hmodel2.features)
print(hmodel2.distribution)

hmodel3 = HModel('bfs_2017.yaml')
print(hmodel3.name)
print(hmodel3.features)
# print(hmodel3.distribution)

# # Identical Agents: autocorrelated procesess

# +
# the agent's problem has autocorrelated exogenous process
# it is discretized as an markov chain
# -

eq = find_steady_state(hmodel1)
eq

# a bit out of topic here:
from dolark.perturbation import perturb
peq = perturb(hmodel1, eq)
peq

# +
# cf reiter_example to see what to do with eq and peq
# -

# # Many Agents: autocorrelated procesess

# distribution of agent's parameters
hmodel2.distribution
示例#9
0
# %%
from dolo import groot

groot("examples")
from dolark import HModel
from dolark.equilibrium import find_steady_state

hmodel = HModel("ayiagari_betadist.yaml")
eq = find_steady_state(hmodel)
示例#10
0
# hmodel3 = HModel('bfs_2017.yaml')
# print(hmodel3.name)

#%%

#%%

#%%

# dr0 = hmodel2.get_starting_rule()
# m0, y0 = hmodel2.calibration['exogenous','aggregate']
# eq = equilibrium(hmodel2, m0, y0, dr0=dr0)
# eq = find_steady_state(hmodel1, dr0=dr0)
# #%%

eq0 = find_steady_state(hmodel1)

for j in range(3):
    plt.plot(w * eq0.μ[j, :], label=f"{i}")

#%%

eqss = find_steady_state(hmodel2)

from matplotlib import pyplot as plt

for i, (w, eq) in enumerate(eqss):
    s = eq.dr.endo_grid.nodes()
    for j in range(3):
        plt.plot(s, w * eq.μ[j, :], label=f"{i}")
plt.legend()