Learn R Programming

pmhtutorial (version 1.0.0)

pmh_sv: Particle Metropolis-Hastings algorithm for a stochastic volatility model model

Description

Estimates the parameter posterior for \(\theta=\{\mu,\phi,\sigma_v\}\) in a stochastic volatility model of the form \(x_t = \mu + \phi ( x_{t-1} - \mu ) + \sigma_v v_t\) and \(y_t = \exp(x_t/2) e_t\), where \(v_t\) and \(e_t\) denote independent standard Gaussian random variables, i.e. \(N(0,1)\).

Usage

pmh_sv(y, initPar, nPart, T, nIter, stepSize)

Arguments

y

Observations from the model for \(t=1,...,T\).

initPar

An inital value for the parameters \(\theta=\{\mu,\phi,\sigma_v\}\).

nPart

The number of particles to use in the filter.

T

The number of observations.

nIter

The number of iterations in the PMH algorithm.

stepSize

The standard deviation of the Gaussian random walk proposal for \(\theta\).

Value

The trace of the Markov chain exploring the posterior of \(\theta\).

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 {
## Get the data
library("Quandl")
d <- Quandl("NASDAQOMX/OMXS30", start_date="2012-01-02", 
            end_date="2014-01-02", type="zoo")
y <- as.numeric(100 * diff(log(d$"Index Value")))

## Estimate the filtered state
res <- pmh_sv(y, c(0, 0.9, 0.2), nPart=500, T=500, nIter=1000, 
              stepSize=diag(c(0.05, 0.0002, 0.002)))

## Plot the estimate
par(mfrow=c(3,1))
hist(res$thhat[,1], main="", xlab=expression(mu), 
     ylab="marginal posterior", freq=FALSE)
hist(res$thhat[,2], main="", xlab=expression(phi), 
     ylab="marginal posterior", freq=FALSE)
hist(res$thhat[,3], main="", xlab=expression(sigma[v]), 
     ylab="marginal posterior", freq=FALSE)
# }

Run the code above in your browser using DataLab