R: Volatility

volatility {TTR} | R Documentation

## Volatility

### Description

Selected volatility estimators/indicators; various authors.

### Usage

    volatility(OHLC, n = 10, calc = "close", N = 260, mean0 = FALSE, ...)

### Arguments

`OHLC` | Object that is coercible to xts or matrix and contains Open-High-Low-Close prices (or only Close prices, if `calc="close"`).
`n` | Number of periods for the volatility estimate.
`calc` | The calculation (type) of estimator to use.
`N` | Number of periods per year.
`mean0` | Use a mean of 0 rather than the sample mean.
`...` | Arguments to be passed to/from other methods.

### Details

- Close-to-Close Volatility (`calc="close"`)

  sqrt(N) * runSD(ROC(Cl), n-1)

- OHLC Volatility: Garman and Klass (`calc="garman.klass"`)
  The Garman and Klass estimator for estimating historical volatility assumes Brownian motion with zero drift and no opening jumps (i.e. the opening = close of the previous period). This estimator is 7.4 times more efficient than the close-to-close estimator.

  sqrt(N/n * runSum(0.5 * log(Hi/Lo)^2 - (2*log(2)-1) * log(Cl/Op)^2, n))

- High-Low Volatility: Parkinson (`calc="parkinson"`)
  The Parkinson formula for estimating the historical volatility of an underlying based on high and low prices.

  sqrt(N/(4*n*log(2)) * runSum(log(Hi/Lo)^2, n))

- OHLC Volatility: Rogers and Satchell (`calc="rogers.satchell"`)
  The Roger and Satchell historical volatility estimator allows for non-zero drift, but assumed no opening jump.

  sqrt(N/n * runSum(log(Hi/Cl) * log(Hi/Op) + log(Lo/Cl) * log(Lo/Op), n))

- OHLC Volatility: Garman and Klass - Yang and Zhang (`calc="gk.yz"`)
  This estimator is a modified version of the Garman and Klass estimator that allows for opening gaps.

  sqrt(N/n * runSum(log(Op/lag(Cl,1))^2 + 0.5 * log(Hi/Lo)^2 - (2*log(2)-1) * log(Cl/Op)^2 , n))

- OHLC Volatility: Yang and Zhang (`calc="yang.zhang"`)
  The Yang and Zhang historical volatility estimator has minimum estimation error, and is independent of drift and opening gaps. It can be interpreted as a weighted average of the Rogers and Satchell estimator, the close-open volatility, and the open-close volatility.

  Users may override the default values of α (1.34 by default) or k used in the calculation by specifying `alpha` or `k` in `...`, respectively. Specifying `k` will cause `alpha` to be ignored, if both are provided.

  s <- sqrt(s2o + k*s2c + (1-k)*(s2rs^2))

  s2o <- N * runVar(log(Op/lag(Cl,1)), n=n)

  s2c <- N * runVar(log(Cl/Op), n=n)

  s2rs <- volatility(OHLC, n, "rogers.satchell", N, ...)

  k <- (alpha-1) / (alpha + (n+1)/(n-1))

### Value

A object of the same class as `OHLC` or a vector (if `try.xts` fails) containing the chosen volatility estimator values.

### Author(s)

Joshua Ulrich

### References

The following sites were used to code/document these indicators. All were created by Thijs van den Berg under the GNU Free Documentation License and were retrieved on 2008-04-20. The original links are dead, but can be accessed via internet archives.
Close-to-Close Volatility (`calc="close"`):
https://web.archive.org/web/20100421083157/http://www.sitmo.com/eq/172
OHLC Volatility: Garman Klass (`calc="garman.klass"`):
https://web.archive.org/web/20100326172550/http://www.sitmo.com/eq/402
High-Low Volatility: Parkinson (`calc="parkinson"`):
https://web.archive.org/web/20100328195855/http://www.sitmo.com/eq/173
OHLC Volatility: Rogers Satchell (`calc="rogers.satchell"`):
https://web.archive.org/web/20091002233833/http://www.sitmo.com/eq/414
OHLC Volatility: Garman Klass - Yang Zhang (`calc="gk.yz"`):
https://web.archive.org/web/20100326215050/http://www.sitmo.com/eq/409
OHLC Volatility: Yang Zhang (`calc="yang.zhang"`):
https://web.archive.org/web/20100326215050/http://www.sitmo.com/eq/409

### See Also

See `TR` and `chaikinVolatility` for other volatility measures.

### Examples

    data(ttrc)
    ohlc <- ttrc[,c("Open","High","Low","Close")]
    vClose <- volatility(ohlc, calc="close")
    vClose0 <- volatility(ohlc, calc="close", mean0=TRUE)
    vGK <- volatility(ohlc, calc="garman")
    vParkinson <- volatility(ohlc, calc="parkinson")
    vRS <- volatility(ohlc, calc="rogers")

[Package TTR version 0.23-1 Index]