Skip to content

TTR, volatility(), historical volatility calculation methods differ

3 messages · Joshua Ulrich, S

S
#
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.
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.
#
On Mon, Dec 26, 2011 at 3:13 PM, algotr8der <algotr8der at gmail.com> wrote:
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
2 days later
S
#
Issue #1 is accurate as per the original papers
Issue #2 has been fixed in v119 i.e variance terms are added together

https://r-forge.r-project.org/scm/viewvc.php/pkg/R/volatility.R?view=markup&root=ttr&pathrev=119

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