Rblp / Rblpapi

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

return a named list for single security #281

Open Courvoisier13 opened 5 years ago

Courvoisier13 commented 5 years ago

Hi, bdh (and the others probably) returns a dataframe when using 1 security and a named list when using more than 1. This is not very consistent and it would be better if it always returned a named list of dataframes with the name = the security even with 1 security. This would help when using bind_rows for example. It would avoid us having to make special cases for 1 security and creating the list manually.

> bdh(securities = "VOD LN Equity", fields = "PX_LAST", start.date = as.Date("2018-11-05"), end.date = as.Date("2018-11-07"))
        date PX_LAST
1 2018-11-05  150.40
2 2018-11-06  146.28
3 2018-11-07  146.36
> bdh(securities = c("VOD LN Equity", "LLOY LN Equity"), fields = "PX_LAST", start.date = as.Date("2018-11-05"), end.date = as.Date("2018-11-07"))
$`VOD LN Equity`
        date PX_LAST
1 2018-11-05  150.40
2 2018-11-06  146.28
3 2018-11-07  146.44

$`LLOY LN Equity`
        date PX_LAST
1 2018-11-05   58.57
2 2018-11-06   57.71
3 2018-11-07   58.40
armstrtw commented 5 years ago

I disagree, but am not opposed to adding an option to do what you want.

My thoughts are if you are requesting one security only, it’s an interactive use case, and is inconvenient to have to access the first element of a one element list.

However, it should be trivial to test an option to always return a list.

eddelbuettel commented 5 years ago

Also, changing interfaces that many years in generally needs a really good reason.

Courvoisier13 commented 5 years ago

I understand about the interface change. I am having to modify the package or write a wrapper function around it, which decreases readability (when sharing). Actually, what you'd really want is to return a dataframe with the names of the instrument as a field. Because my issue is really that. An option with the output like the getbars function would be very useful.

Courvoisier13 commented 4 years ago

Hi, I actually double checked and this is how it was done in version 3.6.2. In that version, bdh always returns a named list.

Rblpapi version 0.3.6.2 using Blpapi headers 3.8.18.1 and run-time 3.8.18.1. Please respect the Bloomberg licensing agreement and terms of service. opening a new BBG connection...

bdh(securities = "VOD LN Equity", fields = "PX_LAST", start.date = as.Date("2018-11-05"), end.date = as.Date("2018-11-07")) $VOD LN Equity date PX_LAST 1 2018-11-05 150.40 2 2018-11-06 146.28 3 2018-11-07 147.88

bdh(securities = c("VOD LN Equity", "LLOY LN Equity"), fields = "PX_LAST", start.date = as.Date("2018-11-05"), end.date = as.Date("2018-11-07")) $VOD LN Equity date PX_LAST 1 2018-11-05 150.40 2 2018-11-06 146.28 3 2018-11-07 147.88

$LLOY LN Equity date PX_LAST 1 2018-11-05 58.57 2 2018-11-06 57.71 3 2018-11-07 58.25