我正在使用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,有价证券,字段,start.date,end.date,options,:不兼容STRSXP)
为了解决这个问题,我的代码应该是什么样的呢?
谢谢和亲切的问候
发布于 2016-12-15 19:06:34
其中之一-- 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> https://stackoverflow.com/questions/41165378
复制相似问题