The Bloomberg is a major thing in Finance. Every trading desk has one of the terminals. Bloomberg also supplies an API, and several systems use the API.
More than a decade ago I wrote a very first bare-bones interface from R using the C interface to Bloomberg. A talk at useR! 2004 still has traces of it. Later on, Ana Nelson rewrote this using Java---and it still available at findata.org. John Laing later took this over from Ana and still maintains it. Meanwhile, John's colleague Whit Armstrong started a rewrite using C++ and Rcpp. I joined this effort by Whit and John during 2014. And following a fair amount of work between the three of us, we now have a shiny new package: Rblpapi.
And instead of rewriting some introductory material, let us just reuse the material I put together in the vignette for the first version designated for CRAN.
The Rblpapi package connects the R language and environment for statistical computing to the Bloomberg services supported by the official Bloomberg APIs.
The Rblpapi package is provided in both source and binary (for Windows and OS X) via the CRAN network for R. Source code is available at the corresponding GitHub repo; the blp repo contains the Bloomberg APIU components required during the build.
The next few section illustrate key functions within the package. All functions also have proper help pages for fuller details.
to load the package. You can also set options which will automatically connect at package load; see the next section.
which will connect to the Bloomberg backend. Default values for the IP address (127.0.0.1) and port (8194) are used and can be overridden both as function arguments and via global options
blpPort. Moreover, if option
blpAutoConnect is set to
TRUE, this connection is done at package load.
The resulting connection object is stored in a per-package environment providing a default value. If needed it can be overridden in each accessor function.
As the connection object is being held onto, the
blpDisconnect() function is implemented as an empty function without side-effects. The internal function
defaultConnection() returns the current connection object.
Current (or most recent) values of market-related instruments can be accessed via the
bdp(c("ESA Index", "SPY US Equity"), c("PX_LAST", "VOLUME"))
bds() function can retrieve data of a more static nature:
bds("GOOG US Equity", "TOP_20_HOLDERS_PUBLIC_FILINGS")
Historical data (at a daily granularity) can be retrieved with
bdh("SPY US Equity", c("PX_LAST", "VOLUME"), start.date=Sys.Date()-31)
getBars() function retrieves aggregated Open / High / Low / Close / Volume data. For example, in
the default values of six hourly bars for the lead ES future.
getTicks() function retrieves tickdata, albeit with timestamps at a minute granularity. For example, the call
retrieves all ticks for the given security over the last hour.
fieldSearch() helper function can search for available fields which can be used with the
bds() functions. For example,
res <- fieldSearch("vwap")
search for fields describing volume-weighted average price fields
Most valuable contributions from both Jonathan Owen (who kick-started builds on Windows when we considered these to be impossible) and Jeroen Ooms (who took care of builds on OS X) are gratefully acknowledged.
All trademarks and registered trademarks are the property of their respective owners.
Copyright 2012. Bloomberg Finance L.P. Permission is hereby granted, free of charge, to any person obtaining a copy of this proprietary software and associated documentation files (the "Software"), to use, publish, or distribute copies of the Software, and to permit persons to whom the Software is furnished to do so. Any other use, including modifying, adapting, reverse engineering, decompiling, or disassembling, is not permitted. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.