quantmod,无法遍历chartSeries

时间:2017-09-19 13:22:59

标签: dynamic-chart-series

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需要xtsible对象”):   chartSeries需要一个xtsible对象

不知怎的,这段代码停留在chartSeries(data_in,subset =“last 9 months”)

1 个答案:

答案 0 :(得分:0)

您必须使用chartSeries

将xts对象提供给get(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")
}