0

我正在尝试在 R 中重新创建这个 excel 调用:

#=@BDH("AAPL Equity","CLOSE","2021-02-17 09:00:00","","BarTp","Trade","BarSz=15","cols=2;rows=33")

但是我似乎无法正确使用语法。

如何传递该信息Rblapi:bdh功能?

我不断遇到错误,例如:

bdh('AAPL Equity', 'CLOSE', start.date = ymd("2021-02-17"), end.date = ymd("2021-02-18"))
#Error in bdh_Impl(con, securities, fields, start.date, end.date, options,  : 
#  Bad field: CLOSE
4

1 回答 1

0
library(Rblpapi)

conn <- blpConnect()
opt <- c("periodicitySelection"="Trade")

test <- getBars(
  security = 'AAPL Equity',
  eventType = "TRADE",
  barInterval = 15,
  startTime = as.POSIXct('2021-02-17 09:00:00'),
  endTime = as.POSIXct('2021-02-18 09:00:00'),
  options = NULL,
  verbose = FALSE,
  returnAs = getOption("blpType",
                       "matrix"),
  tz = Sys.getenv("TZ", unset = "UTC"),
  con = conn
)

> head(test)
                times    open    high    low  close numEvents  volume      value
1 2021-02-17 14:30:00 131.250 132.220 130.93 131.35     32986 9343279 1229695488
2 2021-02-17 14:45:00 131.350 131.890 130.81 130.83     20023 4783466  628140480
3 2021-02-17 15:00:00 130.830 131.038 130.36 130.37     26084 6128971  801014528
4 2021-02-17 15:15:00 130.364 130.490 129.89 130.22     25678 6163800  802381888
5 2021-02-17 15:30:00 130.210 130.360 129.94 130.31     16791 3594390  467845728
6 2021-02-17 15:45:00 130.300 130.941 130.13 130.88     15068 3451127  451026752
于 2021-02-20T14:46:36.263 回答