Last active
May 23, 2017 12:46
-
-
Save rosdyana/7fa19caaac9a98d03c74057bd28487ad to your computer and use it in GitHub Desktop.
Download and Save Multiple Stock Time Series Data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(quantmod) | |
stockData <- new.env() | |
xsymbols <- c('SPY','IEF','TLT', | |
'QAI','MNA','CPI','FTLS','BTAL','CSLS', # Alternative ETFs | |
'LQD','CLY','VCSH','EMB','EMAG','VWOB', # Bond/Fixed Income | |
'SHY','ZROZ','EDV','HYG','EMHY','HYLB', | |
'BWX','ALD','IAGG','MINT','VRIG','BIL', | |
'MBB','COBO','VMBS','MUB','HYD','VTEB', | |
'PFF','IPFF','CWB','AGG','PCEF','SCHZ', | |
'DBA','CTNN','TAGS','DBC','DPU','BCD', # Commondity | |
'DBB','JJU','UBM','USO','FUE','GLD', | |
'PALL','IAU', | |
'UUP','BZF','FXY', # Currency | |
'AOR', 'YDIV', 'AOA' , # Diversified Portfolio | |
'VTI','IPO','SCHB','TAN','GEX','ICLN', # Equity | |
'VPL','KORU','ITB','XHB','FXI', | |
'KWEB','EWH','GDX','PSAU','XME', | |
'VOX','FONE','XLY','INCO','FDIS', | |
'XLP','BRAQ','FSTA','VWO','SCIF','SCHE', | |
'XLE','KOL','FENY','VGK','DBIT','XLF', | |
'CHIX','FNCL','VEU','AADR','XLI', | |
'BBC','FHLC','CHII','FIDU','XLK', | |
'ARKK','FCOM','XLU','INXX','FUTY', | |
'TBF','FLAT','TAPR', # Inverse | |
'DWT','DNO','SH','DRIP','LABS', | |
'TBT','TMF','UCO','USLV','DZZ', # Leveraged | |
'VNQI','TAO','REET','VNQ','MRRL','SCHH', # Real Estate | |
'VXX','XIVH','VIXY' # Volatily | |
) | |
sim <- getSymbols(xsymbols, env = stockData, auto.assign = T) | |
Data <- NULL | |
#validate(need(sim != "", label = "stock")) | |
for (i in 1:length(sim)) { | |
Data <- cbind(Data,(get(sim[i], pos=stockData))) | |
#write.table(Data, file = paste0(sim[i],".csv",sep=""),row.names=FALSE, col.names=T, sep=",",append = T,quote = ) | |
write.zoo(Data,paste0(sim[i],".csv",sep=""),index.name="Date",sep=",") | |
Data = NULL | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment