# When computing Garman-Klass volatility in R why does it leave out the ten first values?

I ran this code in R

vGK <- volatility(ohlc, n = 10, calc="garman", N = 260, mean0 = FALSE)


and the ten first values appeared like this:

[1]         NA         NA         NA         NA
[5]         NA         NA         NA         NA
[9]         NA


Is it because the TTR package estimates the average over last 10 days (hence the n=10)? And that's why the values are smoothed?

• You're actually showing the first 9 values, I guess the 10th value is not NA? Mar 13 '17 at 18:37
• Ah, yes, that is correct. Mar 13 '17 at 18:40

Use the source Luke:

> library(TTR)
> volatiliy

function (OHLC, n = 10, calc = "close", N = 260, mean0 = FALSE, ...)
{
OHLC <- try.xts(OHLC, error = as.matrix)
calc <- match.arg(calc, c("close", "garman.klass", "parkinson",
"rogers.satchell", "gk.yz", "yang.zhang"))

<snip>

if (calc == "garman.klass") {
s <- sqrt(N/n * runSum(0.5 * log(OHLC[, 2]/OHLC[, 3])^2 -
(2 * log(2) - 1) * log(OHLC[, 4]/OHLC[, 1])^2, n))
}

<snip>

reclass(s, OHLC)
}


clearly the TTR package is using runSum which seems to be rather complicated on it own. However, we can simply do

> runSum(1:11, n = 10)
NA NA NA NA NA NA NA NA NA 55 65


to see that indeed the first 9 values of runSum called with n = 10 generate 9 NA values. In R those NA's will propagate.

This intuitively makes sense for the reason you suggest in your question.

• Please don't forget to accept this answer if it answered this question for you. Mar 14 '17 at 19:27