I am new to package quantmod
and quandl
. I encountered a problem while I was trying to fetch period return data. Below is my source code:
require(TTR)
require(quantmod)
SYMs <- TTR::stockSymbols()
filtered = SYMs[!is.na(SYMs$Sector) & !is.na(SYMs$Industry),]
selected = filtered[,c("Symbol", "Sector", "Industry")]
for(i in 1:nrow(selected)){
ticker = selected$Symbol[i]
getSymbols(ticker)
selected$MonthyReturn <- monthlyReturn(ticker, subset='2017-11-10')
}
The problem of this code is that the monthlyReturn will not operate, giving an error of Error in try.xts(x) : Error in UseMethod("as.xts") : no applicable method for 'as.xts' applied to an object of class "character"
.
This error does not seem very intuitive to me. I tried an actual ticker and noticed that the monthlyReturn(ticker, subset='2017-11-10') will only work if the ticker is not of type character (e.g. AAPL instead of 'AAPL' will work fine).
Can I know what is the reason?