Description Usage Arguments Details Fast SV General SV Examples
All the heavy lifting in stochvol
is implemented in C++
with the help of R
packages Rcpp
and RcppArmadillo
.
These functions call the MCMC samplers in C++
directly without any
any validation and transformations, expert use only!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37  svsample_fast_cpp(
y,
draws = 1,
burnin = 0,
designmatrix = matrix(NA),
priorspec = specify_priors(),
thinpara = 1,
thinlatent = 1,
keeptime = "all",
startpara,
startlatent,
keeptau = !inherits(priorspec$nu, "sv_infinity"),
print_settings = list(quiet = TRUE, n_chains = 1, chain = 1),
correct_model_misspecification = FALSE,
interweave = TRUE,
myoffset = 0,
fast_sv = get_default_fast_sv()
)
svsample_general_cpp(
y,
draws = 1,
burnin = 0,
designmatrix = matrix(NA),
priorspec = specify_priors(),
thinpara = 1,
thinlatent = 1,
keeptime = "all",
startpara,
startlatent,
keeptau = !inherits(priorspec$nu, "sv_infinity"),
print_settings = list(quiet = TRUE, n_chains = 1, chain = 1),
correct_model_misspecification = FALSE,
interweave = TRUE,
myoffset = 0,
general_sv = get_default_general_sv(priorspec)
)

y 
numeric vector of the observations 
draws 
single positive integer, the number of draws to return (after the burnin) 
burnin 
single positive integer, length of warmup period, this number of draws are discarded from the beginning 
designmatrix 
numeric matrix of covariates. Dimensions:

priorspec 
a 
thinpara 
single number greater or equal to 1, coercible to integer.
Every 
thinlatent 
single number greater or equal to 1, coercible to integer.
Every 
keeptime 
Either 'all' (the default) or 'last'. Indicates which latent volatility draws should be stored. 
startpara 
named list, containing the starting values for the parameter draws. It must contain elements

startlatent 
vector of length 
keeptau 
Logical value indicating whether the 'variance inflation factors' should be stored (used for the sampler with conditional t innovations only). This may be useful to check at what point(s) in time the normal disturbance had to be 'upscaled' by a mixture factor and when the series behaved 'normally'. 
print_settings 
List of three elements:
Please note that this function does not run multiple independent chains
but 
correct_model_misspecification 
Logical value. If 
interweave 
Logical value. If 
myoffset 
Single nonnegative number that is used in

fast_sv 
named list of expert settings. We recommend the use of 
general_sv 
named list of expert settings. We recommend the use of 
The sampling functions are separated into fast SV and general SV. See more details in the sections below.
Fast SV was developed in Kastner and FruehwirthSchnatter (2014). Fast SV estimates an approximate SV model without leverage, where the approximation comes in through auxiliary mixture approximations to the exact SV model. The sampler uses the ancillaritysufficiency interweaving strategy (ASIS) to improve on the sampling efficiency of the model parameters, and it employs allwithoutaloop (AWOL) for computationally efficient Kalman filtering of the conditionally Gaussian state space. Correction for model misspecification happens as a postprocessing step.
Fast SV employs sampling strategies that have been finetuned and specified for
vanilla SV (no leverage), and hence it can be fast and efficient but also more limited
in its feature set. The conditions for the fast SV sampler: rho == 0
; mu
has either a normal prior or it is also constant 0
; the prior for phi
is a beta distribution; the prior for sigma^2
is either a gamma distribution
with shape 0.5
or a mean and variancematched inverse gamma distribution;
either keeptime == 'all'
or correct_model_misspecification == FALSE
.
These criteria are NOT VALIDATED by fast SV on the C++
level!
General SV also estimates an approximate SV model without leverage, where the approximation comes in through auxiliary mixture approximations to the exact SV model. The sampler uses both ASIS and AWOL.
General SV employs adapted random walk MetropolisHastings as the proposal for
the parameters mu
, phi
, sigma
, and rho
. Therefore,
more general prior distributions are allowed in this case.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41  # Draw one sample using fast SV and general SV
y < svsim(40)$y
params < list(mu = 10, phi = 0.9, sigma = 0.1,
nu = Inf, rho = 0, beta = NA,
latent0 = 10)
res_fast < svsample_fast_cpp(y,
startpara = params, startlatent = rep(10, 40))
res_gen < svsample_general_cpp(y,
startpara = params, startlatent = rep(10, 40))
# Embed SV in another sampling scheme
## vanilla SV
len < 40L
draws < 1000L
burnin < 200L
param_store < matrix(NA, draws, 3,
dimnames = list(NULL,
c("mu", "phi", "sigma")))
startpara < list(mu = 0, phi = 0.9, sigma = 0.1,
nu = Inf, rho = 0, beta = NA,
latent0 = 0)
startlatent < rep(0, len)
for (i in seq_len(burnin+draws)) {
# draw the data in the bigger sampling scheme
# now we simulate y from vanilla SV
y < svsim(len, mu = 0, phi = 0.9, sigma = 0.1)$y
# call SV sampler
res < svsample_fast_cpp(y, startpara = startpara,
startlatent = startlatent)
# administrate values
startpara[c("mu","phi","sigma")] <
as.list(res$para[, c("mu", "phi", "sigma")])
startlatent < drop(res$latent)
# store draws after the burnin
if (i > burnin) {
param_store[iburnin, ] <
res$para[, c("mu", "phi", "sigma")]
}
}
### quick look at the traceplots
ts.plot(param_store, col = 1:3)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.