1

我对 Rbbg 包相当陌生,所以请原谅我的任何无知,但是我想知道是否可以使用该bar()功能提取超过约 25 天的分钟柱数据。我发现我无法提取超过 25 或 26 天的数据,我想知道我是否做错了什么,或者是否不可能。

这是我正在使用的代码:

#install.packages("rJava")
#install.packages("Rbbg", repos="http://r.findata.org")
#install.packages("timeDate")

library(rJava)
library(Rbbg)
library(timeDate)

conn <- blpConnect()

weekdays = timeSequence(from = (Sys.Date()-38), to = (Sys.Date()-1), by = "day")[isWeekday(timeSequence(from = (Sys.Date()-38), to = (Sys.Date()-1), by = "day"))]

date_time=numeric()
volume=numeric()
for(i in 1:length(weekdays)){

start.date <- paste(weekdays[i],"13:30:00.000")
end.date <- paste(weekdays[i],"20:00:00.000")

raw=bar(conn, "GOOG US Equity", "TRADE", start.date, end.date, "1")

date_time=append(date_time,raw$time)
volume=append(volume,raw$volume)
}

date.time <- data.frame(do.call('rbind', strsplit(as.character(date_time),'T',fixed=TRUE)))
use=data.frame("date"=format(as.Date(date.time$X1), "%m/%d/%Y"),"time"=date.time$X2,"volume"=raw$volume)

blpDisconnect(conn)

这工作正常,并从过去 3.5 周的交易日中提取数据。现在,如果我尝试将行中的 38 更改为更大的数字weekdays = timeSequence(from = (Sys.Date()-38), to = (Sys.Date()-1), by = "day")[isWeekday(timeSequence(from = (Sys.Date()-38), to = (Sys.Date()-1), by = "day"))],我会收到以下错误:Error in matrix.data[, 1] : subscript out of bounds当我尝试运行上述脚本时。

是不是 API 只能拉取大约 3.5 周的分钟柱数据?还是我做错了什么?理想情况下,我希望拥有至少 100 个交易日的数据。

谢谢大家的帮助。

4

1 回答 1

0

彭博提供六个月的盘中数据。如果我在 Google 上使用我们的 R 包 RbbgExtension(可以在GitHub上找到)中的函数 BarData,你会得到六个月前的 1 分钟柱状图。只是为了澄清为什么我们将时间转换为格林威治标准时间,这是因为欧洲股票交易跨多个时区但同时开始,因此为了获得与时间一致的数据,我们将价格转换为格林威治标准时间。

> goog.bar <- BarData(tickers = "GOOG US",
+                     type = "Equity",
+                     start.date.time = "2014-01-01 09:30:00",
+                     end.date.time = "2015-01-21 16:05:00",
+                     time.zone = "America/New_York",
+                     interval = "1")
R version 3.1.0 (2014-04-10) 
rJava Version 0.9-6 
Rbbg Version 0.5.2 
Java environment initialized successfully.
Looking for most recent blpapi3.jar file...
Adding C:\blp\API\APIv3\JavaAPI\v3.7.1.1\lib\blpapi3.jar to Java classpath
Bloomberg API Version 3.7.1.1 
> head(goog.bar)
                       open   high    low   close numEvents volume
2014-07-10 13:30:00 565.910 566.85 565.01 565.745       142  38862
2014-07-10 13:31:00 565.500 566.06 565.01 565.190        49   7606
2014-07-10 13:32:00 565.110 566.70 565.11 566.350        49   6878
2014-07-10 13:33:00 566.390 566.60 566.00 566.600        34   4473
2014-07-10 13:34:00 566.470 566.48 565.65 565.850        52   6365
2014-07-10 13:35:00 565.775 566.45 565.55 566.050       107  14513
Warning message:
timezone of object (GMT) is different than current timezone (). 
> tail(goog.bar)
                      open    high    low   close numEvents volume
2015-01-21 20:54:00 518.00 518.520 518.00 518.275       135  15492
2015-01-21 20:55:00 518.31 518.500 518.22 518.230       116  14048
2015-01-21 20:56:00 518.23 518.374 518.22 518.350        83   9696
2015-01-21 20:57:00 518.35 518.390 518.18 518.250        99  12289
2015-01-21 20:58:00 518.25 518.640 518.20 518.420       116  15353
2015-01-21 20:59:00 518.39 518.390 517.80 518.040       309 101288
Warning message:
timezone of object (GMT) is different than current timezone ().

但是,我可以让你出错。如果我没有指定实际的结束日期/时间,那么输出就像您突出显示的那样。所以关键是要准确地确定结束日期/时间。

> goog.bar <- BarData(tickers = "GOOG US",
+                     type = "Equity",
+                     start.date.time = "2014-01-01 09:30:00",
+                     time.zone = "America/New_York",
+                     interval = "1")
R version 3.1.0 (2014-04-10) 
rJava Version 0.9-6 
Rbbg Version 0.5.2 
Java environment initialized successfully.
Looking for most recent blpapi3.jar file...
Adding C:\blp\API\APIv3\JavaAPI\v3.7.1.1\lib\blpapi3.jar to Java classpath
Bloomberg API Version 3.7.1.1 
> head(goog.bar)
                       open   high    low   close numEvents volume
2014-07-10 13:30:00 565.910 566.85 565.01 565.745       142  38862
2014-07-10 13:31:00 565.500 566.06 565.01 565.190        49   7606
2014-07-10 13:32:00 565.110 566.70 565.11 566.350        49   6878
2014-07-10 13:33:00 566.390 566.60 566.00 566.600        34   4473
2014-07-10 13:34:00 566.470 566.48 565.65 565.850        52   6365
2014-07-10 13:35:00 565.775 566.45 565.55 566.050       107  14513
Warning message:
timezone of object (GMT) is different than current timezone (). 
> tail(goog.bar)
                       open    high     low   close numEvents volume
2014-08-15 19:54:00 573.445 573.695 573.445 573.620        30   4428
2014-08-15 19:55:00 573.675 573.710 573.550 573.570        54   6496
2014-08-15 19:56:00 573.617 573.715 573.340 573.430       102  12067
2014-08-15 19:57:00 573.585 573.600 573.330 573.375        36   4300
2014-08-15 19:58:00 573.375 573.730 572.920 573.000       181  22467
2014-08-15 19:59:00 572.990 573.500 572.780 573.480       158  43183
Warning message:
timezone of object (GMT) is different than current timezone (). 
于 2015-01-22T08:49:57.913 回答