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())
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.
A character variable describing a valid security ticker
A character variable describing an event type; default is ‘TRADE’
A integer denoting the number of minutes for each bar
A Datetime object with the start time, defaults to one hour before current time
A Datetime object with the end time, defaults to current time
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.
A boolean indicating whether verbose operation is desired, defaults to ‘FALSE’
A character variable describing the type of return object; currently supported are ‘matrix’ (also the default), ‘xts’, ‘zoo’ and ‘data.table’
A character variable with the desired local timezone, defaulting to the value ‘TZ’ environment variable, and ‘UTC’ if unset
A connection object as created by a blpConnect
call, and retrieved via the internal function
defaultConnection
.
Dirk Eddelbuettel
if (FALSE) {
getBars("ES1 Index")
}
Run the code above in your browser using DataLab