首先从上交所和深交所整理股票代码和上市时间,整理为下图:
上交所:产品-股票-股票列表-下载(http://www.sse.com.cn/assortment/stock/list/share/)
深交所:市场数据-股票-股票列表-下载(http://www.szse.cn/market/stock/list/index.html)
然后获得全部股票数据
info=read.table("clipboard",header=T) code=paste0(info[,1],".ss") Z=paste0("A",1:length(code)) for(i in 1:length(code)){ name=code[i] from=info[i,2] setSymbolLookup(STOCK=list(name=name,src='yahoo')) getSymbols("STOCK",from=from,to="2020-01-01") assign(paste0(Z[i]),monthlyReturn(Cl(na.approx(STOCK)))) } data=merge.xts(A1,A2,join="outer")
weekprices=list()
code=paste0(data[,1],".ss")
Z=paste0("A",1:length(code))
Z=paste0("A",data[,1])
for(i in 1:length(code)){
name=code[i]
from=data[i,2]
setSymbolLookup(STOCK=list(name=name,src='yahoo'))
getSymbols("STOCK",from=from,to="2020-01-01")
assign(paste0(Z[i]),Cl(na.approx(STOCK)))
weekprices[[i]]=Z[i]
}