svsample_roll
performs rolling window estimation based on svsample.
A convenience function for backtesting purposes.
svsample_roll( y, designmatrix = NA, n_ahead = 1, forecast_length = 500, n_start = NULL, refit_every = 1, refit_window = c("moving", "expanding"), calculate_quantile = c(0.01), calculate_predictive_likelihood = TRUE, keep_draws = FALSE, parallel = c("no", "multicore", "snow"), n_cpus = 1L, cl = NULL, ... ) svtsample_roll( y, designmatrix = NA, n_ahead = 1, forecast_length = 500, n_start = NULL, refit_every = 1, refit_window = c("moving", "expanding"), calculate_quantile = c(0.01), calculate_predictive_likelihood = TRUE, keep_draws = FALSE, parallel = c("no", "multicore", "snow"), n_cpus = 1L, cl = NULL, ... ) svlsample_roll( y, designmatrix = NA, n_ahead = 1, forecast_length = 500, n_start = NULL, refit_every = 1, refit_window = c("moving", "expanding"), calculate_quantile = c(0.01), calculate_predictive_likelihood = TRUE, keep_draws = FALSE, parallel = c("no", "multicore", "snow"), n_cpus = 1L, cl = NULL, ... ) svtlsample_roll( y, designmatrix = NA, n_ahead = 1, forecast_length = 500, n_start = NULL, refit_every = 1, refit_window = c("moving", "expanding"), calculate_quantile = c(0.01), calculate_predictive_likelihood = TRUE, keep_draws = FALSE, parallel = c("no", "multicore", "snow"), n_cpus = 1L, cl = NULL, ... )
y  numeric vector containing the data (usually logreturns), which
must not contain zeros. Alternatively, 

designmatrix  regression design matrix for modeling the mean. Must
have 
n_ahead  number of time steps to predict from each time window. 
forecast_length  the time horizon at the end of the data set that is used for backtesting. 
n_start  optional the starting time point for backtesting.
Computed from 
refit_every  the SV model is refit every 
refit_window  one of 
calculate_quantile  vector of numbers between 0 and 1.
These quantiles are predicted using 
calculate_predictive_likelihood  boolean. If 
keep_draws  boolean. If 
parallel  one of 
n_cpus  optional positive integer, the number of CPUs to be used in case of
parallel computations. Defaults to 
cl  optional socalled SNOW cluster object as implemented in package

...  Any extra arguments will be forwarded to

The value returned is a list object of class svdraws_roll
holding a list item for every time window. The elements of these list items are
a list object containing two elements: train
is the vector
of indices used for fitting the model, and test
is the vector of indices
used for prediction. The latter is mainly useful if a designmatrix
is provided.
the input parameter calculate_quantiles
.
the input parameter refit_every
.
present only if calculate_predictive_likelihood
is TRUE
. Then it is a number, the expected predictive density
of the observation. The expecation is taken over the joint n_ahead
predictive
distribution of all model parameters.
present only if calculate_quantile
is a nonempty
vector. Then it is a vector of quantiles from the n_ahead
predictive
distribution of y
. It is based on MCMC simulation by using predict
.
present only if keep_draws
is TRUE
. Then it is an
svdraws
object as returned by svsample
.
present only if keep_draws
is TRUE
. Then it is an
svpredict
object as returned by predict.svdraws
.
Functions svtsample_roll
, svlsample_roll
, and svtlsample_roll
are
wrappers around svsample_roll
with convenient default values for the SV
model with terrors, leverage, and both terrors and leverage, respectively.
The function executes svsample
(length(y)  arorder  n_ahead  n_start + 2) %/% refit_every
times.
# \donttest{ # Simulate from the true model sim < svsim(200) # Perform rolling estimation using the vanilla SV # model and default priors roll < svsample_roll(sim, draws = 5000, burnin = 2000, keep_draws = TRUE, forecast_length = 10, n_ahead = 1, refit_every = 1, refit_window = "moving", calculate_predictive_likelihood = TRUE, calculate_quantile = c(0.01, 0.05)) #> Extracted data vector from 'svsim'object. #> Done! #> Summarizing posterior draws... #> Done! #> Summarizing posterior draws... #> Done! #> Summarizing posterior draws... #> Done! #> Summarizing posterior draws... #> Done! #> Summarizing posterior draws... #> Done! #> Summarizing posterior draws... #> Done! #> Summarizing posterior draws... #> Done! #> Summarizing posterior draws... #> Done! #> Summarizing posterior draws... #> Done! #> Summarizing posterior draws... # Perform rolling estimation by making use # of two CPU cores, advanced priors, and multiple # chains with preset initial values. Let us combine # that with an AR(2) specification prior_beta < sv_multinormal(c(1,0,1), rbind(c(1, 0, 0.1), c(0, 0.3, 0.04), c(0.1, 0.04, 0.1))) priorspec < specify_priors(rho = sv_beta(4, 4), latent0_variance = sv_constant(1), beta = prior_beta, nu = sv_exponential(0.05)) startpara < list(list(mu = 9, phi = 0.3), list(mu = 11, sigma = 0.1, phi = 0.95), list(phi = 0.99)) roll < svsample_roll(sim, draws = 5000, burnin = 2000, designmatrix = "ar2", priorspec = priorspec, startpara = startpara, parallel = "snow", n_cpus = 2, n_chains = 3, keep_draws = TRUE, forecast_length = 10, n_ahead = 1, refit_every = 1, refit_window = "expanding", calculate_predictive_likelihood = TRUE, calculate_quantile = c(0.01, 0.05)) #> Extracted data vector from 'svsim'object. #> #> Starting cluster... #> #> Cluster stopped. # }