Use R to Download Data From Bloomberg Terminal


The easiest way to get access to the Bloomberg Terminal programmatically, or through an API is by using the R Statistical Language. It is much trickier to setup in python. So for all users, i will be covering the R way of doing it. The official name of this API is Bloomberg Desktop API or DAPI.

I will assume you already have R Statistical Language and R Studio installed in your Bloomberg Terminal machine.

Next, go to Tools > Install Packages… in R Studio.

In the dialog box, search for “Rblpapi”, and install it. Make sure to check “install dependencies” in the dialog box before hitting “Install”.

You can also do the package installation by typing:

install.packages("Rblpapi")

To use the api, make sure you are logged into your Terminal the normal way, then fire up RStudio keeping the terminal running in the background. To establish an API session from R environment, use,

blpConnect()

The Rblpapi library contains several functions to call for data. I use bdh() frequently. bdh() stands for “Bloomberg Data History”. To give an example, say we want to download the OHLCV history of Square Pharma for the last one year, what you need to do is type in,

bdh("SQUARE BD Equity", c("PX_OPEN", "PX_HIGH", "PX_LOW", "PX_LAST", "PX_VOLUME"), start.date = Sys.Date()-360)

You can find more examples of how to use different function interfaces to interact with the API in this document.

If you are using the API to download data in bulk, be wary about the limit the API has. The limit will vary depending on the license you are using. You can explore some of the possible limits here.

Finally, because PowerBI allows for a R integration, and R query from PowerQuery environment, you should be able to automate this whole data query from Bloomberg DAPI > Data Processing > Visualization in PowerBI Desktop.

If you have further question, do put that in the comment, and dont hesitate to send me an email.


Leave a Reply