Skip to content

Commit 30947f8

Browse files
committed
more plotting examples
1 parent f107cc8 commit 30947f8

File tree

1 file changed

+262
-0
lines changed

1 file changed

+262
-0
lines changed

test/fix_combined_plots.jl

Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,268 @@
11
using Revise
22
using MacroModelling, StatsPlots
33

4+
include("../models/GNSS_2010.jl")
5+
6+
model = GNSS_2010
7+
get_shocks(model)
8+
9+
shcks = :e_y
10+
vars = [:C, :K, :Y, :r_k, :w_p, :rr_e, :pie, :q_h, :l_p]
11+
12+
plot_irf(model, shocks = shcks, variables = vars)
13+
14+
plot_irf!(model,
15+
shock_size = 1.2,
16+
shocks = shcks, variables = vars)
17+
18+
plot_irf!(model,
19+
shock_size = 0.2,
20+
shocks = shcks, variables = vars)
21+
22+
23+
vars = [:C, :K, :Y, :r_k, :w_p, :rr_e, :pie, :q_h, :l_p]
24+
25+
plot_irf(model, algorithm = :pruned_second_order, shocks = shcks, variables = vars)
26+
27+
plot_irf!(model, algorithm = :pruned_second_order,
28+
shock_size = 1.2,
29+
shocks = shcks, variables = vars)
30+
31+
plot_irf!(model, algorithm = :pruned_second_order,
32+
shock_size = -1,
33+
shocks = shcks, variables = vars)
34+
35+
plot_irf!(model, algorithm = :second_order,
36+
shock_size = -1,
37+
shocks = shcks, variables = vars)
38+
39+
40+
vars = [:C, :K, :Y, :r_k, :w_p, :rr_e, :pie, :q_h, :l_p]
41+
42+
plot_irf(model, shocks = shcks, variables = vars)
43+
44+
plot_irf!(model,
45+
shock_size = -1,
46+
shocks = shcks, variables = vars)
47+
48+
plot_irf!(model, algorithm = :pruned_second_order,
49+
periods = 10,
50+
shocks = shcks, variables = vars)
51+
52+
plot_irf!(model, algorithm = :second_order,
53+
shock_size = -1,
54+
shocks = shcks, variables = vars)
55+
56+
57+
vars = [:C, :K, :Y, :r_k, :w_p, :rr_e, :pie, :q_h, :l_p]
58+
59+
get_shocks(model)
60+
61+
plot_irf(model, shocks = shcks, variables = vars)
62+
63+
plot_irf!(model, shocks = :e_j, variables = vars)
64+
65+
plot_irf!(model, shocks = [:e_j, :e_me], variables = vars)
66+
67+
plot_irf!(model, variables = vars)
68+
69+
70+
71+
vars = [:C, :K, :Y, :r_k, :w_p, :rr_e, :pie, :q_h, :l_p]
72+
73+
get_shocks(model)
74+
75+
plot_irf(model, shocks = shcks, variables = vars)
76+
77+
plot_irf!(model, algorithm = :pruned_second_order,
78+
shock_size = -1,
79+
shocks = shcks, variables = vars)
80+
81+
plot_irf!(model, algorithm = :second_order,
82+
shock_size = -1,
83+
shocks = shcks, variables = vars)
84+
85+
86+
vars = [:C, :K, :Y, :r_k, :w_p, :rr_e, :pie, :q_h, :l_p]
87+
88+
plot_irf(model, shocks = shcks, variables = vars)
89+
90+
plot_irf!(model, shocks = shcks, variables = vars[2:end], shock_size = -1)
91+
92+
93+
vars = [:C, :K, :Y, :r_k, :w_p, :rr_e, :pie, :q_h, :l_p]
94+
95+
plot_irf(model, shocks = shcks, variables = vars)
96+
97+
for a in [:second_order, :pruned_second_order, :third_order, :pruned_third_order]
98+
plot_irf!(model, shocks = shcks, variables = vars, algorithm = a)
99+
end
100+
101+
102+
vars = [:C, :K, :Y, :r_k, :w_p]
103+
104+
plot_irf(model, shocks = shcks, variables = vars)
105+
106+
for a in [:second_order, :pruned_second_order, :third_order, :pruned_third_order]
107+
plot_irf!(model, shocks = shcks, variables = vars, algorithm = a)
108+
end
109+
110+
111+
112+
vars = [:C, :K, :Y, :r_k, :w_p, :rr_e, :pie, :q_h, :l_p]
113+
114+
plot_irf(model, shocks = shcks, variables = vars)
115+
116+
plot_irf!(model, shocks = shcks, variables = vars, negative_shock = true)
117+
118+
plot_irf!(model, shocks = :e_j, variables = vars, negative_shock = true)
119+
120+
plot_irf!(model, shocks = :e_j, shock_size = 2, variables = vars, negative_shock = true)
121+
122+
plot_irf!(model, shocks = :e_j, shock_size = -2, variables = vars, negative_shock = true, algorithm = :second_order)
123+
124+
125+
vars = [:C, :K, :Y, :r_k, :w_p, :rr_e, :pie, :q_h, :l_p]
126+
127+
plot_irf(model, shocks = shcks, variables = vars, algorithm = :pruned_second_order)
128+
129+
plot_irf!(model, shocks = shcks, variables = vars, generalised_irf = true, algorithm = :pruned_second_order)
130+
131+
plot_irf!(model, shocks = shcks, variables = vars, algorithm = :pruned_third_order)
132+
133+
plot_irf!(model, shocks = shcks, variables = vars, generalised_irf = true, algorithm = :pruned_third_order)
134+
135+
136+
137+
138+
include("../models/Gali_2015_chapter_3_obc.jl")
139+
140+
model = Gali_2015_chapter_3_obc
141+
get_shocks(model)
142+
get_variables(model)[1:10]
143+
shcks = :eps_z
144+
vars = [:A, :C, :MC, :M_real, :N, :Pi, :Pi_star, :Q, :R, :S]
145+
146+
plot_irf(model, shocks = shcks, variables = vars, periods = 10)
147+
148+
plot_irf!(model, shocks = shcks, variables = vars, periods = 10, ignore_obc = true)
149+
150+
plot_irf!(model, shocks = shcks, variables = vars, periods = 10, shock_size = 2, ignore_obc = false)
151+
152+
plot_irf!(model, shocks = shcks, variables = vars, periods = 10, shock_size = 2, ignore_obc = true)
153+
154+
plot_irf!(model, shocks = :eps_a, variables = vars, periods = 10, shock_size = 4, ignore_obc = false)
155+
156+
plot_irf!(model, shocks = :eps_a, variables = vars, periods = 10, shock_size = 4, ignore_obc = true)
157+
158+
159+
160+
plot_irf(model, shocks = shcks, variables = vars, periods = 10)
161+
162+
plot_irf!(model, shocks = shcks, variables = vars, periods = 10, ignore_obc = true)
163+
164+
plot_irf!(model, shocks = shcks, variables = vars, periods = 10, algorithm = :pruned_second_order, ignore_obc = true)
165+
166+
plot_irf!(model, shocks = shcks, variables = vars, periods = 10, algorithm = :pruned_second_order, shock_size = 2, ignore_obc = false)
167+
168+
plot_irf!(model, shocks = shcks, variables = vars, periods = 10, algorithm = :pruned_second_order, shock_size = 2, ignore_obc = true)
169+
170+
plot_irf!(model, shocks = :eps_a, variables = vars, periods = 10, algorithm = :pruned_second_order, shock_size = 4, ignore_obc = false)
171+
172+
plot_irf!(model, shocks = :eps_a, variables = vars, periods = 10, algorithm = :pruned_second_order, shock_size = 4, ignore_obc = true)
173+
174+
175+
plot_irf(model, shocks = shcks, variables = vars, algorithm = :pruned_second_order)
176+
177+
plot_irf!(model, shocks = shcks, variables = vars, algorithm = :pruned_second_order, quadratic_matrix_equation_algorithm = :doubling)
178+
179+
plot_irf!(model, shocks = shcks, variables = vars, algorithm = :pruned_second_order, sylvester_algorithm = :doubling)
180+
181+
plot_irf(model, shocks = shcks, variables = vars, algorithm = :pruned_third_order)
182+
183+
plot_irf!(model, shocks = shcks, variables = vars, algorithm = :pruned_third_order, quadratic_matrix_equation_algorithm = :doubling)
184+
185+
186+
get_parameters(model, values = true)
187+
188+
plot_irf(model, shocks = shcks, variables = vars, parameters = => .25)
189+
190+
plot_irf!(model, shocks = shcks, variables = vars, parameters = => .2)
191+
192+
SS(model, derivatives = false, parameters = => .25)(:R)
193+
SS(model, derivatives = false, parameters = => .2)(:R)
194+
195+
196+
# handle initial state and tol
197+
198+
init_state = get_irf(model, shocks = :none, variables = :all,
199+
periods = 1, levels = true)
200+
201+
init_state[1] += 1
202+
203+
plot_irf(model, shocks = shcks, variables = vars, ignore_obc = true,
204+
initial_state = vec(init_state))
205+
206+
207+
plot_irf!(model, shocks = :none, variables = vars, ignore_obc = true,
208+
initial_state = vec(init_state),
209+
# algorithm = :second_order
210+
)
211+
212+
init_state_2 = get_irf(model, shocks = :none, variables = :all, periods = 1, levels = true)
213+
214+
init_state_2[1] += 2
215+
216+
init_state[1] += 2
217+
218+
plot_irf!(model, shocks = :none, variables = vars, ignore_obc = true,initial_state = vec(init_state))
219+
220+
221+
# init_state_2 = get_irf(model, shocks = :none, variables = :all, periods = 1, levels = true)
222+
223+
init_state[1] += .2
224+
225+
plot_irf!(model, shocks = shcks, variables = vars, ignore_obc = true,
226+
algorithm = :second_order,
227+
initial_state = vec(init_state)
228+
)
229+
230+
231+
init_state_2 = get_irf(model, shocks = :none, variables = :all, algorithm = :pruned_second_order, periods = 1, levels = false)
232+
233+
plot_irf!(model, shocks = shcks, variables = vars, ignore_obc = true,
234+
algorithm = :pruned_second_order,
235+
initial_state = vec(init_state_2)
236+
)
237+
238+
239+
plot_irf(model, shocks = shcks, variables = vars)
240+
241+
# plot_irf!(model, shocks = shcks, variables = vars, ignore_obc = true)
242+
243+
plot_irf!(model, shocks = shcks, variables = vars, tol = Tolerances(NSSS_acceptance_tol = 1e-8))
244+
245+
plot_irf!(model, shocks = shcks, variables = vars, quadratic_matrix_equation_algorithm = :doubling)
246+
247+
248+
data = randn(10, 3)
249+
data = randn(10, 3) # your values
250+
offset = fill(10.0, size(data, 1)) # desired baseline
251+
252+
p = StatsPlots.groupedbar([data offset],
253+
bar_position = :stack,
254+
bar_width = 0.7,
255+
alpha = [ones(size(data, 2)); 0]', # hide the baseline series
256+
# label = [" " ; "A" "B" "C"]' # no legend entry for the baseline
257+
)
258+
259+
p = StatsPlots.groupedbar(data[1,:]', bar_position = :stack, bar_width = 0.7, fillrange = 1)
260+
261+
262+
original_limits = StatsPlots.ylims(p)
263+
lo, hi = original_limits
264+
StatsPlots.ylims!(p, (lo + 10, hi + 10))
265+
4266
@model RBC begin
5267
1 / c[0] =/ c[1]) ** exp(z[1]) * k[0]^- 1) + (1 - δ))
6268
c[0] + k[0] = (1 - δ) * k[-1] + q[0]

0 commit comments

Comments
 (0)