Beispiel #1
0
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.4'
#       jupytext_version: 1.2.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# WARNING: this is not working yet
from dolark import HModel
from dolo import pcat

hmodel = HModel("ks.yaml")

# The yaml file allows for the agent's exogenous process to depend on the aggregate values.

# !sed -n 40,51p ks.yaml | pygmentize -l yaml

# Here is what is recovered from the yaml file

exo = hmodel.model.exogenous

exo.condition  # the driving process coming from aggregate simulation

μ = exo.condition.μ
μ

exo.arguments(μ)
Beispiel #2
0
def test_steady_state_ex_ante():
    hmodel = HModel("ayiagari_betadist.yaml")
    eq = find_steady_state(hmodel)
Beispiel #3
0
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# WARNING: this is not working yet

# +
from dolo import *
from matplotlib import pyplot as plt
import pandas as pd
import altair as alt
from dolark import HModel

hmodel = HModel("bfs_2017.yaml")
hmodel.features
# -
hmodel.agent

# Agent's distributions look good

dis_iids = []
for i in range(3):
    dis_iids.append(hmodel.agent.exogenous.processes[i].discretize(to='iid'))

df1 = pd.DataFrame([[w, x[0]] for w, x in dis_iids[0].iteritems(0)],
                   columns=['w', 'x'])  #constant
df2 = pd.DataFrame([[w, x[0]] for w, x in dis_iids[1].iteritems(0)],
                   columns=['w', 'x'])
df3 = pd.DataFrame([[w, x[0]] for w, x in dis_iids[2].iteritems(0)],
Beispiel #4
0
# First, please follow "README.md" for all the preparation for running the code
# Setup
from dolo import *
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()
Beispiel #5
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)
Beispiel #6
0
def state_trans_2():
    HModel("error_state_trans_2.yaml")
Beispiel #7
0
def state_None():
    HModel("./dolark/tests/check/error_state_None.yaml")
Beispiel #8
0
# %%
import numpy as np
import copy
import scipy
from dolark.equilibrium import equilibrium, find_steady_state
from dolo import improved_time_iteration, ergodic_distribution, time_iteration
from dolo import time_iteration, improved_time_iteration
from dolo import groot

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
Beispiel #9
0
# -*- coding: utf-8 -*-
# + {}
# This notebook computes the equilibrium distribution for various types of models
# -

from dolark import HModel
from dolark.equilibrium import find_steady_state
from matplotlib import pyplot as plt

# +
hmodel1 = HModel('ayiagari.yaml')
print(hmodel1.name)

print(hmodel1.features)
# -

hmodel2 = HModel('ayiagari_betadist.yaml')
print(hmodel2.name)
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
Beispiel #10
0
# %%
from dolo import groot
groot('examples')

# %%
from matplotlib import pyplot as plt

# %%
# here are the three functions we use from dolark
from dolark import HModel
from dolark.equilibrium import find_steady_state
from dolark.perturbation import perturb

# %%
# Let's import the heterogeneous agents model
aggmodel = HModel('ayiagari.yaml')
aggmodel  # TODO: find a reasonable representation of this object

# %%
# see what can be done
aggmodel.features

# %%

# %% [markdown]
# First we can check whether the one-agent sub-part of it works, or whether we will need to find better initial guess.

# %%
from dolo import time_iteration
i_opts = {
    "N": 2
Beispiel #11
0
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.4'
#       jupytext_version: 1.2.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# WARNING: this is not working yet
from dolark import HModel
from dolo import pcat

hmodel = HModel('ks.yaml')

# The yaml file allows for the agent's exogenous process to depend on the aggregate values.

# !sed -n 40,51p ks.yaml | pygmentize -l yaml

# Here is what is recovered from the yaml file

exo = hmodel.model.exogenous

exo.condition  # the driving process coming from aggregate simulation

μ = exo.condition.μ
μ

exo.arguments(μ)
Beispiel #12
0
# -*- coding: utf-8 -*-
# + {}
# This notebook computes the equilibrium distribution for various types of models
# -

from dolark import HModel
from dolark.equilibrium import find_steady_state
from matplotlib import pyplot as plt

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

print(hmodel1.features)
# -

hmodel2 = HModel("ayiagari_betadist.yaml")
print(hmodel2.name)
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
# -
Beispiel #13
0
from dolo import groot

groot("examples")

# %%
from matplotlib import pyplot as plt

# %%
# here are the three functions we use from dolark
from dolark import HModel
from dolark.equilibrium import find_steady_state
from dolark.perturbation import perturb

# %%
# Let's import the heterogeneous agents model
aggmodel = HModel("ayiagari.yaml")
aggmodel  # TODO: find a reasonable representation of this object

# %%
# see what can be done
aggmodel.features

# %%

# %% [markdown]
# First we can check whether the one-agent sub-part of it works, or whether we will need to find better initial guess.

# %%
from dolo import time_iteration

i_opts = {
Beispiel #14
0
def test_with_agg_states():
    hmodel = HModel("prototype.yaml")
    eq = find_steady_state(hmodel)
Beispiel #15
0
def trans_None():
    HModel("error_trans_None.yaml")
Beispiel #16
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)
Beispiel #17
0
def state_trans_1():
    HModel("error_state_trans_1.yaml")
Beispiel #18
0
#%%

from dolark import HModel
from dolo.algos import time_iteration, improved_time_iteration

hmodel = HModel("bfs_2017_K.yaml")
hmodel.features

#%%

#%%

m0 = hmodel.calibration["exogenous"]
s0 = hmodel.calibration["states"]
y0 = hmodel.calibration["aggregate"]
p0 = hmodel.calibration["parameters"]

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

# %%

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]
Beispiel #19
0
import numpy as np
import copy
import scipy
from dolark.equilibrium import equilibrium, find_steady_state
from dolo import improved_time_iteration, ergodic_distribution, time_iteration
from dolo import time_iteration, improved_time_iteration
from dolo import groot

groot('examples')

# Let's import the heterogeneous agents model
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)

#%%

#%%

#%%

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