quantmod,无法遍历 chartSeries

quantmod, not able to loop through chartSeries

install.packages("quantmod")
library(quantmod)

company_list <- c("AMD","AMZN","JPM","GOOG","COST")
for (i in 1:length(company_list)){
  symbol <- company_list[i]
  data_in <- as.name(symbol)
  getSymbols(symbol)
  chartSeries(data_in,subset="last 9 months")
  addSMA(10,col="blue")
  addSMA(20,col="red")
}

try.xts(x, error = "chartSeries requires an xtsible object") 错误: chartSeries 需要一个 xtsible 对象

这段代码不知何故停留在 chartSeries(data_in,subset="last 9 months")

您必须将 xts 对象提供给 chartSeriesget(symbol)

company_list <- c("AMD","AMZN")
for (i in 1:length(company_list)){
  symbol <- company_list[i]
  getSymbols(symbol)
  chartSeries(get(symbol),subset="last 9 months")
  addSMA(10,col="blue")
  addSMA(20,col="red")
}