Title: | R Interface to 'Bloomberg Data License' |
---|---|
Description: | R interface to access prices and market data with the 'Bloomberg Data License' service from <https://www.bloomberg.com/professional/product/data-license/>. As a prerequisite, a valid Data License from 'Bloomberg' is needed together with the corresponding SFTP credentials and whitelisting of the IP from which accessing the service. This software and its author are in no way affiliated, endorsed, or approved by 'Bloomberg' or any of its affiliates. 'Bloomberg' is a registered trademark. |
Authors: | Emanuele Guidotti [aut, cre] |
Maintainer: | Emanuele Guidotti <[email protected]> |
License: | GPL-3 |
Version: | 0.2.6 |
Built: | 2025-01-20 02:39:37 UTC |
Source: | https://github.com/eguidotti/rbldatalicense |
An sftp connection to Bloomberg Datalicense is established. On some Linux systems, this may not work out of the box, as libcurl does not natively support sftp. In that case, you need to compile curl with SFTP support. See here for details: http://askubuntu.com/questions/195545/how-to-enable-sftp-support-in-curl
RblConnect( user, pw, host = "sftp.bloomberg.com", port = "22", protocol = "sftp", verbose = TRUE )
RblConnect( user, pw, host = "sftp.bloomberg.com", port = "22", protocol = "sftp", verbose = TRUE )
user |
The account number assigned by Bloomberg |
pw |
The password assigned by Bloomberg |
host |
The connection host |
port |
The connection port |
protocol |
The connection protocol |
verbose |
logical. Should print extra information on failure? |
logical. Is the connection succesful?
## Not run: # These are dummy credentials. Replace with the credentials received from Bloomberg RblConnect(user = 'dl000000', pw = '0000000000000000') ## End(Not run)
## Not run: # These are dummy credentials. Replace with the credentials received from Bloomberg RblConnect(user = 'dl000000', pw = '0000000000000000') ## End(Not run)
Download a generic file from Bloomberg.
Use RblFiles
to list the files available at Bloomberg.
If the file is not available yet (i.e. a request file has just been uploaded), the function waits until the response file is there or the timeout is reached
RblDownload(file, frequency = 60, timeout = 3600, verbose = TRUE)
RblDownload(file, frequency = 60, timeout = 3600, verbose = TRUE)
file |
character string representing the file to download |
frequency |
the polling frequency to check if file is available at Bloomberg |
timeout |
the timeout in seconds |
verbose |
logical. Should R report extra information on progress? |
character string. Path to the downloaded file. NULL on failure
## Not run: # Run RblConnect first # Build a request file to download the daily closing prices of # EURO STOXX Index from 2005-01-01 to 2015-12-31. RblRequest <- RblRequestBuilder( header = c(FIRMNAME = RblUser(), PROGRAMNAME = 'gethistory', DATERANGE = '20050101|20151231'), fields = c('PX_LAST'), identifiers = c('SXXE Index') ) # Upload the request file req <- RblUpload(RblRequest) # Download the response file out <- RblDownload(req$out) out ## End(Not run)
## Not run: # Run RblConnect first # Build a request file to download the daily closing prices of # EURO STOXX Index from 2005-01-01 to 2015-12-31. RblRequest <- RblRequestBuilder( header = c(FIRMNAME = RblUser(), PROGRAMNAME = 'gethistory', DATERANGE = '20050101|20151231'), fields = c('PX_LAST'), identifiers = c('SXXE Index') ) # Upload the request file req <- RblUpload(RblRequest) # Download the response file out <- RblDownload(req$out) out ## End(Not run)
Retrieve files available at Bloomberg.
RblFiles()
RblFiles()
Vector of character strings representing the filenames available at Bloomberg
## Not run: # Run RblConnect first RblFiles() ## End(Not run)
## Not run: # Run RblConnect first RblFiles() ## End(Not run)
Parse Bloomberg local response files and import the data in R. The PROGRAMNAME in use is auto detected: 'getdata' and 'gethistory' are supported.
RblParse(file, auto.assign = FALSE, env = parent.frame(), verbose = TRUE)
RblParse(file, auto.assign = FALSE, env = parent.frame(), verbose = TRUE)
file |
character string representing the local file to parse (see |
auto.assign |
logical. Should results be loaded to env when using PROGRAMNAME=gethistory? |
env |
where to create objects if auto.assign = TRUE |
verbose |
logical. Should R report extra information on progress? |
data.frame containing identifiers (rows) and fields (columns). NULL on failure.
list of xts objects. If auto.assign=TRUE the xts objects are loaded in env and the object names are returned. NULL on failure.
## Not run: # Run RblConnect first # Build a request file to download the daily closing prices of # EURO STOXX Index from 2005-01-01 to 2015-12-31. RblRequest <- RblRequestBuilder( header = c(FIRMNAME = RblUser(), PROGRAMNAME = 'gethistory', DATERANGE = '20050101|20151231'), fields = c('PX_LAST'), identifiers = c('SXXE Index') ) # Upload the request file req <- RblUpload(RblRequest) # Download the response file out <- RblDownload(req$out) # Import the data data <- RblParse(out) str(data) ## End(Not run)
## Not run: # Run RblConnect first # Build a request file to download the daily closing prices of # EURO STOXX Index from 2005-01-01 to 2015-12-31. RblRequest <- RblRequestBuilder( header = c(FIRMNAME = RblUser(), PROGRAMNAME = 'gethistory', DATERANGE = '20050101|20151231'), fields = c('PX_LAST'), identifiers = c('SXXE Index') ) # Upload the request file req <- RblUpload(RblRequest) # Download the response file out <- RblDownload(req$out) # Import the data data <- RblParse(out) str(data) ## End(Not run)
The function provides a high level interface to Bloomberg Datalicense 'getdata' and 'gethistory' programs.
RblQuery( identifiers, fields, from = NULL, to = Sys.Date(), auto.assign = FALSE, env = parent.frame(), category = c(), add_headers = c(), overrides = c(), limit = 5, split = 100, frequency = 60, timeout = 3600, filename = format(Sys.time(), "%m%d%H%M%S"), verbose = TRUE )
RblQuery( identifiers, fields, from = NULL, to = Sys.Date(), auto.assign = FALSE, env = parent.frame(), category = c(), add_headers = c(), overrides = c(), limit = 5, split = 100, frequency = 60, timeout = 3600, filename = format(Sys.time(), "%m%d%H%M%S"), verbose = TRUE )
identifiers |
vector of Bloomberg identifiers. E.g. c('SXXE Index', 'SX5E Index') |
fields |
vector of Bloomberg fields. E.g. c('PX_LAST', 'PX_CLOSE', 'PX_OPEN', 'PX_HIGH', 'PX_LOW') |
from |
date or string (format YYYY-MM-DD). Start time for the 'gethistory' request. If not provided, a 'getdata' request will be made |
to |
date or string (format YYYY-MM-DD). End time for the 'gethistory' request. Ignored if from is not provided |
auto.assign |
logical. Should results be loaded to env? Ignored if from is not provided |
env |
where to create objects if auto.assign = TRUE |
category |
vector of Data License categories to enable. E.g. c('SECMASTER', 'PRICING', 'FUNDAMENTALS'). WARNING! Each DL category is billed separately, so check your DL license carefully! |
add_headers |
named vector of additional headers. E.g. c(PROGRAMFLAG = 'oneshot') |
overrides |
named vector of Bloomberg overrides. E.g. c('END_DT' = '20100101') |
limit |
prevent requesting data for more than this amout of identifiers. This is done to help you keeping your budget under control. Data License is billing based on the amout of instruments you request, so check your DL license carefully before increasing this limit. |
split |
maximum number of identifiers to process at once. Requests are split to avoid memory leaks. |
frequency |
the polling frequency to check if the response file is available at Bloomberg |
timeout |
the timeout in seconds |
filename |
name assigned to the remote file. Only alphanumeric characters are allowed. Invalid characters are removed. |
verbose |
logical. Should R report extra information on progress? |
The following routine to query Bloomberg is implemented:
see RblUpload
see RblDownload
see RblParse
A list with components
List of characters representing each of the request files uploaded to Bloomberg
List of characters representing each of the response file downloaded from Bloomberg
Return of RblParse
## Not run: # Run RblConnect first data <- RblQuery(fields = c('PX_LAST', 'PX_OPEN', 'PX_HIGH', 'PX_LOW'), identifiers = c('SXXE Index', "SX5E Index"), from = '2005-01-01') str(data) ## End(Not run)
## Not run: # Run RblConnect first data <- RblQuery(fields = c('PX_LAST', 'PX_OPEN', 'PX_HIGH', 'PX_LOW'), identifiers = c('SXXE Index', "SX5E Index"), from = '2005-01-01') str(data) ## End(Not run)
The request file is generated according to Bloomberg Data License Documentation. Refer to the Documentation to build the request.
RblRequestBuilder(header, fields, identifiers, overrides = c())
RblRequestBuilder(header, fields, identifiers, overrides = c())
header |
named vector of headers. E.g. c(FIRMNAME = RblUser(), PROGRAMNAME = 'getdata') |
fields |
vector of Bloomberg fields. E.g. c('PX_LAST', 'PX_OPEN', 'PX_HIGH', 'PX_LOW') |
identifiers |
vector of Bloomberg identifiers. E.g. c('SXXE Index', 'SX5E Index') |
overrides |
named vector of Bloomberg overrides. E.g. c('END_DT' = '20100101') |
character string representing the request file. Upload it to query Bloomberg (see RblUpload
)
## Not run: # Run RblConnect first # Build a request file to download the daily closing prices of # EURO STOXX Index from 2005-01-01 to 2015-12-31. RblRequest <- RblRequestBuilder( header = c(FIRMNAME = RblUser(), PROGRAMNAME = 'gethistory', DATERANGE = '20050101|20151231'), fields = c('PX_LAST'), identifiers = c('SXXE Index') ) RblRequest ## End(Not run)
## Not run: # Run RblConnect first # Build a request file to download the daily closing prices of # EURO STOXX Index from 2005-01-01 to 2015-12-31. RblRequest <- RblRequestBuilder( header = c(FIRMNAME = RblUser(), PROGRAMNAME = 'gethistory', DATERANGE = '20050101|20151231'), fields = c('PX_LAST'), identifiers = c('SXXE Index') ) RblRequest ## End(Not run)
Upload a request file to query Bloomberg. A response file will be generated by Bloomberg.
The request file can be user-defined following the Bloomberg Data License documentation or generated with the RblRequestBuilder
function.
The response file needs to be downloaded (see RblDownload
) and parsed (see RblParse
) to import the data in R.
RblUpload( RblRequest, filename = format(Sys.time(), "%m%d%H%M%S"), verbose = TRUE )
RblUpload( RblRequest, filename = format(Sys.time(), "%m%d%H%M%S"), verbose = TRUE )
RblRequest |
character string representing the request file according to Bloomberg Datalicense documentation. Can be generated with the |
filename |
name assigned to the remote file. Only alphanumeric characters and underscores are allowed. Invalid characters are removed. |
verbose |
logical. Should R report extra information on progress? |
A list with components
the request filename
the response filename
## Not run: # Run RblConnect first # Build a request file to download the daily closing prices of # EURO STOXX Index from 2005-01-01 to 2015-12-31. RblRequest <- RblRequestBuilder( header = c(FIRMNAME = RblUser(), PROGRAMNAME = 'gethistory', DATERANGE = '20050101|20151231'), fields = c('PX_LAST'), identifiers = c('SXXE Index') ) # Upload the request file req <- RblUpload(RblRequest) req ## End(Not run)
## Not run: # Run RblConnect first # Build a request file to download the daily closing prices of # EURO STOXX Index from 2005-01-01 to 2015-12-31. RblRequest <- RblRequestBuilder( header = c(FIRMNAME = RblUser(), PROGRAMNAME = 'gethistory', DATERANGE = '20050101|20151231'), fields = c('PX_LAST'), identifiers = c('SXXE Index') ) # Upload the request file req <- RblUpload(RblRequest) req ## End(Not run)
Retrieve the Bloomberg connection Url.
RblUrl()
RblUrl()
Url string
## Not run: # Run RblConnect first RblUrl() ## End(Not run)
## Not run: # Run RblConnect first RblUrl() ## End(Not run)
Retrieve the Bloomberg User.
RblUser()
RblUser()
User string
## Not run: # Run RblConnect first RblUser() ## End(Not run)
## Not run: # Run RblConnect first RblUser() ## End(Not run)