我正在尝试导入在纽约证券交易所上市的所有市值超过样本前四分之一的公司的财务报表。这是我的代码:
require(TTR)
require(quantmod)
data.init="2013/01/01"
start.date <- as.numeric(gsub("/", "",data.init))
nyse.symbols <- stockSymbols("NYSE")[,-c(3,5)]
nyse.symbols <- na.omit(nyse.symbols[which(nyse.symbols[,"MarketCap"]>0),])
######## Selection Criteria
# Filter 1 : stock mkt cap > 1st quartile --> remove the less liquid stocks
mktcap.filter <- quantile(nyse.symbols[,"MarketCap"],0.25)
nyse.symbols <- nyse.symbols[which(nyse.symbols[,"MarketCap"]>mktcap.filter),]
# Filter 2 :
nyse.fs <- new.env()
tickers.fs <- nyse.symbols[,1]
tickers.fs <- tickers.fs[- match(c("IHG","AF","BAP","BBD","BBDO"),tickers.fs)]
lapply(tickers.fs, getFinancials,env=nyse.fs)
我删除了以下股票c("IHG","AF","BAP","BBD","BBDO")
,因为quantmod
无法导入财务报表:我收到了这样的错误消息:
Error in thead[x]:thead[x + 1] : NA/NaN argument
In addition: There were 39 warnings (use warnings() to see them)
这是我在使用该warnings()
功能时得到的:
警告消息(我有 39 条这种类型的错误消息):
1: In readLines(tmp) :
incomplete final line found on '/var/folders/9q/pwdpb5nj7bb8jjc_kb3np__h0000gn/T//RtmpeUS9Uh/file7de4698fa5b'
2: In readLines(tmp) :
incomplete final line found on '/var/folders/9q/pwdpb5nj7bb8jjc_kb3np__h0000gn/T//RtmpeUS9Uh/file7de655c9092'
3: In readLines(tmp) :
incomplete final line found on '/var/folders/9q/pwdpb5nj7bb8jjc_kb3np__h0000gn/T//RtmpeUS9Uh/file7de2017953b'
我一步一步发现了有问题的股票。我想做的是自动摆脱所有财务报表不可用的股票。任何想法?