Giter VIP home page Giter VIP logo

sv-comparison's People

Contributors

hdarjus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

lnsongxf

sv-comparison's Issues

Not doing a loop in stan-nc

Hello! I'm kind of confused by the loop here in stan-nc

  for (i in 1:N) {
    if (i == 1) {
      h_i_mean[i] = 0;
      h_i_sigma[i] = pow(1-square(phi), -0.5);
    } else {
      h_i_mean[i] = fma(phi, h[i-1], 0);
      h_i_sigma[i] = 1;
    }
    exph[i] = exp(fma(h[i], 0.5*sigma, 0.5*mu));
  }

I thought stoch vol models have to depend on previous points of h, but it appears you've written this in a way that could actually be fully vectorized like the below for a good bit of speedup

data {
  int<lower=0> N;
  real y[N];
}

transformed data {
  real<lower=0> phi_prior_a = 1;
  real<lower=0> phi_prior_b = 1;
  real mu_prior_mu = 0;
  real<lower=0> mu_prior_sigma = 100;
  real<lower=0> sigma_prior_shape = 0.5;
  real<lower=0> sigma_prior_rate = 0.5;
}

parameters {
  vector[N] h;
  real<lower=0,upper=1> phi_beta;
  real mu;
  real<lower=0> sigma2;
}

transformed parameters {
  real<lower=-1,upper=1> phi = fma(phi_beta, 2, -1);
  real<lower=0> sigma = sqrt(sigma2);
  vector[N] h_i_mean;
  vector<lower=0>[N] h_i_sigma;
  h_i_mean[1] = 0;
  h_i_sigma[1] = pow(1 - square(phi), -0.5);
  h_i_sigma[2:N] = rep_vector(1, (N - 1));
  h_i_mean[2:N] = phi * h[1:(N-1)]; // This added 0 before, but idt that's needed?
}

model {
  mu ~ normal(mu_prior_mu, mu_prior_sigma);
  phi_beta ~ beta(phi_prior_a, phi_prior_b);
  sigma2 ~ gamma(sigma_prior_shape, sigma_prior_rate);

  h ~ normal(h_i_mean, h_i_sigma);
  y ~ normal(0, exp(h * (0.5 * sigma) + (0.5 * mu)));
}

But, is this correct? Looking at the stoch vol model from the Stan docs here it seems like you do need a loop to be updating off of past values of h. Is there a paper somewhere or an explainer on how this model avoids the time dependence? If this does work that would be super awesome as we will have a new matrix type soon in stan that would make this very fast

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.