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”)答案 0 :(得分:0)
您必须使用chartSeries
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")
}