\[ \]
\[ \]
\[ \]
\[ \]
\[ \]
\[ \]
\[ \]
library(bsvars)
data(us_fiscal_lsuw)
us_fiscal_lsuw |>
specify_bsvar$new() |>
estimate(S = 1000) |>
estimate(S = 10000) -> post
post |> compute_impulse_responses(horizon = 12) |> plot()
post |> compute_variance_decompositions(horizon = 12) |> plot()
post |> compute_historical_decompositions() |> plot()
post |> compute_structural_shocks() |> plot()
post |> compute_conditional_sd() |> plot()
post |> forecast(horizon = 12) |> plot()
post |> verify_identification() |> summary()
library(bsvarSIGNs)
data(optimism)
optimism |>
specify_bsvarSIGN$new() |>
estimate(S = 10000) -> post
post |> compute_impulse_responses(horizon = 12) |> plot()
post |> compute_variance_decompositions(horizon = 12) |> plot()
post |> compute_historical_decompositions() |> plot()
post |> compute_structural_shocks() |> plot()
post |> compute_conditional_sd() |> plot()
post |> forecast(horizon = 12) |> plot()
\[\begin{align} \text{równanie VAR: }&& y_t &= \mathbf{A}_1 y_{t-1} + \dots + \mathbf{A}_p y_{t-p} + \mathbf{A}_d x_{t} + \epsilon_t\\[1ex] \text{równanie structuralne: }&& \mathbf{B}\epsilon_t &= u_t\\[1ex] \text{structuralne szoki: }&& u_t |Y_{t-1} &\sim N_N\left(\mathbf{0}_N,\text{diag}\left(\boldsymbol\sigma_t^2\right)\right) \end{align}\]
homoskedastyczność \(\boldsymbol\sigma_{n.t}^2 = 1\)
zmienność stochastyczna
stacjonarny proces Markova dla zmienności
nieparametryczny proces Markova dla zmienności
rozkłady szoków
\[\begin{align} &&&\\ \text{równanie strukturalne: }&& \epsilon_t &= \mathbf{B}^{-1}u_t = \mathbf{\Theta}_0 u_t\\[1ex] \text{błędy statystyczne: }&& \epsilon_t |Y_{t-1} &\sim N_N\left(\mathbf{0}_N,\Sigma\right)\\[1ex] \text{kowariancja: }&& \mathbf\Sigma &= \mathbf{B}^{-1}\mathbf{B}^{-1\prime} = \Theta_0\Theta_0' \end{align}\]
Wstaw równanie VAR w równanie strukturalne:
\[\begin{align} \mathbf{B}y_t &= \mathbf{B}\mathbf{A}_1 y_{t-1} + \dots + \mathbf{B}\mathbf{A}_p y_{t-p} + \mathbf{B}\boldsymbol\mu_0 + u_t\\[1ex] &\\ \end{align}\]
Niech \(N=2\)
\[\begin{align} \mathbf{B}y_t &= \begin{bmatrix}B_{11}&B_{12}\\B_{21}&B_{22}\end{bmatrix}\begin{bmatrix}y_{1t}\\y_{2t}\end{bmatrix} \end{align}\]
Wstaw równanie strukturalne dla \(\epsilon_t\) w równanie VAR:
\[\begin{align} y_t &= \mathbf{A}_1 y_{t-1} + \dots + \mathbf{A}_p y_{t-p} + \boldsymbol\mu_0 + \mathbf{B}^{-1}u_t\\[1ex] y_t &= \mathbf{A}_1 y_{t-1} + \dots + \mathbf{A}_p y_{t-p} + \boldsymbol\mu_0 + \mathbf{\Theta}_0 u_t \end{align}\]
Niech \(N=2\)
\[\begin{align} \begin{bmatrix}y_{1t}\\y_{2t}\end{bmatrix} &= \dots + \begin{bmatrix}\Theta_{11}&\Theta_{12}\\\Theta_{21}&\Theta_{22}\end{bmatrix}\begin{bmatrix}u_{1t}\\ u_{2t}\end{bmatrix} \end{align}\]
\[\begin{align} &\\ \mathbf\Sigma &= \mathbf{B}^{-1}\mathbf{B}^{-1\prime}\\[1ex] \end{align}\]
\[\begin{align} &\\ \mathbf\Sigma &= \mathbf{B}^{-1}\mathbf{B}^{-1\prime}\\[1ex] \end{align}\]
Niech \(N=2\)
\[\begin{align} \begin{bmatrix}\sigma_1^2&\sigma_{12}\\ \sigma_{12}&\sigma_2^2\end{bmatrix} &\qquad \begin{bmatrix}B_{11}&B_{12}\\ B_{21}&B_{22}\end{bmatrix}\\[1ex] \end{align}\]
\[\begin{align} \begin{bmatrix}\sigma_1^2&\sigma_{12}\\ \sigma_{12}&\sigma_2^2\end{bmatrix} &\qquad \begin{bmatrix}B_{11}& 0\\ B_{21}&B_{22}\end{bmatrix}\\[1ex] \end{align}\]
Rozważ:
\[\begin{align} \mathbf\Sigma_1 &= \mathbf{B}_0^{-1}\text{diag}\left(\boldsymbol\sigma_1^2\right)\mathbf{B}_0^{-1\prime}\\[1ex] \mathbf\Sigma_2 &= \mathbf{B}_0^{-1}\text{diag}\left(\boldsymbol\sigma_2^2\right)\mathbf{B}_0^{-1\prime} \end{align}\]
\[\begin{align} \mathbf\Sigma_1 &= \mathbf{B}_0^{-1}\text{diag}\left(\boldsymbol\sigma_1^2\right)\mathbf{B}_0^{-1\prime}\\[1ex] \mathbf\Sigma_2 &= \mathbf{B}_0^{-1}\text{diag}\left(\boldsymbol\sigma_2^2\right)\mathbf{B}_0^{-1\prime} \end{align}\]
Rozważ uogólnienie
\[\begin{align} u_t |Y_{t-1} &\sim N_N\left(\mathbf{0}_N, \text{diag}\left(\boldsymbol\sigma_t^2\right)\right)\\[1ex] \mathbf\Sigma_t &= \mathbf{B}_0^{-1}\text{diag}\left(\boldsymbol\sigma_t^2\right)\mathbf{B}_0^{-1\prime} \end{align}\]
Wybierz model dla \(\boldsymbol\sigma_t^2\) o najlepszych właściwościach.
\[\begin{align} \text{relacje strukturalne:}&&\mathbf{Q}\mathbf{B}\epsilon_t &= \mathbf{Q}u_t\\[1ex] \text{efekty strukturalne:}&&\epsilon_t &= \mathbf{\Theta}_0\mathbf{Q}'\mathbf{Q} u_t\\[1ex] \end{align}\]
\[\begin{align} \mathbf\Sigma &= \mathbf{B}^{-1}\mathbf{Q}'\mathbf{Q}\mathbf{B}^{-1\prime} = \mathbf{\Theta}_0\mathbf{Q}'\mathbf{Q}\mathbf{\Theta}_0^{\prime}\\[1ex] \mathbf{Q}'\mathbf{Q} &= \mathbf{I}_N\\[1ex] \end{align}\]
\[\begin{align} \text{relacje strukturalne:}&&\tilde{\mathbf{B}}\epsilon_t &= \tilde{u}_t\\[1ex] \text{efekty strukturalne:}&&\epsilon_t &= \tilde{\mathbf{\Theta}}_0\tilde{u}_t\\[1ex] \end{align}\]
\[\begin{align} &\\ \text{wariancja warunkowa:}&&\sigma_{n.t}^2 &= \exp\left\{\omega_n h_{n.t}\right\}\\ \text{w skali log:}&&h_{n.t} &= \rho_n h_{n.t-1} + v_{n.t}\\ \text{innowacje zmienności:}&&v_{n.t}&\sim N\left(0,1\right)\\ \end{align}\]
verify_identification()
przez ocene restrykcji \(H_0:\omega_n = 0\)\[\begin{align} &\\ \text{wariancja warunkowa:}&&\sigma_{n.t}^2 &= \exp\left\{ \tilde{h}_{n.t}\right\}\\ \text{w skali log:}&&\tilde{h}_{n.t} &= \rho_n \tilde{h}_{n.t-1} + \tilde{v}_{n.t}\\ \text{innowacje zmienności:}&&\tilde{v}_{n.t}&\sim N\left(0,\omega_n^2\right)\\ \end{align}\]
\[\begin{align} &\\ \text{szoki strukturalne:}&&\mathbf{u}_t\mid s_t \sim N\left( \mathbf{0}_N, \text{diag}\left(\boldsymbol{\sigma}_{s_t}^2\right) \right)\\ \text{a priori:}&& M^{-1}\left(\boldsymbol{\sigma}_{1}^2, \dots, \boldsymbol{\sigma}_{M}^2\right) \sim Dirichlet(\underline{a}\boldsymbol\imath')\\ \text{proces Markowa:}&& s_t\sim \text{Markov}(\mathbf{P},\boldsymbol\pi_0) \end{align}\]
verify_identification()
przez ocenę restrykcji \(H_0:\boldsymbol{\sigma}_{1}^2, \dots, \boldsymbol{\sigma}_{M}^2 = 1\)\[\begin{align} &\\ \text{szoki strukturalne:}&&\mathbf{u}_t\mid s_t \sim N\left( \mathbf{0}_N, \text{diag}\left(\boldsymbol{\sigma}_{s_t}^2\right) \right)\\ \text{a priori:}&& M^{-1}\left(\boldsymbol{\sigma}_{1}^2, \dots, \boldsymbol{\sigma}_{M}^2\right) \sim Dirichlet(\underline{a}\boldsymbol\imath')\\ \text{prawdopodobieństwo:}&& Pr[s_t]=\boldsymbol\pi_0 \end{align}\]
verify_identification()
przez ocenę restrykcji \(H_0:\boldsymbol{\sigma}_{1}^2, \dots, \boldsymbol{\sigma}_{M}^2 = 1\)\[\begin{align} &&&\\ \text{szoki strukturalne:}&&\mathbf{u}_t\mid\mathbf{x}_t &\sim t\left( \mathbf{0}_N, \mathbf{I}_N, \nu \right) \end{align}\]
verify_identification()
przez ocenę restrykcji \(H_0:\nu \rightarrow\infty\)\[ \]
Based on Turnip (2017)
\[\begin{align} y_t = \begin{bmatrix} \Delta rgdp_t & \pi_t & cr_t & \Delta rtwi_t \end{bmatrix}' \end{align}\]
\[\begin{align} \begin{bmatrix} B_{11}&0&0&0\\ B_{21}&B_{22}&0&0\\ B_{31}&B_{32}&B_{33}&0\\ B_{41}&B_{42}&B_{43}&B_{44} \end{bmatrix} \begin{bmatrix} \Delta rgdp_t \\ \pi_t \\ cr_t \\ \Delta rtwi_t \end{bmatrix} \end{align}\]
# 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 - lower-triangular model
############################################################
library(bsvars)
set.seed(123)
spec = specify_bsvar$new(
as.matrix(y),
p = 4,
stationary = rep(TRUE, 4)
)
spec |>
estimate(S = 1000) |>
estimate(S = 5000) -> post
**************************************************|
bsvars: Bayesian Structural Vector Autoregressions|
**************************************************|
Gibbs sampler for the SVAR model |
**************************************************|
Progress of the MCMC simulation for 1000 draws
Every draw is saved via MCMC thinning
Press Esc to interrupt the computations
**************************************************|
**************************************************|
bsvars: Bayesian Structural Vector Autoregressions|
**************************************************|
Gibbs sampler for the SVAR model |
**************************************************|
Progress of the MCMC simulation for 5000 draws
Every draw is saved via MCMC thinning
Press Esc to interrupt the computations
**************************************************|