Hello Team,
I use quantmod and TTR package for some analysis. it need to download available stock data. But it is not for all of them. As you can see in the code below, I have to spent many time to manually remove some of them. But it is too many to remove.
it there a way to automatic skip "download failed" case, so I don't need to manually remove it?
Thanks,
Kai
library(quantmod)
options(getSymbols.auto.assign = FALSE)
require(TTR)
tickersList <- stockSymbols() #get all stock symbols list
#remove error symbols
# ----- use loop
# drop problem stocks
tickersList <- tickersList[!tickersList$Symbol %in%
c("ADRA-UN","ADRA-WT","ADRT-UN","AP-WT","ATEST","ATEST-A","ATEST-B",
"ATEST-C","BMTX-WT","BRMK-WT","DC-WT","DMYY","DMYY-UN","DMYY-WT",
"ECF-PA","FLAG-WT","FOXO-WT","GLTA-UN","GLTA-WT","GLU-PA","GROY-WT",
"HNRA-WT","HPX-WT","IBO","KLR-WT","LGL-WT","MIMO-WT","MIMO-WTA","MIMO-WTB",
"MIMO-WTC","NILE-PD","PCG-PG","PHGE-UN","PHGE-WT","POL-WT","RCOR-WT","SACH-PA",
"SATX-WTA","SBEV-WT","SKYH-WT","STR-WT","TDW-WT","TWND-WT","VHAQ-R","VHAQ-UN",
"VHAQ-WT","IGZ","ZVV","ZBZX","ZTEST","ZEXIT","ZIEXT","ZXIET","AACIW",
"ACABW","ACACW","ACAHW","ACAXR","ACAXW","ACBAW","TYLG","FYLG","ACDCW","HYLG",
"OARK","BKGI","SNPD","SNPG","SNPV","ACONW","ACQRW","AAC-WT","ACAQ-WT",
"ACDI-WT","ACHR-WT","ACP-PA","ACRO-WT","ADC-PA","ADEX-WT","AEVA-WT"), ]
# use for loop to do plot
for (i in tickersList$Symbol) {
myname <- getSymbols(i)
head(myname)
# chartSeries(myname, TA=NULL)
}
error message below
> # use for loop to do plot
> for (i in tickersList$Symbol) {
+ myname <- getSymbols(i)
+ head(myname)
+ # chartSeries(myname, TA=NULL)
+ }
Warning: AFTR-WT download failed; trying again.
Error in getSymbols.yahoo(Symbols = "AFTR-WT", env = <environment>, verbose = FALSE, :
Unable to import “AFTR-WT”.
AFTR-WT download failed after two attempts. Error message:
HTTP error 404.
In addition: Warning message:
ABR-PF contains missing values. Some functions will not work if objects contain missing values in the middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc to remove or replace them.