I'm trying to create function that provides historical volatility after getting symbol from Yahoo. However, when I pass output to volatility function it doesn't like it; The Get variable gets assigned a vector with quotes, e.g. "SPY", but the volatility function only takes without quotes (SPY no "SPY"). I try to take quotes off using noquote() and now get following error:
Error in log(x) : Non-numeric argument to mathematical function
My code
require(quantmod)
vClose = function(X){
Get <- getSymbols(X, from="2000-01-01", src="yahoo")
Set <- noquote(Get)
volatility(Set, calc="close")
}
Any help would be great.
Just set auto.assign=FALSE
in your call to getSymbols
:
require(quantmod)
Get <- getSymbols("SPY", from="2000-01-01", auto.assign=FALSE)
volatility(Get, calc="close")