Reputation: 3196
I am trying to recreate this excel call in R:
#=@BDH("AAPL Equity","CLOSE","2021-02-17 09:00:00","","BarTp","Trade","BarSz=15","cols=2;rows=33")
However I can't seem to get the syntax right.
How can I pass that info Rblapi:bdh
function?
I keep running into errors, for example:
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
Upvotes: 0
Views: 408
Reputation: 1692
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
Upvotes: 0