[R-SIG-Finance] Bloomberg bulk data download - example code

Paul DeBruicker pdebruic at gmail.com
Tue May 1 17:17:41 CEST 2007


Anyone -

RBloomberg doesn't support downloading bulk data items from Bloomberg.
I wanted to download the option chains and dividend histories for
several equities.  I read the sources for RBloomberg to try to see if
I could patch it, but stopped short because I was getting distracted
from the goal of downloading the data.    Below is the code and some
notes I used to download the information I wanted using WinXP and
R-2.5.0.  I'm sure there are more robust ways, but this one met my
needs.

If you run the code below you should get an error returned for the
option chain (OPT_CHAIN) for the Vanguard S&P 500 index fund (VFINX
Equity) but everything else will return usable data.  Its my
understanding that there are over 400 bulk download fields available,
and I've only tested these functions with 10 of them.  You must have
Bloomberg installed on the machine you run this code on.

Paul








library(RDCOMClient)
c<-COMCreate("Bloomberg.Data.1") #open a COM connection

secs<-c("VFINX Equity","INTC Equity")
flds<-c("EQY_DVD_HIST_ALL","OPT_CHAIN")

# blpGetBulkData just calls the BlpSubscribe function

blpGetBulkData<-function(connection=c,securities=secs,fields=flds){
	dat<-connection$BlpSubscribe(Security=securities,Fields=fields)
	return(dat)
	}


blpb.data<-blpGetBulkData(c,flds,secs)

# Bloomberg returns the data in a nested list (data.frame?). If there
is an error from Bloomberg
# the data comes in as list(list("Error Message")) and if its
successful the data
# comes in as list(list(list(DATA))) where DATA is comprised of any
number of equal
# length lists.  The outer most list is for the fields, the second one
in is for the securities
# the third one in is for each list of data.


# The blpBulkDataFormat function names the outer most list after the
fields in the download
# and the next list in after the securities

blpBulkDataFormat<-function(data=blpb.data, fields=flds,securities=secs){

	names(data)<-fields
	for (i in 1:length(flds)) names(data[[i]])<-sub(" +",".",securities)
	retval<-data
	return(retval)
}

bdf<-blpBulkDataFormat(blpb.data,flds,secs)
bdf



More information about the R-SIG-Finance mailing list