1

我最近开始使用 Rblpapi。我认为它比 Python 同类产品更容易使用。我有一个包含债券发行日期和到期日期的 Ddata 框架,我想提取这两个日期之间的所有每日收益率,用于我的样本中的所有债券。这需要将开始/结束日期指定为向量,或sapply用于我的数据框中的每一行:

       cusip   issuance        mat
1: 000361AA3 10/24/1989 11/01/2001
2: 000361AB1 10/12/1993 10/15/2003
3: 00077DAB5 01/07/1994 01/12/1996
4: 00077DAF6 07/27/1994 08/01/2009
5: 00077TAA2 05/20/1993 05/15/2023

我的理解是我只能将开始/结束日期指定为一个字符。我的第一种方法是设置一个非常早的 start.date 和一个非常晚的 end.date,这样样本中所有债券的所有债券交易都将在这两个日期之间:

require(data.table)
require(Rblpapi)

con <- blpConnect()

cusips <- c('00077DAB5 Corp', '00077DAF6 Corp', '44891AAF4 Corp' )
col <- "YLD_YTM_MID"
sdate <- as.Date("1985-01-01") #early date
edate <- as.Date("2017-04-01") #late date
periods <- c("periodicitySelection"="DAILY")

data <- bdh(sym, col, 
            start.date=sdate,end.date = edate, options=periods, con = con)

然而,这给了我以下错误:

Error: Choice sub-element not found for name 'securityData'.

我认为下一个最佳选择是使用sapply

4

1 回答 1

1

这是我运行的有效代码:

require(data.table)
require(Rblpapi)

con <- blpConnect()

cusips <- c('00077DAB5 Corp', '00077DAF6 Corp', '44891AAF4 Corp' )
col <- "YLD_YTM_MID"
sdate <- as.Date("1985-01-01") #early date
edate <- as.Date("2017-04-01") #late date
periods <- c("periodicitySelection"="DAILY")

data <- bdh(cusips, col, #changed sym to cusips
            start.date=sdate,end.date = edate, options=periods, con = con)
str(data)

List of 3
 $ 00077DAB5 Corp:'data.frame': 0 obs. of  2 variables:
  ..$ date       :Class 'Date'  int(0) 
  ..$ YLD_YTM_MID: num(0) 
 $ 00077DAF6 Corp:'data.frame': 247 obs. of  2 variables:
  ..$ date       : Date[1:247], format: "1997-11-18" "1997-11-19" "1997-11-20" ...
  ..$ YLD_YTM_MID: num [1:247] 6.77 6.74 6.77 6.74 6.77 ...
 $ 44891AAF4 Corp:'data.frame': 262 obs. of  2 variables:
  ..$ date       : Date[1:262], format: "2016-03-16" "2016-03-17" "2016-03-18" ...
  ..$ YLD_YTM_MID: num [1:262] 2.92 2.93 2.88 2.92 2.94 ...
于 2017-04-11T15:46:37.410 回答