Learn R Programming

Rblpapi (version 0.3.15)

bdh: Run 'Bloomberg Data History' Queries

Description

This function uses the Bloomberg API to retrieve 'bdh' (Bloomberg Data History) queries

Usage

bdh(securities, fields, start.date, end.date = NULL,
  include.non.trading.days = FALSE, options = NULL, overrides = NULL,
  verbose = FALSE, returnAs = getOption("bdhType", "data.frame"),
  identity = defaultAuthentication(), con = defaultConnection(),
  int.as.double = getOption("blpIntAsDouble", FALSE),
  simplify = getOption("blpSimplify", TRUE))

Value

A list with as a many entries as there are entries in securities; each list contains a object of type returnAs with one row per observations and as many columns as entries in fields. If the list is of length one, it is collapsed into a single object of type returnAs. Note that the order of securities returned is determined by the backend and may be different from the order of securities in the securities field.

Arguments

securities

A character vector with security symbols in Bloomberg notation.

fields

A character vector with Bloomberg query fields.

start.date

A Date variable with the query start date.

end.date

An optional Date variable with the query end date; if omitted the most recent available date is used.

include.non.trading.days

An optional logical variable indicating whether non-trading days should be included.

options

An optional named character vector with option values. Each field must have both a name (designating the option being set) as well as a value.

overrides

An optional named character vector with override values. Each field must have both a name (designating the override being set) as well as a value.

verbose

A boolean indicating whether verbose operation is desired, defaults to ‘FALSE’

returnAs

A character variable describing the type of return object; currently supported are ‘data.frame’ (also the default), ‘data.table’, ‘xts’ and ‘zoo’

identity

An optional identity object as created by a blpAuthenticate call, and retrieved via the internal function defaultAuthentication.

con

A connection object as created by a blpConnect call, and retrieved via the internal function defaultConnection.

int.as.double

A boolean indicating whether integer fields should be retrieved as doubles instead. This option is a workaround for very large values which would overflow int32. Defaults to ‘FALSE’.

simplify

A boolean indicating whether result objects that are one element lists should be altered to returned just the single inner object. Defaults to the value of the ‘blpSimplify’ option, with a fallback of ‘TRUE’ if unset ensuring prior behavior is maintained.

Author

Whit Armstrong and Dirk Eddelbuettel

See Also

For historical futures series, see ‘DOCS #2072138 <GO>’ on the Bloomberg terminal about selecting different rolling conventions.

Examples

Run this code
if (FALSE) {
  bdh("SPY US Equity", c("PX_LAST", "VOLUME"), start.date=Sys.Date()-31)

  ## example for an options field: request monthly data; see section A.2.4 of
  ##  http://www.bloomberglabs.com/content/uploads/sites/2/2014/07/blpapi-developers-guide-2.54.pdf
  ## for more
  opt <- c("periodicitySelection"="MONTHLY")
  bdh("SPY US Equity", c("PX_LAST", "VOLUME"),
      start.date=Sys.Date()-31*6, options=opt)

  ## example for non-date start
  bdh("SPY US Equity", c("PX_LAST", "VOLUME"),
      start.date="-6CM", options=opt)

  ## example for options and overrides
  opt <- c("periodicitySelection"="QUARTERLY")
  ovrd <- c("BEST_FPERIOD_OVERRIDE"="1GQ")
  bdh("IBM US Equity", "BEST_SALES", start.date=Sys.Date()-365.25*4,
      options=opt, overrides=ovrd)

  ## example for returnRelativeDate option
  opt <- c(periodicitySelection="YEARLY", periodicityAdjustment="FISCAL", returnRelativeDate=TRUE)
  bdh("GLB ID Equity", "CUR_MKT_CAP", as.Date("1997-12-31"), as.Date("2017-12-31"), options=opt)
}

Run the code above in your browser using DataLab