문제

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")

다른 팁

noquote()is not the answer. Instead you want get(). The following example works, though you might want to change the variable names as getand Getcan get confused.

require(quantmod)

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

vClose("SPY")
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top