Skip to content

Commit 1372ae3

Browse files
committed
WIP
1 parent 75302e9 commit 1372ae3

File tree

9 files changed

+395
-85
lines changed

9 files changed

+395
-85
lines changed

ICAI/partial.dyno

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ r <- r_w
1717
η <- 2.5
1818
η_b <- 2.5
1919
ω <- 0.5
20+
21+
T <- 20
22+
2023
hand_to_mouth <- 0.0
2124

2225
y[~] <- y_bar
@@ -31,47 +34,59 @@ b_τ[~] <- 0
3134
p[~] <- β/(1-β)*r
3235
q[~] <- p[~]*a[~]*y[~]/r
3336
n[~] <- 1 # total number of shares
34-
x[~] <- 1/χ # number of shares per top earner
3537

36-
W_τ[~] <- p[~]*(b_τ[~]) + q[~]*x[~]
38+
W_τ[~] <- p[~]*(b_τ[~]) + q[~]
3739
W_b[~] <- 1.0 + p[~]*(b_b[~])*0 # adding/removing the last term affects the result !
38-
c_b[~] <- a[~]*(1-y[~])*(1-ζ[~])/(1-χ)
39-
c_τ[~] <- a[~]*(1-y[~])*ζ[~]*x[~] + b_τ[~]*r + (a[~]*y[~])*x[~]
40-
y_b[~] <- a[~]*(1-y[~])*(1-ζ[~])/(1-χ) # labor income for bottom-earners
41-
y_τ[~] <- a[~]*(1-y[~])*ζ[~]*x[~] + (a[~]*y[~])*x[~] # top earners income (labor plus dividends)
40+
c_b[~] <- a[~]*(1-y[~])*(1-ζ[~])
41+
c_τ[~] <- a[~]*(1-y[~])*ζ[~] + b_τ[~]*r + (a[~]*y[~])
42+
y_b[~] <- a[~]*(1-y[~])*(1-ζ[~]) # labor income for bottom-earners
43+
y_τ[~] <- a[~]*(1-y[~])*ζ[~] + (a[~]*y[~]) # top earners income (labor plus dividends)
4244
c_b[~] <- b_b[~]*r + y_b[~]
4345
c_τ[~] <- b_τ[~]*r + y_τ[~]
4446

45-
4647
φ_τ <- (1-β_τ/p[~])*c_τ[~]^(-σ)/(W_τ[~])^(-η)
4748
φ_b <- (1-β_b/p[~])*c_b[~]^(-σ)/(W_b[~])^(-η_b)
4849

50+
ΔNFA[~] <- 0.0
4951

5052

5153
# exogenous processes
5254
y[t] = y[~] + ρ_y*(y[t-1]-y[~])
5355
ζ[t] = ζ[~] + ρ_ζ*(ζ[t-1]-ζ[~])
54-
x[t] = x[~]
56+
5557
a[t] = 1 + ρ_a*(a[t-1]-1)
5658

57-
d[t] = d[t-1] + e_d[t] # income shock for top earners
58-
d_b[t] = d_b[t-1] + e_d_b[t] # income shock for bottom earners
59+
d[t] = d[t-1] + e_d[t] # income shock for top earners (aggregate)
60+
d_b[t] = d_b[t-1] + e_d_b[t] # income shock for bottom earners (aggregate)
5961

60-
y_b[t] = a[t]*(1-y[t])*(1-ζ[t])/(1-χ) # labor income for bottom-earners
61-
y_τ[t] = a[t]*(1-y[t])*ζ[t]*x[t] + (a[t]*y[t])*x[t] # top earners income (labor plus dividends)
62+
y_b[t] = a[t]*(1-y[t])*(1-ζ[t]) # labor income for bottom-earners (aggregate)
63+
y_τ[t] = a[t]*(1-y[t])*ζ[t] + (a[t]*y[t]) # top earners income (per capita)
6264

63-
c_b[t] = d_b[t]/(1-χ) + b_b[t-1]*r - (b_b[t]-b_b[t-1])*p[t] + y_b[t]
64-
c_τ[t] = d[t] + b_τ[t-1]*r - (b_τ[t]-b_τ[t-1])*p[t] + y_τ[t]
65+
c_b[t] = d_b[t] + b_b[t-1]*r - (b_b[t]-b_b[t-1])*p[t] + y_b[t] # consumption bottom earners (aggregate)
66+
c_τ[t] = d[t] + b_τ[t-1]*r - (b_τ[t]-b_τ[t-1])*p[t] + y_τ[t] # consumption top earners (aggregate)
6567

66-
W_τ[t] = q[t]*x[t] + p[t]*(b_τ[t])
67-
W_b[t] = 1 + p[t]*(b_b[t])
68+
W_τ[t] = q[t] + p[t]*(b_τ[t]) # wealth top earners (aggregate)
69+
W_b[t] = 1 + p[t]*(b_b[t]) # wealth bottom earners (aggregate)
6870

6971
p[t] = β_b*(c_b[t+1]/c_b[t])^(-σ)*(r+p[t+1]) + φ_b*(W_b[t])^(-η_b)/(c_b[t])^(-σ)*p[t]
7072
p[t] = β_τ*(c_τ[t+1]/c_τ[t])^(-σ)*(r+p[t+1]) + φ_τ*(W_τ[t])^(-η )/(c_τ[t])^(-σ)*p[t]
7173

74+
q[t] = p[~]*a[~]*y[~]/r
75+
76+
ΔNFA[t] = b_τ[t] + b_b[t] - (b_τ[~] + b_b[~]) # change in net foreign asset position
77+
78+
# small open economy assumption:
7279
r_w + p[t] = 1
7380

74-
q[t] = p[~]*a[~]*y[~]/r
81+
# closed economy assumption:
82+
# b_τ[t] + b_b[t] = b_τ[~] + b_b[~] # net-zero change in bond supply
83+
84+
85+
### Exogenous shocks
86+
# e_d[t] <- N(0, 0.01)
87+
# e_d_b[t] <- N(0, 0.01)
88+
7589

76-
# e_d[t] <- N(0, 0.1)
77-
e_d_b[t] <- N(0, 0.1)
90+
e_d[1] <- 0.01
91+
forall t, 2<=t<T: e_d[t] <- 0.02
92+
e_d_b[1] <- 0.01

ICAI/solve_icai.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,64 @@
11
import dyno
22
from matplotlib import pyplot as plt
33
from dyno.symbolic_model import SymbolicModel
4+
import pandas as pd
45

56
model = SymbolicModel("partial.dyno")
67

8+
v0 = model.deterministic_guess()
9+
10+
pd.DataFrame(v0, columns=model.symbols['variables'])
11+
12+
13+
14+
15+
model.jacobians[0]
16+
17+
718
dr = model.solve()
19+
sim = dr.irfs(type='level')['e_d']
20+
# plt.plot(sim.index, sim['W_τ'], label="baseline")
21+
22+
plt.plot(sim.index, sim['b_b'], label="baseline",marker='.',linestyle='-')
23+
plt.plot(sim.index, sim['b_τ'], label="baseline",marker='.',linestyle='-')
24+
plt.xlim(0,10)
25+
26+
plt.plot(sim.index, sim['W_b'], label="baseline",marker='.',linestyle='-')
27+
plt.plot(sim.index, sim['W_τ'], label="baseline",marker='.',linestyle='-')
28+
plt.xlim(0,10)
29+
30+
31+
m2 = model.recalibrate(η=1.51)
32+
dr2 = m2.solve()
33+
sim2 = dr2.irfs()['e_d']
34+
35+
# plt.plot(sim.index, (sim['W_τ']-sim['W_τ'][0])/sim['d'], label="baseline")
36+
# plt.plot(sim2.index, (sim2['W_τ']-sim2['W_τ'][0])/sim2['d'], label="η=3.0")
37+
38+
plt.plot(sim2.index, sim2['W_τ'])
39+
40+
41+
m2 = model.recalibrate(η=1.51)
42+
dr2 = m2.solve()
43+
sim2 = dr2.irfs()['e_d']
44+
45+
# plt.plot(sim.index, (sim['W_τ']-sim['W_τ'][0])/sim['d'], label="baseline")
46+
# plt.plot(sim2.index, (sim2['W_τ']-sim2['W_τ'][0])/sim2['d'], label="η=3.0")
47+
48+
plt.plot(sim.index, (sim['W_b']-sim['W_b'][0])/sim['d'], label="baseline")
49+
plt.plot(sim2.index, (sim2['W_b']-sim2['W_b'][0])/sim2['d'], label="η=3.0")
50+
51+
52+
53+
54+
55+
print(m2.data.context['constants']['D'])
56+
print(m2.data.context['processes'][('e_d',)].Σ)
57+
58+
59+
plt.plot(sim['e_d'].index, sim['e_d']['d'], label="baseline")
60+
plt.plot(sim2['e_d'].index, sim2['e_d']['d'], label="D=0.05")
61+
plt.legend()
862

963

1064
######

dev_dynare.py

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,52 @@
44
dir_path = os.path.dirname(os.path.realpath(__file__))
55

66

7-
f_r = "examples/modfiles/RBC.mod"
87
f_o = "examples/RBC.dyno"
8+
f_r = "examples/modfiles/RBC.mod"
9+
10+
11+
from dyno.symbolic_model import SymbolicModel
12+
13+
model1 = SymbolicModel(f_o)
14+
model2 = SymbolicModel(f_r)
15+
16+
17+
import copy
18+
19+
t1 = time.time()
20+
m1 = model1.recalibrate(beta=0.4)
21+
t2 = time.time()
22+
print("Elapsed: ", t2 - t1)
23+
24+
25+
26+
import copy
27+
t1 = time.time()
28+
mm1 = copy.deepcopy(model1)
29+
mm1.solve()
30+
t2 = time.time()
31+
print("Elapsed: ", t2 - t1)
32+
33+
34+
import copy
35+
t1 = time.time()
36+
mm2 = copy.deepcopy(model2)
37+
dr = mm2.solve()
38+
t2 = time.time()
39+
print("Elapsed: ", t2 - t1)
40+
41+
942

1043
from dyno.symbolic_model import SymbolicModel
1144

1245
t1 = time.time()
1346
model = SymbolicModel(f_o)
1447
t2 = time.time()
1548
dr1 = model.solve()
49+
t3 = time.time()
1650
print("Model parsing time: ", t2 - t1)
51+
print("Model solving time: ", t3 - t2)
52+
1753

1854
from dyno.symbolic_model import SymbolicModel
1955

@@ -23,7 +59,12 @@
2359
dr2 = model.solve()
2460
t3 = time.time()
2561
print("Model parsing time: ", t2 - t1)
26-
# print("Model solving time: ", t3 - t2)
62+
print("Model solving time: ", t3 - t2)
63+
64+
65+
66+
67+
2768

2869
from dyno.modfile import DynareModel as DynareModelPP
2970

@@ -33,7 +74,7 @@
3374
dr3 = model.solve()
3475
t3 = time.time()
3576
print("Model parsing time: ", t2 - t1)
36-
# print("Model solving time: ", t3 - t2)
77+
print("Model solving time: ", t3 - t2)
3778

3879

3980
from IPython.display import Math, display

0 commit comments

Comments
 (0)