Learn R Programming

factorstochvol (version 0.8.1)

fsvsample: Markov Chain Monte Carlo (MCMC) Sampling for the Factor Stochastic Volatility Model.

Description

fsvsample simulates from the joint posterior distribution and returns the MCMC draws. It is the main workhorse to conduct inference for factor stochastic volatility models in this package.

Usage

fsvsample(y, draws = 1000, burnin = 100, factors = 1, priormu = c(0, 10), priorphi = c(10, 3, 3, 3), priorsigma = 1, priorfacload = 1, priorng = c(1, 1), columnwise = FALSE, priorh0 = c("stationary", 1), thin = 1, keeptime = "last", runningstore = 1, runningstorethin = 1, runningstoremoments = 2, quiet = FALSE, restrict = "upper", interweaving = 4, signswitch = FALSE, heteroskedastic = TRUE, priorhomoskedastic = NA, expert, startpara, startlatent, startfacload, startfac)

Arguments

y
Data matrix. Each of m rows is assumed to contain a single (univariate) series of length n.
draws
Number of MCMC draws kept after burn-in.
burnin
Number of initial MCMC draws to be discarded.
factors
Number of latent factors to be estimated.
priormu
Vector of length 2 denoting prior mean and standard deviation for unconditional levels of the log-volatility processes.
priorphi
Vector of length 4, indicating the shape parameters for the Beta prior distributions of the transformed parameters (phi+1)/2, where phi denotes the persistence of the log-variances The first two elements of priorphi are interpreted to belong to the idiosyncratic series, the third and fourth element of priorphi are interpreted to belong to the latent factors.
priorsigma
Vector of length m + factors containing the prior volatilities of log-variances Note: If priorsigma has exactly two elements, the first one will be recycled for all idiosyncratic series and the second one will be recycled for all latent factors.
priorfacload
Either a matrix of dimensions m times factors with nonnegative elements or a single number. If a matrix is provided, its elements are the standard deviations of the Gaussian prior distributions for the factor loadings. If a single nonnegative number is provided, it will be recycled accordingly. If a single negative number is provided, a Normal-Gamma shrinkage prior for the factor loadings is assumed, where -priorfacload is interpreted as the shrinkage parameter a.
priorng
Two-element vector with positive entries indicating the Gamma hyperprior's hyperhyperparameters c and d.
columnwise
Set to TRUE if you want to use column-wise shrinkage and to FALSE for row-wise shrinkage. For details please see the paper by Kastner et al. (2016).
priorh0
Vector of length 1, 2, or m + factors, containing information about the Gaussian prior for the initial log-variances The first m elements are used for the idiosyncratic log-variances, the last factors elements are used for the factor log-variances If an element of priorh0 is a nonnegative number, the conditional prior of the corresponding initial log-volatility h0 is assumed to be Gaussian with mean 0 and standard deviation priorh0 time sigma. If an element of priorh0 is the string 'stationary', the prior of the corresponding initial log volatility is taken to be from the stationary distribution, i.e. h0 is assumed to be Gaussian with mean 0 and variance $sigma^2/(1-phi^2)$. If priorh0 is of length 2 it will be recycled accordingly, whereby the first element is used for all idiosyncratic log-variances and the second element is used for all factor log-variances.
thin
Single number greater or equal to 1, coercible to integer. Every thinth MCMC draw is kept and returned. The default value is 1, corresponding to no thinning of the draws, i.e. every draw is stored.
keeptime
Either a number coercible to a positive integer, or a string equal to "all" or "last". If a number different from 1 is provided, only every keeptimeth latent log-volatility is being monitored. If, e.g., keeptime = 3, draws for the latent log-variances h_1,h_4,h_7,... will be kept. If keeptime is set to "all", this is equivalent to setting it to 1. If keeptime is set to "last" (the default), only draws for the very last latent log-variances h_n are kept.
runningstore
Because most machines these days do not have enough memory to store all draws for all points in time, setting runningstore to an integer greater than 0 will cause fsvsample to store the first runningstoremoments ergodic moments of certain variables of interest. More specifically, mean, variance, skewness, etc. will be stored for certain variables if runningstore is set to a value...
  • >= 1: Latent log-variances h_1,h_2,...,h_(n+r).
  • >= 2: Latent factors f_1,...,f_r.
  • >= 3: Latent volatilities sqrt(exp(h_1,h_2,...,h_(n+r))).
  • >= 4: Conditional covariance matrix and the square roots of its diagonal elements.
  • >= 5: Conditional correlation matrix.
  • >= 6: Communalities, i.e. proportions of variances explained through the common factors.
runningstorethin
How often should the calculation of running moments be conducted? Set to a value > 1 if you want to avoid time consuming calculations at every MCMC iteration.
runningstoremoments
Selects how many running moments (up to 4) should be calculated.
quiet
Logical value indicating whether the progress bar and other informative output during sampling should be omitted. The default value is FALSE, implying verbose output.
restrict
Either "upper" or "none", indicating whether the factor loadings matrix should be restricted to have zeros above the diagonal ("upper") or whether all elements should be estimated from the data ("none"). Setting restrict to "upper" often stabilizes MCMC estimation and can be important for identifying the factor loadings matrix, however, it imposes a dependence on how the data are ordered. Setting restrict to "none" is usually the preferred option if identification of the factor loadings matrix is of less concern but covariance estimation or prediction is the goal. Alternatively, restrict can be a logical matrix of dimension c(m, r) indicating which elements should be unrestricted (where restrict is FALSE) or zero (where restrict is TRUE).
interweaving
The following values for interweaving the factor loadings are accepted:
  • 0: No interweaving.
  • 1: Shallow interweaving through the diagonal entries.
  • 2: Deep interweaving through the diagonal entries.
  • 3: Shallow interweaving through the largest absolute entries in each column.
  • 4: Deep interweaving through the largest absolute entries in each column.

For details please see Kastner et al. (2016). A value of 4 is the highly recommended default.

signswitch
Set to TRUE to turn on a random sign switch of factors and loadings. Note that the signs of each factor loadings matrix column and the corresponding factor cannot be identified from the likelihood.
heteroskedastic
Vector of length 1, 2, or m + factors, containing logical values indicating whether time-varying (heteroskedastic = TRUE) or constant (heteroskedastic = FALSE) variance should be estimated. If heteroskedastic is of length 2 it will be recycled accordingly, whereby the first element is used for all idiosyncratic variances and the second element is used for all factor variances.
priorhomoskedastic
Only used if at least one element of heteroskedastic is set to FALSE. In that case, priorhomoskedastic must be must be a matrix with positive entries and dimension c(factors + m, 2). Values in column 1 will be interpreted as shape and values in column 2 will be interpreted as the rate parameter of the corresponding inverse gamma prior distribution.
expert
optional named list of expert parameters for the univariate SV models (will be passed to the stochvol package). For most applications, the default values probably work best. Interested users are referred to Kastner and Frühwirth-Schnatter (2014) and Kastner (2016). If expert is provided, it may contain the following named elements:
  • parameterization: Character string equal to "centered", "noncentered", "GIS_C", or "GIS_NC". Defaults to "GIS_C".
  • mhcontrol: Single numeric value controlling the proposal density of a Metropolis-Hastings (MH) update step when sampling sigma. If mhcontrol is smaller than 0, an independence proposal will be used, while values greater than zero control the stepsize of a log-random-walk proposal. Defaults to -1.
  • gammaprior: Single logical value indicating whether a Gamma prior for sigma^2 should be used. If set to FALSE, an Inverse Gamma prior is employed. Defaults to TRUE.
  • truncnormal: Single logical value indicating whether a truncated Gaussian distribution should be used as proposal for draws of phi. If set to FALSE, a regular Gaussian prior is employed and the draw is immediately discarded when values outside the unit ball happen to be drawn. Defaults to FALSE.
  • mhsteps: Either 1, 2, or 3. Indicates the number of blocks used for drawing from the posterior of the parameters. Defaults to 2.
  • proposalvar4sigmaphi: Single positive number indicating the conditional prior variance of sigma*phi in the ridge proposal density for sampling (mu, phi). Defaults to 10^8.
  • proposalvar4sigmatheta: Single positive number indicating the conditional prior variance of sigma*theta in the ridge proposal density for sampling (mu, phi). Defaults to 10^12.
startpara
optional named list, containing the starting values for the parameter draws. If supplied, startpara must contain three elements named mu (vector of length m), phi (vector of length m+r) and sigma (vector of length m+r). The elements of mu can be arbitrary numerical values, the phis must be real numbers between -1 and 1, and the sigmas must be positive real numbers.
startlatent
optional numeric matrix of dimension c(n, m + factors), containing the starting values of the latent log-variances.
startfacload
optional numeric matrix of dimension c(m, factors), containing the starting values of the factor loadings.
startfac
optional numeric matrix of dimension c(factors, n), containing the starting values of the latent factors.

Value

The value returned is a list object of class fsvdraws holding
  • fArray containing factor draws from the posterior distribution.
  • paraArray containing parameter draws form the posterior distribution.
  • hArray containing idiosyncratic and factor log-variance draws.
  • facloadArray containing draws from the posterior distribution of the factor loadings matrix.
  • yMatrix containing the data supplied.
  • runningstoreList whose elements contain ergodic moments of certain variables of interest. See argument runningstore for details about what is being stored here.
To display the output, use print, summary and plot. The print method simply prints the posterior draws (which is very likely a lot of output); the summary method displays the summary statistics currently stored in the object; the plot method plot.fsvdraws gives a graphical overview.

Details

For details concerning the factor SV algorithm please see Kastner et al. (2016), details about the univariate SV estimation can be found in Kastner and Frühwirth-Schnatter (2014).

References

Kastner, G., Frühwirth-Schnatter, S., and Lopes, H.F. (2016). Efficient Bayesian Inference for Multivariate Factor Stochastic Volatility Models Research Report Series / Department of Statistics and Mathematics, 128. https://epub.wu.ac.at/4875/.

Kastner, G. (2016). Dealing with stochastic volatility in time series using the R package stochvol. Journal of Statistical Software, 69(5), 1--30, http://dx.doi.org/10.18637/jss.v069.i05.

Kastner, G. and Frühwirth-Schnatter, S. (2014). Ancillarity-sufficiency interweaving strategy (ASIS) for boosting MCMC estimation of stochastic volatility models. Computational Statistics & Data Analysis, 76, 408--423, http://dx.doi.org/10.1016/j.csda.2013.01.002.

Examples

Run this code
## Not run: 
# # Load exchange rate data (ships with stochvol):
# data(exrates, package = "stochvol")
# exrates$date <- NULL
# 
# # Compute the de-meaned percentage log returns:
# dat <- 100 * logret(exrates, demean = TRUE)
# 
# # We are going to fit a one-factor model so the ordering is irrelevant
# # NOTE that these are very few draws, you probably want more...
# res <- fsvsample(dat, factors = 1, draws = 2000, burnin = 1000, runningstore = 6)
# 
# voltimeplot(res)
# 
# corimageplot(res, nrow(dat), plotCI = 'circle')
# 
# oldpar <- par(ask = TRUE)
# plot(res)
# par(oldpar)
# ## End(Not run)

Run the code above in your browser using DataLab