Hi,

I want to estimate a simple GARCH(1,1) in STAN. Until now, I used the following code to simulate an out-of-sample prediction, which, however, doesn’t perform well. So, I want to make one-step-ahead forecast rolling forecast. Does someone have an idea how to write it in STAN.

```
data {
int<lower=2> T;
real y[T];
real<lower=0> sigma1;
int<lower=0> T_pred;
}
parameters {
real mu;
real<lower=0> alpha0;
real<lower=0,upper=1> alpha1;
real<lower=0, upper=(1-alpha1)> beta1;
}
transformed parameters {
real<lower=0> sigma[T];
sigma[1] = sigma1;
for (t in 2:T)
sigma[t] = sqrt(alpha0 +
+ alpha1 * square(y[t - 1] - mu)
+ beta1 * square(sigma[t - 1]));
}
model {
y ~ normal(mu,sigma);
}
generated quantities {
real y_pred[T_pred];
real sigma_pred[T_pred];
sigma_out[1] = sqrt(alpha0 + alpha1 * square(y[T] - mu) + beta1 * square(sigma[T]));
y_pred[1] = normal_rng(mu, sigma_pred[1]);
for (t in 2:T_pred) {
sigma_pred[t] = sqrt(alpha0 + alpha1 * square(y_pred[t - 1] - mu)
+ beta1 * square(sigma_pred[t - 1]));
y_pred[t] = normal_rng(mu, sigma_pred[t]);
}
}
```