Learn R Programming

pmhtutorial (version 1.0.0)

example4_sv: Parameter estimation in a simple stochastic volatility model

Description

Minimal working example of parameter estimation in a stochastic volatility model using the particle Metropolis-Hastings algorithm with a bootstrap particle filter for providing an unbiased estimator of the likelihood. The code estimates the parameter posterior for three parameters using real-world data.

Usage

example4_sv(nIter = 7500)

Arguments

nIter

The number of iterations in the PMH algorithm. 100 iterations takes about a minute on a laptop to execute. 7500 iterations are used in the reference below. The length of the burn-in is calculated as one fifth of nIter.

Value

The function returns the estimated marginal parameter posteriors for each parameter, the trace of the Markov chain and the resulting autocorrelation function. The data is also presented with an estimate of the log-volatility.

The function returns a list with the elements:

  • thhat: The estimate of the mean of the parameter posterior.

  • xhat: The estimate of the mean of the log-volatility posterior.

  • thhatSD: The estimate of the standard deviation of the parameter posterior.

  • xhatSD: The estimate of the standard deviation of the log-volatility posterior.

  • iact: The estimate of the integrated autocorrelation time for each parameter.

  • estCov: The estimate of the covariance of the parameter posterior.

Details

The Particle Metropolis-Hastings (PMH) algorithm makes use of a Gaussian random walk as the proposal for the parameters. The data are scaled log-returns from the OMXS30 index during the period from January 2, 2012 to January 2, 2014.

This version of the code makes use of a proposal that is tuned using the pilot run from example3_sv and therefore have better mixing properties.

References

Dahlin, J. & Schoen, T. B. "Getting started with particle Metropolis-Hastings for inference in nonlinear dynamical models." pre-print, arXiv:1511.01707, 2015.

Examples

Run this code
# NOT RUN {
# Use a short run when testing the code on CRAN
# Set nIter manually if running on local computer
# nIter=1000 is usually enough
if(nchar(Sys.getenv("LONG_TEST")) != 0) {
  nIter=7500
} else {
  nIter=5
}
  
# Run the example script
example4_sv(nIter)
# }

Run the code above in your browser using DataLab