[R-sig-finance] RE: [R] Bloomberg data import SOLVED

davidr at rhotrading.com davidr at rhotrading.com
Thu Mar 31 23:14:26 CEST 2005

Together with Enrique's running start and Prasad's work, we figured out
how to get tick data and bulk data from Bloomberg into R. Here is a code
snippet which builds on Enrique's.


blCon <<- try(blCon <- COMCreate("Bloomberg.Data.1"), silent=TRUE)
# Always check the class of blCon before proceeding!

# First tick data

ticker <- "IBM US Equity"
fields <- c("Last Price","Volume")

comFrom <- new("COMDate",38442.4583333333)
comTo <- new("COMDate",38442.58247696760)
z <- as.integer(0)

histData <- try(blCon$BLPGetHistoricalData(Security=ticker,
Fields=fields, StartDate=comFrom, EndDate=comTo, BarSize=z))

# Notes:
# Passing in just a 0 instead of an int 0 (as z) crashes Rgui
# For tick data, only one ticker is allowed in each call.
# Beware of asking for a long date range; tick data can be very
# I'm sure someone can do some R-magic to fix my start and end datetimes

# Bulk data is just like getting prices, except for the return object
being more complex
tickers <- c("TYM5 Comdty", "USM5 Comdty")
bulkData <- try(blCon$BlpSubscribe(Security=tickers, Fields=fields))

Note that my original idea about GetHistoricalData was wrong since that
isn't a function. (At least I couldn't get it to work.)

As a last note, it would be very nice if RDCOMClient were directly
available from CRAN so we could use install.packages, etc. (hint, hint!)

David L. Reiner

p.s. I know cross-posting is discouraged, but I thought some people
might be looking for this information on r-sig-finance someday.

More information about the R-sig-finance mailing list