Quotes Analysis in R: Quantmod App

I am trying to create a function that provides historical volatility after receiving a symbol from Yahoo. However, when I pass the output to the volatility function, I don't like this; The Get variable is assigned a vector with quotes, for example. "SPY", but the volatility function accepts only quotation marks (SPY no "SPY"). I am trying to strip quotes with noquote () and now get the following error:

Error in log (x): non-numeric argument for math 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.

+5
source share
2 answers

Just set auto.assign=FALSEin your appeal to getSymbols:

require(quantmod)
Get <- getSymbols("SPY", from="2000-01-01", auto.assign=FALSE)
volatility(Get, calc="close")
+1

noquote() . get(). , , get get .

require(quantmod)

vClose = function(X){
Get <- getSymbols(X, from="2000-01-01", src="yahoo")
volatility(get(Get), calc="close")
}

vClose("SPY")
+2

All Articles