While I can manually use quantmod to collect volatilities on a stock-by-stock basis, such as:
library(quantmod)
library(TTR)
getSymbols("SPY",from="2010-01-02", to="2020-01-02")
vol=volatility(SPY,n=252,N=252,calc="close"),
This requires me to manually copy the symbol, (in the case above it is SPY
), to the volatility function.
I have been trying to generate volatilities for a vector of symbols, but have unable to get this working without having to manually enter each symbol into the volatility function.
How can I pass the xts zoo output from getsymbols into the volatility function?