pymc-devs / pymc

Bayesian Modeling and Probabilistic Programming in Python
https://docs.pymc.io/
Other
8.69k stars 2.01k forks source link

GARCH #690

Closed akuz closed 8 years ago

akuz commented 9 years ago

Feature request: implement GARCH in timeseries.py

twiecki commented 9 years ago

That would be a great addition. It shouldn't be too difficult. There's a pretty good description and model in the stan manual: http://mc-stan.org/manual.html which should be easy to port.

springcoil commented 8 years ago

Taking the GARCH (1,1) model here just to put it down as an example.

    data {
      int<lower=0> T;
      real r[T];
      real<lower=0> sigma1;
    }
    parameters {
real mu;
// number of time points
// return at time t
// average return
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 * pow(r[t-1] - mu, 2)
                         + beta1 * pow(sigma[t-1], 2));
} model {
      r ~ normal(mu,sigma);
    }

I've no experience of porting from STAN to PyMC3 but I reckon I could give it a shot in the new year.

fonnesbeck commented 8 years ago

You would probably have to implement this similarly to the GaussianRandomWalk class, by using 2 views of sigma indexed at different offsets. I predict it will be ugly.

akuz commented 8 years ago

Should not be harder than the stochastic volatility example, maybe I can have a go in the future ;)

springcoil commented 8 years ago

Once https://github.com/pymc-devs/pymc3/pull/963 is added in - we have this issue resolved :) Only 8 months later :)

springcoil commented 8 years ago

Assuming https://github.com/pymc-devs/pymc3/pull/965 is accepted this can be closed :) Can someone close this for me and @akuz