Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Noise added to unconditional forecast #86

Open
syrop87 opened this issue Sep 25, 2023 · 2 comments
Open

Noise added to unconditional forecast #86

syrop87 opened this issue Sep 25, 2023 · 2 comments
Labels
question Further information is requested

Comments

@syrop87
Copy link

syrop87 commented Sep 25, 2023

Hello,

First, thanks a lot for developing the package! I am relying on it heavily in my daily work.

However, only recently I started to doubt if I understand the details of how the BVAR unconditional forecasts are generated. In predict method there is a line made to add noise to a forecast generated with compute_fcast method.

fcast_store[["fcast"]][i, , ] <- fcast_base + t(crossprod(sigma[j, , ], matrix(rnorm(M * fcast[["horizon"]]), nrow = M)))

I have a two questions on that:

  1. It looks like we want to augment fcast_base with a set of shocks drawn from $N(0, \Sigma)$. But to get that, shouldn't we multiply a sample drawn form $N(0,1)$ by $L$ defined so $\Sigma=LL^T$ (e.g. obtained with Cholesky decomp), instead of multiplying that sample by the covariance matrix itself?
  2. More generally, wouldn't it be more appropriate to add the noise within compute_fcast in a period-by-period manner? I mean doing that within a core loop in compute_fcast, so that Y_f[i+1,] is calculated based Y_f[i, ] that is consistent with added period i noise/shock. Adding all the shocks as a batch after the full path of base forecast was calculated seems inconsistent. The loop that I refer to:
for(i in seq.int(2, 1 + horizon)) {
    Y_f[i, ] <- tcrossprod(Y_f[i - 1, ], beta_comp) +
      c(beta_const, rep(0, M * (lags - 1))) # Maybe go back to normal beta
  }

Thanks,

Pawel

@nk027 nk027 added the question Further information is requested label Oct 1, 2023
@nk027
Copy link
Owner

nk027 commented Oct 1, 2023

Hey Pawel,
You raise good points. I'd have though that sigma is already the Cholesky factor (may be wrong), but the forecast definitely seems off to me. I'll have to put a closer investigation off until a later date, but thanks for raising the issue!
Best,
Nikolas

@nk027
Copy link
Owner

nk027 commented Feb 16, 2024

Hey @syrop87,
your observation wrt to the forecasting noise hits the mark – seems that I introduced this bug while over-optimizing vectorization. We're putting off a fix until the next version, but a patched version of the package is available here: https://github.com/nk027/bvar/tree/dev_fcasts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants