Hi, I have been using the volatility function from the TTR package and I noticed something that I thought was a bit unusual. I expected that I should be able to calculate the default 10-day volatility using the close estimator starting with 10 or maybe 11 days of data. That's not what I found. It appears that 18 days of data is necessary to calculate a 10-day volatility. For example:
> getSymbols("SPY") [1] "SPY" > volatility(tail(SPY, 10), n = 10, calc = "close", N = 260) Error in `[.xts`(x, beg:(n + beg - 1)) : subscript out of bounds > volatility(tail(SPY, 11), n = 10, calc = "close", N = 260) Error in `[.xts`(x, beg:(n + beg - 1)) : subscript out of bounds > volatility(tail(SPY, 18), n = 10, calc = "close", N = 260) [,1] 2011-05-03 NA 2011-05-04 NA 2011-05-05 NA - edited for brevity - 2011-05-23 NA 2011-05-24 NA 2011-05-25 NA 2011-05-26 0.09481466 Stranger still (at least to me), it appears that 38 days worth of data is necessary to start calculating a 20-day volatility. > volatility(tail(SPY, 37), n = 20, calc = "close", N = 260) Error in `[.xts`(x, beg:(n + beg - 1)) : subscript out of bounds > volatility(tail(SPY, 38), n = 20, calc = "close", N = 260) [,1] 2011-04-04 NA 2011-04-05 NA 2011-04-06 NA - edited for brevity - 2011-05-23 NA 2011-05-24 NA 2011-05-25 NA 2011-05-26 0.1088309 58 days of data is necessary for a 30-day volatility calculation. >From looking at the code for the volatility function, I'm not seeing why so much additional data is needed to calculate the volatility. Does anybody have an idea of why so much additional data is necessary? Thanks. James R version 2.13.0 (2011-04-13) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) _______________________________________________ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.