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

algotr8der algotr8der at gmail.com
Mon Dec 26 22:13:26 CET 2011


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. 

> sessionInfo()
R version 2.13.0 (2011-04-13)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] C/en_US.UTF-8/C/C/C/C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] TTR_0.21-0 xts_0.8-0  zoo_1.6-5 

loaded via a namespace (and not attached):
[1] grid_2.13.0     lattice_0.19-26 tools_2.13

--
View this message in context: http://r.789695.n4.nabble.com/TTR-volatility-historical-volatility-calculation-methods-differ-tp4235583p4235583.html
Sent from the Rmetrics mailing list archive at Nabble.com.



More information about the R-SIG-Finance mailing list