I am trying to using the TTR package and volatility() function in R to calculate the rolling 30 day volatility of a spread between two underlyings.
Here is a stripped version of my code so far (already pulled/cleaned data, date matched, etc.):
asset1 <-c(rnorm(100, mean=50))
asset2 <-c(rnorm(100, mean=50))
spread <-c(asset1-asset2)
vClose.spread <-volatility(spread, n=30, calc="close", N=252)
Now the error I get here is:
Error in runCov(x, x, n, use = "all.obs", sample = sample, cumulative) :
Series contain non-leading NAs
In addition: Warning message:
In log(x) : NaNs produced
Any assistance or direction is greatly appreciated.