Title: | R Interface to 'Bloomberg' |
---|---|
Description: | An R Interface to 'Bloomberg' is provided via the 'Blp API'. |
Authors: | Whit Armstrong [aut], Dirk Eddelbuettel [aut, cre] , John Laing [aut] |
Maintainer: | Dirk Eddelbuettel <[email protected]> |
License: | file LICENSE |
Version: | 0.3.15 |
Built: | 2024-11-19 06:27:41 UTC |
Source: | https://github.com/rblp/rblpapi |
This function uses the Bloomberg API to retrieve 'bdh' (Bloomberg Data History) queries
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))
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))
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
|
con |
A connection object as created by a |
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. |
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.
Whit Armstrong and Dirk Eddelbuettel
For historical futures series, see ‘DOCS #2072138 <GO>’ on the Bloomberg terminal about selecting different rolling conventions.
## Not run: 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) ## End(Not run)
## Not run: 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) ## End(Not run)
This function uses the Bloomberg API to retrieve 'bdp' (Bloomberg Data Point) queries
bdp(securities, fields, options = NULL, overrides = NULL, verbose = FALSE, identity = defaultAuthentication(), con = defaultConnection())
bdp(securities, fields, options = NULL, overrides = NULL, verbose = FALSE, identity = defaultAuthentication(), con = defaultConnection())
securities |
A character vector with security symbols in Bloomberg notation. |
fields |
A character vector with Bloomberg query fields. |
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’ |
identity |
An optional identity object as created by a
|
con |
A connection object as created by a |
A data frame with as a many rows as entries in
securities
and columns as entries in fields
.
Whit Armstrong and Dirk Eddelbuettel
## Not run: bdp(c("ESA Index", "SPY US Equity"), c("PX_LAST", "VOLUME")) ## using overrides (cf https://github.com/Rblp/Rblpapi/issues/67) bdp("EN00 Index", "MLI_OAS", overrides=c(MLI_DATE="20150831")) ## another override example (cf http://stackoverflow.com/a/39373019/143305) ovrd <- c("CALC_INTERVAL"="10Y", "MARKET_DATA_OVERRIDE"="PE_RATIO") bdp("SPX Index", "INTERVAL_AVG", overrides=ovrd) ## End(Not run)
## Not run: bdp(c("ESA Index", "SPY US Equity"), c("PX_LAST", "VOLUME")) ## using overrides (cf https://github.com/Rblp/Rblpapi/issues/67) bdp("EN00 Index", "MLI_OAS", overrides=c(MLI_DATE="20150831")) ## another override example (cf http://stackoverflow.com/a/39373019/143305) ovrd <- c("CALC_INTERVAL"="10Y", "MARKET_DATA_OVERRIDE"="PE_RATIO") bdp("SPX Index", "INTERVAL_AVG", overrides=ovrd) ## End(Not run)
This function uses the Bloomberg API to retrieve 'bds' (Bloomberg Data Set) queries
bds(security, field, options = NULL, overrides = NULL, verbose = FALSE, identity = defaultAuthentication(), con = defaultConnection(), simplify = getOption("blpSimplify", TRUE))
bds(security, field, options = NULL, overrides = NULL, verbose = FALSE, identity = defaultAuthentication(), con = defaultConnection(), simplify = getOption("blpSimplify", TRUE))
security |
A character value with a single security symbol in Bloomberg notation. |
field |
A character string with a single Bloomberg query field. |
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’ |
identity |
An optional identity object as created by a
|
con |
A connection object as created by a |
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. |
A data frame object with the requested data set.
Whit Armstrong and Dirk Eddelbuettel
## Not run: ## simple query bds("GOOG US Equity", "TOP_20_HOLDERS_PUBLIC_FILINGS") ## example of using overrides overrd <- c("START_DT"="20150101", "END_DT"="20160101") bds("CPI YOY Index","ECO_RELEASE_DT_LIST", overrides = overrd) ## End(Not run)
## Not run: ## simple query bds("GOOG US Equity", "TOP_20_HOLDERS_PUBLIC_FILINGS") ## example of using overrides overrd <- c("START_DT"="20150101", "END_DT"="20160101") bds("CPI YOY Index","ECO_RELEASE_DT_LIST", overrides = overrd) ## End(Not run)
This function uses the Bloomberg API to retrieve 'beqs' (Bloomberg EQS Data) queries
beqs(screenName, screenType = "GLOBAL", language = "", group = "", date = NULL, verbose = FALSE, con = defaultConnection())
beqs(screenName, screenType = "GLOBAL", language = "", group = "", date = NULL, verbose = FALSE, con = defaultConnection())
screenName |
A character string with the name of the screen to execute. It can be a user defined EQS screen or one of the Bloomberg Example screens on EQS |
screenType |
A character string of value PRIVATE or GLOBAL Use PRIVATE for user-defined EQS screen. Use GLOBAL for Bloomberg EQS screen. |
language |
An optional character string with the EQS language |
group |
An optional character string with the Screen folder name as defined in EQS |
date |
An optional Date object with the ‘point in time’ date of the screen to execute. |
verbose |
A boolean indicating whether verbose operation is desired, defaults to ‘FALSE’. |
con |
A connection object as created by a |
A data frame object with the date in the first column and and the requested EQS data in the remaining columns.
Rademeyer Vermaak and Dirk Eddelbuettel
## Not run: head(beqs("Global Oil Companies YTD Return"), 20) head(beqs("Global Oil Companies YTD Return", "GLOBAL"), 20) head(beqs("Global Oil Companies YTD Return", "GLOBAL", "GERMAN"), 20) head(beqs("Global Oil Companies YTD Return", "GLOBAL", "GERMAN", "GENERAL"), 20) head(beqs("Global Oil Companies YTD Return", "GLOBAL", "ENGLISH", "GENERAL", as.Date("2015-09-30")), 20) ## End(Not run)
## Not run: head(beqs("Global Oil Companies YTD Return"), 20) head(beqs("Global Oil Companies YTD Return", "GLOBAL"), 20) head(beqs("Global Oil Companies YTD Return", "GLOBAL", "GERMAN"), 20) head(beqs("Global Oil Companies YTD Return", "GLOBAL", "GERMAN", "GENERAL"), 20) head(beqs("Global Oil Companies YTD Return", "GLOBAL", "ENGLISH", "GENERAL", as.Date("2015-09-30")), 20) ## End(Not run)
This function authenticates against the the Bloomberg API
blpAuthenticate( uuid = getOption("blpUUID", NULL), host = getOption("blpLoginHostname", "localhost"), ip.address = getOption("blpLoginIP", NULL), con = defaultConnection(), default = TRUE, isAuthId = getOption("blpIsAuthId", FALSE), appName = getOption("blpAppName", NULL) )
blpAuthenticate( uuid = getOption("blpUUID", NULL), host = getOption("blpLoginHostname", "localhost"), ip.address = getOption("blpLoginIP", NULL), con = defaultConnection(), default = TRUE, isAuthId = getOption("blpIsAuthId", FALSE), appName = getOption("blpAppName", NULL) )
uuid |
An optional character variable with a unique user id
token. If this is missing the function will attempt to connect
to B-PIPE or SAPI using the connection. It is assumed that an
app_name was set. See |
host |
An optional character variable with a hostname. This is
the hostname of the machine where the user last authenticated.
Either host or ip.address should be provided for user/uuid
authentication. Note this is likely not the same 'host' used in
|
ip.address |
An optional character variable with an IP address
for authentication. Usually the IP address where the uuid/user
last logged into the Bloomberg Terminal appication. Defaults to
|
con |
A connection object as created by a |
default |
A logical indicating whether this authentication should
be saved as the default, as opposed to returned to the
user. Default to |
isAuthId |
A logical indicating whether to interpret the uuid as an authId for authenticating a user with a B-PIPE application. |
appName |
If isAuthId is TRUE, this is a character string
associated with the B-PIPE application name. This will be the same
appName used by |
In the default=TRUE
case nothing is returned, and
this authentication is automatically used for all future calls which
omit the identity
argument. Otherwise an authentication object is
returned which is required by all the accessor functions in the
package. (e.g. bdp()
bds()
getPortfolio()
Whit Armstrong and Dirk Eddelbuettel
## Not run: blpConnect(host=blpHost, port=blpPort) blpAuthenticate(uuid=blpUUID, ip=blpIP_address) bdp("IBM US Equity", "NAME") blpid <- blpAuthenticate(uuid=blpUUID, ip=blpIP_address) bdp("IBM US Equity", "NAME", identity=blpid) ## End(Not run)
## Not run: blpConnect(host=blpHost, port=blpPort) blpAuthenticate(uuid=blpUUID, ip=blpIP_address) bdp("IBM US Equity", "NAME") blpid <- blpAuthenticate(uuid=blpUUID, ip=blpIP_address) bdp("IBM US Equity", "NAME", identity=blpid) ## End(Not run)
This function connects to the Bloomberg API
blpConnect(host = getOption("blpHost", "localhost"), port = getOption("blpPort", 8194L), default = TRUE, appName = getOption("blpAppName", NULL))
blpConnect(host = getOption("blpHost", "localhost"), port = getOption("blpPort", 8194L), default = TRUE, appName = getOption("blpAppName", NULL))
host |
A character option with either a machine name that is resolvable by DNS, or an IP address. Defaults to ‘localhost’. |
port |
An integer variable with the connection port. Default
to |
default |
A logical indicating whether this connection should
be saved as the default, as opposed to returned to the
user. Default to |
appName |
the name of an application that is authorized to connect to bpipe. If this is NULL Rblpapi connects to the Bloomberg API but cannot authenticate with an app name. This requires the user to authenticate with a user uuid. |
For both host
and port
argument, default
values can also be specified via options
using,
respectively, the named entries blpHost
and
blpConnect
.
If an additional option blpAutoConnect
is set to
‘TRUE’, a connection is established in the
.onAttach()
function and stored in the package
environment. This effectively frees users from having to
explicitly create such an object.
In the default=TRUE
case nothing is returned, and
this connection is automatically used for all future calls which
omit the con
argument. Otherwise a connection object is
returned which is required by all the accessor functions in the
package.
Whit Armstrong and Dirk Eddelbuettel
Many SAPI and bPipe connections require authentication
via blpAuthenticate
after blpConnect
.
## Not run: con <- blpConnect() # adjust as needed ## End(Not run)
## Not run: con <- blpConnect() # adjust as needed ## End(Not run)
This function provides an empty stub and does not really disconnect.
blpDisconnect(con)
blpDisconnect(con)
con |
A connection object |
The internal connection object is managed via finalizers. As such the connection is only destroyed, and the connection removed, once the packaged is unloaded or the session is otherwise terminated.
A boolean is returned; it simply states whether the connection object was small or large relative to an arbitrary cutoff of 1000 bytes.
Whit Armstrong and Dirk Eddelbuettel
## Not run: blpDisconnect(con) ## End(Not run)
## Not run: blpDisconnect(con) ## End(Not run)
This function uses the Bloomberg API to retrieve 'bsrcb' (Bloomberg SRCH Data) queries
bsrch(domain, limit = "", verbose = FALSE, con = defaultConnection())
bsrch(domain, limit = "", verbose = FALSE, con = defaultConnection())
domain |
A character string with the name of the domain to execute. It can be a user defined SRCH screen, commodity screen or one of the variety of Bloomberg examples. All domains are in the format <domain>:<search_name>. |
limit |
A character string containing a value by which to limit the search length – NOT YET IMPLEMENTED |
verbose |
A boolean indicating whether verbose operation is desired, defaults to ‘FALSE’. |
con |
A connection object as created by a |
A data frame object with the requested SRCH data.
There are two main domains used for bsrch. The COMDTY domain requires additional parameters and is not supported. The FI domain works on user-defined searches accessed via SRCH.
Morgan Williams and Dirk Eddelbuettel
## Not run: head(bsrch("FI:SRCHEX.@CLOSUB"), 20) ## End(Not run)
## Not run: head(bsrch("FI:SRCHEX.@CLOSUB"), 20) ## End(Not run)
These functions return the default connection/authentication objects from the package environment. If no default connection/authentication has been established yet, will return NULL. In the case of authentication, if using a desktop/workstation session, NULL will work fine. If using SAPI/Bpipe, you may need to use blpAuthenticate() to create an authentication object.
defaultConnection() defaultAuthentication()
defaultConnection() defaultAuthentication()
Required arguments can be set via options
. See
blpConnect
and blpAuthenticate
for details.
In addition, if options blpAutoConnect
and/or
blpAutoAuthenticate
are set to ‘TRUE’, a connection and/or
authentication is established in the .onAttach()
function and
stored in the package environment. This effectively frees users from
having to explicitly create such objects. Of course, the user can also
call blpConnect
and/or blpAuthenticate
explicitly and
store the connection/authentication objects. These helper functions
look up the stored connection/authentications object and return them.
In case no connection has been established, an error message is shown.
In case no authentication has been established, NULL is returned.
(NULL is sufficent for Desktop API connections.)
Whit Armstrong and Dirk Eddelbuettel
## Not run: con <- defaultConnection() blpid <- defaultAuthentication() ## End(Not run)
## Not run: con <- defaultConnection() blpid <- defaultAuthentication() ## End(Not run)
This function uses the Bloomberg API to retrieve fieldInfo
fieldInfo(fields, con = defaultConnection())
fieldInfo(fields, con = defaultConnection())
fields |
A character vector with Bloomberg query fields. |
con |
A connection object as created by a |
A data frame with as a many rows as entries in
fields
Whit Armstrong and Dirk Eddelbuettel
## Not run: fieldInfo(c("PX_LAST", "VOLUME")) ## End(Not run)
## Not run: fieldInfo(c("PX_LAST", "VOLUME")) ## End(Not run)
This function searches for matching Bloomberg data fields given a search term.
fieldSearch(searchterm, excludeterm = NULL, con = defaultConnection())
fieldSearch(searchterm, excludeterm = NULL, con = defaultConnection())
searchterm |
A string with the term to search for |
excludeterm |
Deprecated. A warning is issued if not ‘NULL’, the default |
con |
A connection object as created by a |
A data.frame
with three columns of the id,
mnenemonic and description of each match.
Dirk Eddelbuettel
## Not run: head(fieldSearch("vwap"), 20) ## End(Not run)
## Not run: head(fieldSearch("vwap"), 20) ## End(Not run)
This function uses the Bloomberg API to retrieve bars for the requested security.
getBars(security, eventType = "TRADE", barInterval = 60, startTime = Sys.time() - 60 * 60 * 6, endTime = Sys.time(), options = NULL, verbose = FALSE, returnAs = getOption("blpType", "matrix"), tz = Sys.getenv("TZ", unset = "UTC"), con = defaultConnection())
getBars(security, eventType = "TRADE", barInterval = 60, startTime = Sys.time() - 60 * 60 * 6, endTime = Sys.time(), options = NULL, verbose = FALSE, returnAs = getOption("blpType", "matrix"), tz = Sys.getenv("TZ", unset = "UTC"), con = defaultConnection())
security |
A character variable describing a valid security ticker |
eventType |
A character variable describing an event type; default is ‘TRADE’ |
barInterval |
A integer denoting the number of minutes for each bar |
startTime |
A Datetime object with the start time, defaults to one hour before current time |
endTime |
A Datetime object with the end time, defaults to current time |
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. |
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 ‘matrix’ (also the default), ‘xts’, ‘zoo’ and ‘data.table’ |
tz |
A character variable with the desired local timezone, defaulting to the value ‘TZ’ environment variable, and ‘UTC’ if unset |
con |
A connection object as created by a |
A numeric matrix with elements ‘time’ (as a
‘POSIXct’ object), ‘open’, ‘high’,
‘low’, ‘close’, ‘numEvents’, ‘volume’,
‘value’ or an object of the type selected in returnAs
.
Note that the ‘time’ value is adjusted: Bloomberg returns the
opening time of the bar interval, whereas financial studies
typically refer to the most recent timestamp. Therefore, if one wants
the timestamp associated with the end of the bar interval one should
add the length of the bar interval to time value returned from Bloomberg
to obtain the time at the end of the interval.
Dirk Eddelbuettel
## Not run: getBars("ES1 Index") ## End(Not run)
## Not run: getBars("ES1 Index") ## End(Not run)
This function retrieves the version of Bloomberg API headers.
getHeaderVersion()
getHeaderVersion()
A string with four dot-separated values for major, minor, pathch and build version of the headers.
Dirk Eddelbuettel
getRuntimeVersion
## Not run: getHeaderVersion() ## End(Not run)
## Not run: getHeaderVersion() ## End(Not run)
This function uses the Bloomberg API to retrieve multiple ticks for the requested security.
getMultipleTicks(security, eventType = c("TRADE", "BID", "ASK"), startTime = Sys.time() - 60 * 60, endTime = Sys.time(), verbose = FALSE, returnAs = getOption("blpType", "data.frame"), tz = Sys.getenv("TZ", unset = "UTC"), con = defaultConnection())
getMultipleTicks(security, eventType = c("TRADE", "BID", "ASK"), startTime = Sys.time() - 60 * 60, endTime = Sys.time(), verbose = FALSE, returnAs = getOption("blpType", "data.frame"), tz = Sys.getenv("TZ", unset = "UTC"), con = defaultConnection())
security |
A character variable describing a valid security ticker |
eventType |
A character vector describing event
types, default is |
startTime |
A Datetime object with the start time, defaults to one hour before current time |
endTime |
A Datetime object with the end time, defaults to current time |
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) and ‘data.table’ |
tz |
A character variable with the desired local timezone, defaulting to the value ‘TZ’ environment variable, and ‘UTC’ if unset |
con |
A connection object as created by a |
A numeric matrix with elements ‘time’, (as a
‘POSIXct’ object), ‘values’ and ‘sizes’, or
an object of the type selected in returnAs
.
Dirk Eddelbuettel
This function uses the Bloomberg API to retrieve 'portfolio' queries
getPortfolio(security, field, options = NULL, overrides = NULL, verbose = FALSE, identity = defaultAuthentication(), con = defaultConnection())
getPortfolio(security, field, options = NULL, overrides = NULL, verbose = FALSE, identity = defaultAuthentication(), con = defaultConnection())
security |
A character value with a single security symbol in Bloomberg notation. |
field |
A character string with a single Bloomberg query field. |
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’ |
identity |
An optional identity object as created by a
|
con |
A connection object as created by a |
A list with as many entries as there are entries in
securities
; each list contains a data.frame 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 data frame.
John Laing
This function retrieves the version of Bloomberg API run-time.
getRuntimeVersion()
getRuntimeVersion()
A string with four dot-separated values for major, minor, pathch and build version of the run-time library.
Dirk Eddelbuettel
getHeaderVersion
## Not run: getRuntimeVersion() ## End(Not run)
## Not run: getRuntimeVersion() ## End(Not run)
This function uses the Bloomberg API to retrieve ticks for the requested security.
getTicks(security, eventType = "TRADE", startTime = Sys.time() - 60 * 60, endTime = Sys.time(), verbose = FALSE, returnAs = getOption("blpType", "data.frame"), tz = Sys.getenv("TZ", unset = "UTC"), con = defaultConnection())
getTicks(security, eventType = "TRADE", startTime = Sys.time() - 60 * 60, endTime = Sys.time(), verbose = FALSE, returnAs = getOption("blpType", "data.frame"), tz = Sys.getenv("TZ", unset = "UTC"), con = defaultConnection())
security |
A character variable describing a valid security ticker |
eventType |
A character variable describing an event, default is ‘TRADE’. |
startTime |
A Datetime object with the start time, defaults to one hour before current time |
endTime |
A Datetime object with the end time, defaults to current time |
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’ |
tz |
A character variable with the desired local timezone, defaulting to the value ‘TZ’ environment variable, and ‘UTC’ if unset |
con |
A connection object as created by a |
Depending on the value of ‘returnAs’, either a ‘data.frame’ or ‘data.table’ object also containing non-numerical information such as condition codes, or a time-indexed container of type ‘xts’ and ‘zoo’ with a numeric matrix containing only ‘value’ and ‘size’.
Bloomberg returns condition codes as well, and may return multiple observations for the same trade. Eg for ES we can get ‘AS’ or ‘AB’ for aggressor buy or sell, ‘OR’ for an order participating in the matching event, or a ‘TSUM’ trade summary. Note that this implies double-counting. There may be an option for this in the API.
The Bloomberg API allows to retrieve up to 140 days of intra-day history relative to the current date.
Dirk Eddelbuettel
## Not run: res <- getTicks("ES1 Index") str(res) head(res, 20) res <- getTicks("ES1 Index", returnAs="data.table") str(res) head(res, 20) ## End(Not run)
## Not run: res <- getTicks("ES1 Index") str(res) head(res, 20) res <- getTicks("ES1 Index", returnAs="data.table") str(res) head(res, 20) ## End(Not run)
This function uses the Bloomberg API to look up tickers and descriptions given the name of a company.
lookupSecurity(query, yellowkey = c("none", "cmdt", "eqty", "muni", "prfd", "clnt", "mmkt", "govt", "corp", "indx", "curr", "mtge"), language = c("none", "english", "kanji", "french", "german", "spanish", "portuguese", "italian", "chinese_trad", "korean", "chinese_simp", "none_1", "none_2", "none_3", "none_4", "none_5", "russian"), maxResults = 20, verbose = FALSE, con = defaultConnection())
lookupSecurity(query, yellowkey = c("none", "cmdt", "eqty", "muni", "prfd", "clnt", "mmkt", "govt", "corp", "indx", "curr", "mtge"), language = c("none", "english", "kanji", "french", "german", "spanish", "portuguese", "italian", "chinese_trad", "korean", "chinese_simp", "none_1", "none_2", "none_3", "none_4", "none_5", "russian"), maxResults = 20, verbose = FALSE, con = defaultConnection())
query |
A character variable describing the name of the company; for certain queries a trailing space may help. |
yellowkey |
A character variable that restricts the asset classes to search in; one of “none”, “cmdt”, “eqty”, “muni”, “prfd”, “clnt”, “mmkt”, “govt”, “corp”, “indx”, “curr”, “mtge”. |
language |
A character variable denoting the language that the results will be translated in; one of “NONE”, “english”, “kanji”, “french”, “german”, “spanish”, “portuguese”, “italian”, “chinese_trad”, “korean”, “chinese_simp”, “none_1”, “none_2”, “none_3”, “none_4”, “none_5”, “russian” |
maxResults |
A integer variable containing a value by which to limit the search length |
verbose |
A boolean indicating whether verbose operation is desired, defaults to ‘FALSE’ |
con |
A connection object as created by a |
A data.frame with two columns of the ticker and description of each match.
Kevin Jin and Dirk Eddelbuettel
## Not run: lookupSecurity("IBM") lookupSecurity("IBM", maxResuls=1000) # appears to be capped at 1000 lookupSecurity("IBM", "mtge") lookupSecurity("IBM ", "mtge") # trailing space affects query ## modify the symbol column (cf issue ticket 215 at GitHub) res <- lookupSecurity("IBM") res[, "symbol"] <- sub(pattern="^(.+)<(.)(.+)>$", "\\1 \\U\\2\\E\\3", perl=TRUE, res[, "security"]) res ## End(Not run)
## Not run: lookupSecurity("IBM") lookupSecurity("IBM", maxResuls=1000) # appears to be capped at 1000 lookupSecurity("IBM", "mtge") lookupSecurity("IBM ", "mtge") # trailing space affects query ## modify the symbol column (cf issue ticket 215 at GitHub) res <- lookupSecurity("IBM") res[, "symbol"] <- sub(pattern="^(.+)<(.)(.+)>$", "\\1 \\U\\2\\E\\3", perl=TRUE, res[, "security"]) res ## End(Not run)
This function uses the Bloomberg API to stream live market data
subscribe(securities, fields, fun, options = NULL, identity = defaultAuthentication(), con = defaultConnection())
subscribe(securities, fields, fun, options = NULL, identity = defaultAuthentication(), con = defaultConnection())
securities |
A character vector with security symbols in Bloomberg notation. |
fields |
A character vector with Bloomberg query fields. |
fun |
An R function to be called on the subscription data. |
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. |
identity |
An optional identity object as created by a
|
con |
A connection object as created by a |
The subscribe function allows one to subscribe to streaming market quotes.
Full detials of the subscription string can be found in the header file blpapi_subscriptionlist.h.
This function always returns NULL.
Whit Armstrong
https://bloomberg.github.io/blpapi-docs/cpp/3.8/
## Not run: subscribe(securities=c("TYZ5 Comdty","/cusip/912810RE0@BGN"), fields=c("LAST_PRICE","BID","ASK"), fun=function(x) print(str(x$data))) ## End(Not run)
## Not run: subscribe(securities=c("TYZ5 Comdty","/cusip/912810RE0@BGN"), fields=c("LAST_PRICE","BID","ASK"), fun=function(x) print(str(x$data))) ## End(Not run)