/
ex4_Sims_2011.jl
188 lines (169 loc) · 6.4 KB
/
ex4_Sims_2011.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
using DRIPs, Printf, Plots, LaTeXStrings, BenchmarkTools; pyplot();
Base.show(io::IO, f::Float64) = @printf io "%1.3f" f #rounds up floats for display
## Initialize
# Primitives of D.R.I.P.
β = 0.9;
ω = 1.0;
A = [0.95 0.0; 0.0 0.4];
Q = [√0.0975 0.0; 0.0 √0.86];
H = [1.0; 1.0];
## Solve Sims (2011) under benchmark parameterization
sol_bp = solve_drip(ω,β,A,Q,H);
display(sol_bp.Σ_p)
# Measure performance with random ω
@benchmark solve_drip(ω,β,A,Q,H) setup = (ω = 2*rand())
# Measure performance with random β
@benchmark solve_drip(ω,β,A,Q,H) setup = (β = rand())
## Solve Sims (2011) under low ω parameterization
sol_lω = solve_drip(0.1,β,A,Q,H);
display(sol_lω.Σ_p)
## Solve Sims (2011) under low and high β parameterization
sol_lβ = solve_drip(ω,0,A,Q,H); display(sol_lβ.Σ_p);
sol_hβ = solve_drip(ω,1,A,Q,H); display(sol_hβ.Σ_p);
## IRFs for benchmark parameterization
T = 25; #length of IRFs
irfs_bp = dripirfs(sol_bp,T = T);
p1 = plot(1:T, [irfs_bp.x[1,1,:], irfs_bp.a[1,1,:]],
title = L"IRFs to Slow-Moving Shock ($\rho = 0.95$)",
label = ["Shock" "Price"],
color = [:darkgray :black],
marker = [:circle :square],
markerstrokecolor = :match,
markercolor = false,
markersize = 6)
p2 = plot(1:T, [irfs_bp.x[2,2,:], irfs_bp.a[1,2,:]],
title = L"IRFs to Fast-Moving Shock ($\rho = 0.4$)",
label = ["Shock" "Price"],
color = [:darkgray :black],
marker = [:circle :square],
markerstrokecolor = :match,
markercolor = false,
markersize = 6)
p = plot(p1,p2,
layout = (2,1),
xlabel = "Time",
lw = 2,
xticks = (1:2:T),
xlim = (0,T+1),
fontfamily = "serif",
legend = :topright,
legendfont = font(12),
tickfont = font(12),
size = (900,550),
framestyle = :box)
## IRFs for low ω
T = 25; #length of IRFs
irfs_lω = dripirfs(sol_lω,T = T);
p1 = plot(1:T, [irfs_lω.x[1,1,:], irfs_lω.a[1,1,:]],
title = L"IRFs to Slow-Moving Shock ($\rho = 0.95$)",
label = ["Shock" "Price"],
color = [:darkgray :black],
marker = [:circle :square],
markerstrokecolor = :match,
markercolor = false,
markersize = 6)
p2 = plot(1:T, [irfs_lω.x[2,2,:], irfs_lω.a[1,2,:]],
title = L"IRFs to Fast-Moving Shock ($\rho = 0.4$)",
label = ["Shock" "Price"],
color = [:darkgray :black],
marker = [:circle :square],
markerstrokecolor = :match,
markercolor = false,
markersize = 6)
p = plot(p1,p2,
layout = (2,1),
xlabel = "Time",
lw = 2,
xticks = (1:2:T),
xlim = (0,T+1),
fontfamily = "serif",
legend = :topright,
legendfont = font(12),
tickfont = font(12),
size = (900,550),
framestyle = :box)
## IRFs for different βs
T = 25; #length of IRFs
irfs_lβ = dripirfs(sol_lβ,T = T);
irfs_hβ = dripirfs(sol_hβ,T = T);
p1 = plot(1:T, [irfs_bp.x[1,1,:],irfs_hβ.a[1,1,:], irfs_lβ.a[1,1,:]],
title = L"IRFs to Slow-Moving Shock ($\rho = 0.95$)",
label = ["Shock" L"Price ($\beta=1$)" L"Price ($\beta=0$)"],
color = [:darkgray :black :gray50],
marker = [:circle :square :utriangle],
markerstrokecolor = :match,
markercolor = false,
markersize = 6)
p2 = plot(1:T, [irfs_bp.x[2,2,:],irfs_hβ.a[1,2,:], irfs_lβ.a[1,2,:]],
title = L"IRFs to Fast-Moving Shock ($\rho = 0.4$)",
label = ["Shock" L"Priceblack ($\beta=1$)" L"Price ($\beta=0$)"],
color = [:darkgray :black :gray50],
marker = [:circle :square :utriangle],
markerstrokecolor = :match,
markercolor = false,
markersize = 6)
p = plot(p1,p2,
layout = (2,1),
xlabel = "Time",
lw = 2,
xticks = (1:2:T),
xlim = (0,T+1),
fontfamily = "serif",
legend = :topright,
legendfont = font(12),
tickfont = font(12),
size = (900,550),
framestyle = :box)
## Transition dynamics
s0 = Signal(H,0.0);
Tss = 15; # guess for time until convergence
bp_trip = solve_trip(sol_bp, s0; T = Tss);
@benchmark solve_trip(sol_bp, S; T = 30) setup = (S = Signal(rand(2),0.0))
p = plot(0:Tss-1,[bp_trip.Ds[1,1:Tss],bp_trip.Ds[2,1:Tss],bp_trip.P.ω*ones(Tss,1)],
label = ["Low marginal value dim." "High marginal value dim." "Marginal cost of attention"],
size = (900,275),
title = "Marginal Value of Information",
xlabel = "Time",
color = [:darkgray :black :black],
line = [:solid :solid :dash],
marker = [:circle :square :none],
markercolor = false,
markerstrokecolor = :match,
markersize = 6,
xlim = (-1,Tss),
xticks = 0:2:Tss-1,
legend = :outertopright,
fontfamily = "serif",
framestyle = :box)
## IRFs with information treatment
T = 30; #length of IRFs
tirfs_bp = dripirfs(sol_bp,s0, T = T); # irfs with treatment
irfs_bp = dripirfs(sol_bp, T = T); # irfs in the Ss (without treatment)
p1 = plot(1:T, [irfs_bp.x[1,1,:], tirfs_bp.a[1,1,:], irfs_bp.a[1,1,:]],
title = L"IRFs to Slow-Moving Shock ($\rho = 0.95$)",
label = ["Shock" "Price (w/ treatment)" "Price (w/o treatment)"],
color = [:darkgray :black :gray80],
marker = [:circle :square :utriangle],
markerstrokecolor = :match,
markercolor = false,
markersize = 6)
p2 = plot(1:T, [tirfs_bp.x[2,2,:], tirfs_bp.a[1,2,:], irfs_bp.a[1,2,:]],
title = L"IRFs to Fast-Moving Shock ($\rho = 0.4$)",
label = ["Shock" "Price (w/ treatment)" "Price (w/o treatment)"],
color = [:darkgray :black :gray80],
marker = [:circle :square :utriangle],
markerstrokecolor = :match,
markercolor = false,
markersize = 6)
p = plot(p1,p2,
layout = (2,1),
xlabel = "Time",
lw = 2,
xticks = (1:2:T),
xlim = (0,T+1),
fontfamily = "serif",
legend = :topright,
legendfont = font(12),
tickfont = font(12),
size = (900,550),
framestyle = :box)