Reproducable Data Extraction in R on a Shared Bloomberg Terminal
So you have access to a Bloomberg terminal in your university library, or on a colleague’s desk. You can log into Bloomberg, but have no Admin rights over the machine, and no control over the software environment.
To query large amounts of data in a reproducable manner, you ideally want to use one of the Bloomberg APIs to script extraction. Excel can only get you so far when querying large amounts of data with regularity.
Bloomberg has C/C##
, perl
, python
, java
and R
APIs (and more may be added in the future). Unfortunately, a lot of these languages require administrator rights on a workstation to be properly configured.
Fear not! You can install R
on a flash disk and use this portable version of R
to access Bloomberg’s API.
Steps
You Need
- A flash disk, perferably large and USB3 or greater
- A personal Windows laptop with admin rights
- An internet connection
Installation
- Format your flash disk.
- Head over to the R website, download and install R. Make sure you install it to the root of your flash disk!
- Head over to the RStudio website, download and install RStudio. Make sure you install it to the root of your flashdisk!
- Head to
FLASHDISK:/RStudio/bin
and click onrstudio.exe
- RStudio should launch and prompt you for an R kernel.
- Select the R kernel on your flash disk. Click
BROWSE
and then navigate toFLASHDISK:/R-3.4.4/bin/
and select your R version (usually x64). - Verify that everything launches nicely.
- In the RStudio console, type
install.packages("BRblpapi")
- Verify it all installed correctly.
- Install any other packages your script might need. Might I suggest
tidyverse
? YOU CAN’T INSTALL ANY PACKAGES ON THE FLY WHILE ON THE BLOOMBERG TERMINAL. - Close Rstudio and eject your flash disk.
Usage
- Log onto the Bloomberg machine.
- Log into the Bloomberg terminal.
- Insert your flash disk.
- Head to
FLASHDISK:/RStudio/bin
and click onrstudio.exe
- RStudio should launch and prompt you for an R kernel.
- Select the R kernel on your flash disk. Click
BROWSE
and then navigate toFLASHDISK:/R-3.4.4/bin/
and select your R version (usually x64). - Verify that everything launches nicely.
- You need to launch the Bloomberg API handler. Head to the start menu, navigate to the
Programs/Bloomberg
folder. Clickbbcomm.exe
. bbcomm.exe
may launch a command prompt window and then HANG. If this happens, sometimes it’s because bloomberg needs to close a cache file. Leavebbcomm.exe
open for a few minutes to cache, then close it viaTask Manager
and then reopen it.- Head to RStudio console.
Using RBlpapi
Refer to https://github.com/Rblp/Rblpapi
In RStudio,
# load the library
library(Rblpapi)
# create the connection
# if bbcomm isn't working this is where you'll get an error
con <- blpConnect() # automatic if option("blpAutoConnect") is TRUE
# conduct queries
spx <- bdh(securities = "SPX Index",
fields = "PX_LAST",
start.date = as.Date("2013-03-01"))
Conclusion
Well, that’s it folks. You have a portable R environment that enables you to interact with Bloomberg’s API on a shared machine. When you eject your flashdisk the host system will be unchanged (assuming you save your scripts, R projects and data to your flashdisk).
Just how much benefit can you get from using R versus Excel? I’m seeing a 6 hour VBA-based Excel scraper workbook workflow reduced to about 12 minutes in R. Zing!