Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions examples/Caroll_2017_no_aggregate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
symbols:
exogenous: [w,r,ʊ,ψ,ξ]
states: [m]
controls: [c]
parameters: [ρ, β, δ, D, Đ, wbar, rbar, ʊbar, μ_ue, τ, θ, μ_θ, σ_θ, l, val]


equations:

transition:
- m = ((D+r)/Đ)*(m(-1)-c(-1))*(1/ψ) + ξ

arbitrage:
- ( β*(c(1)/c)^(-ρ) )*(ψ(1)^(-ρ))*(D+r(1))/Đ - 1 | 0.0<=c<=m



calibration:
ρ: 1
β: 0.99
δ: 0.025
D: 1-δ
Đ: 1-0.00625
wbar: 1
rbar: 0.01 + δ
ʊbar: 0.07
μ_ue: 0.15
τ: 0
l: 1/0.9

μ_θ: 1
σ_θ: 0.010*4
μ_ψ: 1
σ_ψ: (0.010*4)/11

val: (D+r)/Đ
m: 1.2
c: (m*(val-1) + 1 )/val
θ: 1

w : wbar
r : rbar
ʊ : ʊbar
ψ : 1
ξ : 1

domain:
m: [0.1, 10.0]

exogenous:
w,r,ʊ: !ConstantProcess
μ: [wbar, rbar, ʊbar]

ψ: !LogNormal
μ: 1
σ: 0.00004

ξ: !Mixture
index: !Bernouilli
π: ʊbar
distributions:
0: !ConstantProcess
μ: [μ_ue]
1: !LogNormal
μ: (1-τ)*l*μ_θ
σ: (((1-τ)*l)^2)*(σ_θ)^2
### transformed for μ_e=(1-τ)*l*θ)

options:
grid: !Cartesian
orders: [1000]
39 changes: 33 additions & 6 deletions examples/bfs_2017.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# text_representation:
# extension: .py
# format_name: light
# format_version: '1.4'
# jupytext_version: 1.2.4
# format_version: '1.5'
# jupytext_version: 1.3.0
# kernelspec:
# display_name: Python 3
# language: python
Expand All @@ -15,14 +15,22 @@

# WARNING: this is not working yet

# + jupyter={"source_hidden": true}
from dolo import groot
# -

groot()

pwd

# +
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 = HModel("examples/bfs_2017.yaml")
hmodel.features
# -
hmodel.agent
Expand All @@ -43,26 +51,44 @@

# Agents' decision rule is not correct yet

# +


from dolo.numeric.decision_rule import CustomDR

values = {
#'c': 'min(m, 1 + 0.05*(m-1))'
'c': 'm*0.2'
}


cdr = CustomDR(values, hmodel.agent)

# -

from dolo import time_iteration, improved_time_iteration
dr = time_iteration(hmodel.agent)
# # %time dr = improved_time_iteration(hmodel.model, dr0=dr, verbose=True, details=False)
dr = time_iteration(hmodel.agent, dr0 = cdr, maxit=100)
# %time dr = improved_time_iteration(hmodel.model, dr0=dr, verbose=True, details=False)


from dolo import tabulate

tab = tabulate(hmodel.agent, dr, 'm')

plt.plot(tab['m'], tab['c'])
#plt.ylim(0,1)

# ergodic distribution (premature)

Π, μ = ergodic_distribution(hmodel.model, dr)
df_μ = μ.to_dataframe('μ').reset_index()

plt.plot(df_μ['m'], df_μ['μ'])

ch = alt.Chart(tab)
g1 = ch.mark_line(color='black',strokeDash=[1,1]).encode(x='m', y='m') + \
ch.mark_line().encode(x='m', y='c')
g2 = alt.Chart(df_μ).mark_line().encode(x='m:Q', y= 'mu:Q')
g2 = alt.Chart(df_μ).mark_line().encode(x='m:Q', y= 'μ:Q')

g2

Expand All @@ -74,5 +100,6 @@
# here are the values projected from market equilibrium, given default level of capital
m0, y0, p = hmodel.calibration['exogenous','aggregate', 'parameters']
hmodel.projection(m0, y0, p) # values for r, w, ω (not the same at all)
# This should give w, r, ʊ


31 changes: 16 additions & 15 deletions examples/bfs_2017.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ calibration:
Đ: 1-0.00625
l: 1/0.9

wbar: 1
wbar: 2.37
rbar: 0.01 + δ
ʊbar: 0.07
μ_ue: 0.15
Expand All @@ -44,14 +44,14 @@ calibration:
ξ : 1

domain:
m: [0.1, 10.0]
m: [0.1, 20.0]

exogenous:
w,r,ʊ: !ConstantProcess
μ: [wbar, rbar, ʊbar]

ψ: !UNormal
μ: 1
ψ: !LogNormal
μ: 1.0
σ: 0.00004

ξ: !Mixture
Expand All @@ -60,14 +60,15 @@ exogenous:
distributions:
0: !ConstantProcess
μ: [μ_ue]
1: !UNormal
μ: (1-τ)*l
σ: (1-τ)*l*σ_θ

# 1: !UNormal
# μ: (1-τ)*l
# σ: (1-τ)*l*σ_θ

# 1: !LogNormal
# μ: (1-τ)*l*μ_θ
# σ: (((1-τ)*l)^2)*(σ_θ)^2
### transformed for μ_e=(1-τ)*l*θ)
1: !LogNormal
μ: (1-τ)*l*μ_θ
σ: (((1-τ)*l)**2)*(σ_θ)**2
## transformed for μ_e=(1-τ)*l*θ)

distribution:
β: !Uniform
Expand All @@ -76,7 +77,7 @@ distribution:

options:
grid: !Cartesian
orders: [100]
orders: [200]


---
Expand All @@ -90,7 +91,7 @@ symbols:

calibration:
α: 0.36
YK: 10.26
YK: 1/10.26
L: 1
l: 1/0.9
Z: 1.0
Expand All @@ -105,10 +106,10 @@ exogenous: !ConstantProcess
μ: [1.0, 1.0, 1.0]

projection:
w: (1-α)*Z*(K/(l*L))**(α)
w: (1-α)*Z*(YK)**(α/(α-1))
r: α*YK
ʊ: ʊbar


equilibrium:
- K = m-c
- K = m-c
75 changes: 75 additions & 0 deletions examples/bfs_2017_beta_het.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
symbols:
exogenous: [w,r,ʊ,ψ,ξ]
states: [m]
controls: [c]
parameters: [ρ, β, δ, D, Đ, wbar, rbar, ʊbar, μ_ue, τ, θ, μ_θ, σ_θ, l, val]


equations:

transition:
- m = ((D+r)/Đ)*(m(-1)-c(-1))*(1/ψ) + ξ

arbitrage:
- ( β*(c(1)/c)^(-ρ) )*(ψ(1)^(-ρ))*(D+r(1))/Đ - 1 | 0.0<=c<=m



calibration:
ρ: 1
β: 0.99
δ: 0.025
D: 1-δ
Đ: 1-0.00625
wbar: 1
rbar: 0.01 + δ
ʊbar: 0.07
μ_ue: 0.15
τ: 0
l: 1/0.9

μ_θ: 1
σ_θ: 0.010*4
μ_ψ: 1
σ_ψ: (0.010*4)/11

val: (D+r)/Đ
m: 1.2
c: (m*(val-1) + 1 )/val
θ: 1

w : wbar
r : rbar
ʊ : ʊbar
ψ : 1
ξ : 1

domain:
m: [0.1, 10.0]

exogenous:
w,r,ʊ: !ConstantProcess
μ: [wbar, rbar, ʊbar]

ψ: !LogNormal
μ: 1
σ: 0.00004

ξ: !Mixture
index: !Bernouilli
π: 1-ʊbar
distributions:
0: !ConstantProcess
μ: [μ_ue]
1: !UNormal
μ: (1-τ)*l
σ: (1-τ)*l*σ_θ

# 1: !LogNormal
# μ: (1-τ)*l*μ_θ
# σ: (((1-τ)*l)^2)*(σ_θ)^2
### transformed for μ_e=(1-τ)*l*θ)

options:
grid: !Cartesian
orders: [1000]
Loading