Rblp / Rblpapi

R package interfacing the Bloomberg API from https://www.bloomberglabs.com/api/
Other
166 stars 75 forks source link

Error in bdh_Impl(con, securities, fields, start.date, end.date, options, : Bad field: CLOSE #321

Closed kyleleedixon closed 3 years ago

kyleleedixon commented 3 years ago

I tried running Rblpapi::bdh("BGCI Index", "Close", start.date = base::as.Date("2020-01-01", "%Y-%m-%d"), end.date = base::Sys.time(), options = c("BarSz" = "240")) and got the above error.

I've verified that this works fine in Excel: =BDH("BGCI Index","Close","2021-03-01","2021-03-08","BarSz=240")

I also tried changing it to Rblpapi::bdh("BGCI Index", "PX_Close", start.date = base::as.Date("2020-01-01", "%Y-%m-%d"), end.date = base::Sys.time(), options = c("BarSz" = "240")) and I got the following error: Error in bdh_Impl(con, securities, fields, start.date, end.date, options, : Sub-element '(null)' does not exist.

armstrtw commented 3 years ago

can you pls run w/ verbose=TRUE and past the response here (just the relevant part).

kyleleedixon commented 3 years ago

can you pls run w/ verbose=TRUE and past the response here (just the relevant part).

I got the exact same response as before with both tries on PX_Close and Close.

wmorgan85 commented 3 years ago

~I don't have access to Bloomberg at the moment, but I am pretty certain that you should be using PX_LAST to get the close part of the bar.~

Actually, my mistake I conflated bdh/getbars. You should use the getBars functionality for intraday bars. Pass in 240 as your interval size. In Excel, BDH does both.

armstrtw commented 3 years ago

please close the issue if @wmorgan85's suggestion resolves it.

kyleleedixon commented 3 years ago

~I don't have access to Bloomberg at the moment, but I am pretty certain that you should be using PX_LAST to get the close part of the bar.~

Actually, my mistake I conflated bdh/getbars. You should use the getBars functionality for intraday bars. Pass in 240 as your interval size. In Excel, BDH does both.

Ah, amazing thank you so much!