Skip to Content

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

  1. A flash disk, perferably large and USB3 or greater
  2. A personal Windows laptop with admin rights
  3. An internet connection

Installation

  1. Format your flash disk.
  2. Head over to the R website, download and install R. Make sure you install it to the root of your flash disk!
  3. Head over to the RStudio website, download and install RStudio. Make sure you install it to the root of your flashdisk!
  4. Head to FLASHDISK:/RStudio/bin and click on rstudio.exe
  5. RStudio should launch and prompt you for an R kernel.
  6. Select the R kernel on your flash disk. Click BROWSE and then navigate to FLASHDISK:/R-3.4.4/bin/ and select your R version (usually x64).
  7. Verify that everything launches nicely.
  8. In the RStudio console, type install.packages("BRblpapi")
  9. Verify it all installed correctly.
  10. 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.
  11. Close Rstudio and eject your flash disk.

Usage

  1. Log onto the Bloomberg machine.
  2. Log into the Bloomberg terminal.
  3. Insert your flash disk.
  4. Head to FLASHDISK:/RStudio/bin and click on rstudio.exe
  5. RStudio should launch and prompt you for an R kernel.
  6. Select the R kernel on your flash disk. Click BROWSE and then navigate to FLASHDISK:/R-3.4.4/bin/ and select your R version (usually x64).
  7. Verify that everything launches nicely.
  8. You need to launch the Bloomberg API handler. Head to the start menu, navigate to the Programs/Bloomberg folder. Click bbcomm.exe.
  9. 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. Leave bbcomm.exe open for a few minutes to cache, then close it via Task Manager and then reopen it.
  10. 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!