hdarjus / sv-comparison Goto Github PK
View Code? Open in Web Editor NEWComparison of different implementations of the same stochastic volatility model (stochvol, JAGS, Stan)
License: MIT License
Comparison of different implementations of the same stochastic volatility model (stochvol, JAGS, Stan)
License: MIT License
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.