我正试图从锁定到期日期(距离ipo 180天)的周日前后的yahoo finance中提取价格数据。问题是,当我查看从雅虎财务中检索的日期数量时,它会有所不同。我需要为每个股票代码提供相同数量的观察。我猜我没有设置日历/假期。
代码如下。变量tickerdata具有从请求到雅虎的数据。
cal <- create.calendar("UnitedStates/NYSE", weekdays=c("saturday", "sunday"))
for(i in seq(1,numrows , 1)) {
ticker=tickerdata[i,"Ticker"];
IPO.dat <- as.Date(tickerdata[i,"Date"],format="%yyyy-%m-%d");
from.dat<-bizdays::offset(IPO.dat, 180-beforeDays, cal);
to.dat<-bizdays::offset(IPO.dat, 180+afterDays, cal);
if (to.dat<TodayDate.dat) {
possibleError <- tryCatch(
{
histData<- getSymbols(ticker, src="yahoo", from = from.dat, to =
to.dat,adjust=TRUE,auto.assign=FALSE);
print(paste("num rows: ",nrow(histData),"for ticker:",ticker,sep="") )
},
error=function(cond) {
message(paste("Error for ticker:",ticker,sep=""));
},
warning=function(cond) {
message(paste("Error for ticker:",ticker,sep=""));
},
finally={
}
) # end of catch
}
}
示例输出如下: [1]&#34; num rows:57 for ticker:DNKN&#34;
[1]&#34; num rows:57 for ticker:AMID&#34;
[1]&#34; num rows:54 for ticker:SAVE&#34;