generated from donotdespair/presentation-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbsvars_oz.R
85 lines (63 loc) · 2.27 KB
/
bsvars_oz.R
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
library(bsvars)
set.seed(123)
# Download data using the readrba package
############################################################
# Gross domestic product (GDP); Chain volume
rgdp_dwnld = readrba::read_rba(series_id = "GGDPCVGDP")
rgdp_tmp = xts::xts(rgdp_dwnld$value, rgdp_dwnld$date, tclass = 'yearqtr')
drgdp = na.omit(400 * diff(log(rgdp_tmp)))
drgdp = xts::to.quarterly(drgdp, OHLC = FALSE)
# Consumer price index; All groups; Quarterly change (in per cent)
picpi_dwnld = readrba::read_rba(series_id = "GCPIAGSAQP")
pi = 4 * xts::xts(picpi_dwnld$value, picpi_dwnld$date, tclass = 'yearqtr')
pi = xts::to.quarterly(pi, OHLC = FALSE)
# Interbank Overnight Cash Rate
cr_dwnld = readrba::read_rba(series_id = "FIRMMCRID") # Cash Rate Target
cr_tmp = xts::xts(cr_dwnld$value, cr_dwnld$date)
cr = xts::to.quarterly(cr_tmp, OHLC = FALSE)
# Real Trade-Weighted Index
rtwi_dwnld = readrba::read_rba(series_id = "FRERTWI")
rtwi_tmp = xts::xts(rtwi_dwnld$value, rtwi_dwnld$date, tclass = 'yearqtr')
rtwi = 100 * na.omit(diff(log(rtwi_tmp)))
drtwi = xts::to.quarterly(rtwi, OHLC = FALSE)
y = na.omit(merge(drgdp, pi, cr, drtwi))
plot(y, main = "Australian monetary system",
legend.loc = "bottomleft", col = c("#FF00FF","#990099","#77001b","#330033"))
# Estimation setup
############################################################
N = ncol(y)
p = 4
S_burn = 1e3
S = 5e3
# estimation - lower-triangular model
############################################################
# specify a model
spec = specify_bsvar$new(
as.matrix(y),
p = p,
stationary = rep(TRUE, N)
)
# estimate a model
spec |>
estimate(S = S_burn) |>
estimate(S = S) -> post
# compute and plot impulse responses
post |>
compute_impulse_responses(horizon = 20) |>
plot()
# compute and plot forecast error variance decompositions
post |>
compute_variance_decompositions(horizon = 20) |>
plot()
# compute and plot structural shocks
post |>
compute_structural_shocks() |>
plot()
# compute and plot fitted values
post |>
compute_fitted_values() |>
plot()
# compute and plot forecasts
post |>
forecast(horizon = 8) |>
plot(data_in_plot = 0.3)