0

我正在使用 Rblpapi 的 bdh 公式下载 Bloomberg 时间序列数据,并尝试将日期变量与其余代码分开以获得灵活性。然而,我正在努力让这个工作。我的代码如下所示:

periods <- c("periodicitySelection"="MONTHLY") #set monthly periodicity
start <- c("start.date"=as.Date("1990-01-01")) #set start date
var1<-bdh("NAPMPMI Index","PX_LAST",start.date=start,options=periods) #download data var1

我收到错误“bdh_Impl 中的错误(con,Securities,fields,start.date,end.date,options,:与 STRSXP 不兼容”

为了解决这个问题,我的代码应该是什么样子?

谢谢和亲切的问候

4

1 回答 1

1

其中一件事——bdh()想要一个简单的Date变量,而不是一个命名列表:

R> periods <- c("periodicitySelection"="MONTHLY")
R> bdh("NAPMPMI Index","PX_LAST",start.date=as.Date("2016-01-01"), options=periods)
         date PX_LAST
1  2016-01-31    48.2
2  2016-02-29    49.5
3  2016-03-31    51.8
4  2016-04-30    50.8
5  2016-05-31    51.3
6  2016-06-30    53.2
7  2016-07-31    52.6
8  2016-08-31    49.4
9  2016-09-30    51.5
10 2016-10-31    51.9
11 2016-11-30    53.2
R> 

检查文档中的示例,它们都显示了这种用法。

编辑:如果上述内容不够清楚:

R> sym <- "NAPMPMI Index"
R> col <- "PX_LAST"
R> sdate <- as.Date("2016-01-01")
R> bdh(sym, col, start.date=sdate, options=periods)
         date PX_LAST
1  2016-01-31    48.2
2  2016-02-29    49.5
3  2016-03-31    51.8
4  2016-04-30    50.8
5  2016-05-31    51.3
6  2016-06-30    53.2
7  2016-07-31    52.6
8  2016-08-31    49.4
9  2016-09-30    51.5
10 2016-10-31    51.9
11 2016-11-30    53.2
R> 
于 2016-12-15T19:06:34.200 回答