[R-SIG-Finance] TTR, volatility(), historical volatility calculation methods differ

Joshua Ulrich josh.m.ulrich at gmail.com
Mon Dec 26 23:22:46 CET 2011


On Mon, Dec 26, 2011 at 3:13 PM, algotr8der <algotr8der at gmail.com> wrote:
> 1) Garman-Klass volatility as defined by Euan Sinclair in his book
> "volatility trading" on page 23:
>
> http://oneryng.com/library/ViolatilityTrading.pdf
>
>            Cl1 <- lag(OHLC[, 4])
>             s <- sqrt(N/n * runSum(0.5 * log(OHLC[, 2]/OHLC[, 3])^2 - (2 *
> log(2) - 1) * log(OHLC[, 4]/Cl1)^2, n))
>
> In the volatility function in the TTR package has (defined by the sitmo
> website):
>
> http://web.archive.org/web/20081224134053/http://www.sitmo.com/eq/402
>
>        s <- sqrt(N/n * runSum(0.5 * log(OHLC[, 2]/OHLC[, 3])^2 - (2 *
> log(2) - 1) * log(OHLC[, 4]/OHLC[, 1])^2, n))
>
> The difference is with the last term i.e. OHLC[,1] - today's open is used in
> the denominator in the TTR package rather than yesterday's close (Cl1). I
> have read various documents that use the same definition as Dr. Sinclair.
> Which is correct and why?
>
> 2) Yang Zhang volatility as defined by Euan Sinclair in his book "volatility
> trading"  on page 24-25 :
>
>         k <- 0.34/(1 + (n + 1)/(n - 1))
>        s2o <- N/(n - 1) * runSum(log(OHLC[, 1]/Cl1), n))^2
>        s2c <- N/(n - 1) * runSum(log(OHLC[, 4]/OHLC[, 1]), n))^2
>        s2rs <- volatility(OHLC = OHLC, n = n, calc = "rogers.satchell", N =
> N, ...)
>        s <-  sqrt(s2o + k * s2c + (1 - k) * (s2rs)^2, n)
>
>
> But the volatility function in the TTR package has:
>
> http://web.archive.org/web/20081224134117/http://www.sitmo.com/eq/417
>
>            k <- 0.34/(1 + (n + 1)/(n - 1))
>        s2o <- N/(n - 1) * runSum(log(OHLC[, 1]/Cl1) - 1/n *
>            runSum(log(OHLC[, 1]/Cl1), n))^2
>        s2c <- N/(n - 1) * runSum(log(OHLC[, 4]/OHLC[, 1]) -
>            1/n * runSum(log(OHLC[, 4]/OHLC[, 1]), n))^2
>        s2rs <- volatility(OHLC = OHLC, n = n, calc = "rogers.satchell",
>            N = N, ...)
>        s <- s2o + k * s2c + (1 - k) * s2rs
>
> There are multiple differences - firstly the mean of the uo and uc are not
> present in Dr. Sinclair's version and moreover the last term in the TTR
> package seems to add a standard deviation (s2rs) with 2 variance
> calculations (s2c and s2o).
>
> I would greatly appreciate if someone can comment on which versions are
> correct.  Thank you.
>
The calculations in most recent revisions on R-forge match the
original papers.  I can't comment on Euan Sinclair's calculations.

Best,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com



More information about the R-SIG-Finance mailing list