Resolver One Library Documentation

API for Bloomberg

Up to Library documentation index.

Access real-time Bloomberg data feeds.

In order to use the Bloomberg functions, you will need to have Bloomberg installed on your computer. You will also need to install the extra software that allows Bloomberg to be used in spreadsheet applications. The software to install is called the Bloomberg Desktop .NET SDK.

It is very important that you DO NOT INSTALL the Bloomberg Server .NET SDK!

If no Bloomberg library is installed, then these functions raise a BloombergError.

BDS() and BLP() are executed asynchronously. When they are used, Resolver One will continue to execute as it subscribes to the Bloomberg interface. Whilst waiting for the information from Bloomberg, a yellow cross will appear in the related cell and the Tool Tip warning will be "FetchingDataWarning: Fetching 'Ticker:Field'". The spreadsheet will be recalculated when Bloomberg provides an initial value, usually in less than a second, and will recalculate again whenever updates to this value are received.

If you need synchronous versions of these functions (for example, if you want to call them in user code and get meaningful results rather than FetchingData warnings), you can use the BLPSync() and BDSSync() functions. These functions are not imported automatically in user code; you will need to import them yourself.

This module also provides the ParallelBloombergRequests() function to enable you to make a number of synchronous Bloomberg requests at once.

If the underlying Bloomberg function returns more than one value, BLPH() and BDS() will return a 2D .NET array.

Functions

BDH

def BDH(securityName, fieldMnemonic, startDate, endDate,
        *options)

The BDH function retrieves historical information on any security listed on Bloomberg. It returns a two-dimensional array, with each row containing a date and the value of the requested field on that date.

A security is specified by a string of text, consisting of the ticker or ticker exchange followed by a market sector key, for example "BARC LN Equity". Each security may have several fields of prices and information associated with it, for example "LAST_PRICE" might be one field.

The start and end dates provided determine the boundaries of the data retrieved. If endDate is None or an empty string, the current day is used.

Additional options can be supplied as 'name=value' strings after the end date. Resolver One currently supports periodicity (per) and currency (fx).

The currency option allows you to specify the currency that the returned data should be reported in. The option should be a string containing "fx=xxx", where xxx is the ISO4217 short currrency code e.g. USD, JPY, CHF, GBP etc.

The periodicity option allows you to specify the time intervals between successive dates in the resulting array. It should be a string containing "per=xx", where xx is one of the following codes:

Code Meaning
ad Actual daily
aw Actual weekly
am Actual monthly
aq Actual quarterly
as Actual semi-annually
aa Actual annual
cd Calendar daily
cw Calendar weekly
cm Calendar monthly
cq Calendar quarterly
cs Calendar semi-annually
ca Calendar annual
fq Fiscal quarterly
fs Fiscal semi-annually
fa Fiscal annual

The Actual codes indicate that the periods should be based on the day of the specified end date in the period. For example if you used per=am, with an end date of 23/07/2008, you would get monthly values on the 23rd of each month, and if you used per=aa with the end date 23/07/2008, you'd get values for the 23rd of July each year. If you use weekly with an end date which is a Tuesday, you'd get dates that correspond to the Tuesday of each week.

The Calendar codes use the calendar end day of each time period, so per=cm will use the last trading day of each month, while per=ca will give the last day of each year in the period.

The Fiscal codes use the financial end dates for each period.

If periodicity is not specified, the "Actual daily" period is used.

Example usage:

BDH('GOOG US Equity', 'PX_LAST', '01/01/2005', '')
BDH('GOOG US Equity', 'PX_LAST', '01/01/2005', '01/01/2008')
BDH('GOOG US Equity', 'PX_LAST', '01/01/2005', '01/01/2008', 'per=cm')
BDH('GOOG US Equity', 'PX_LAST', '01/01/2008', '', 'fx=GBP')
BDH('GOOG US Equity', 'PX_LAST', '01/01/2005', '01/01/2008', 'fx=JPY', 'per=ca')

BDP

def BDP(securityName, fieldMnemonic, overrideNames=None,
        overrideValues=None)

BDP is an alias to the BLP function. Consult BLP's documentation for more information.

BDS

def BDS(securityName, fieldMnemonic, overrideNames=None,
        overrideValues=None)

The BDS function retrieves up-to-date information on any security listed on Bloomberg. A security is specified by a string of text, consisting of the ticker or ticker exchange followed by a market sector key, for example "BARC LN Equity". Each security may have several fields of prices and information associated with it, for example "LAST_PRICE" might be one field.

It is also possible to specify additional request fields by passing extra parameters; 2 forms are acceptable.

The simplest form requires a Python dictionary (mapping field name to value) as the third parameter.

The more complex, but potentially more convenient form, requires cell ranges as the third and fourth parameters. The first of the ranges should contain the names of the fields and the second the values for the named fields. The two cell ranges must be the same length and the names and values must be in the appropriate order.

BDSSync

def BDSSync(securityName, fieldMnemonic, overrideNames=None,
            overrideValues=None, timeout=5000)

This function allows you to make synchronous BDS requests: the recalculation will wait for the response from Bloomberg. This can be useful if you want to use the results immediately in other calculations without another recalculation. It should only be used from user code, not from the grid. It accepts the same arguments as BDS, as well as an optional timeout (in milliseconds) which is the maximum time the function should wait for the response (this defaults to 5 seconds).

BDSSync is not imported in user code by default. To call it, import it first.

from Library.BloombergFunctions import BDSSync
result = BDSSync('security', 'fieldname', {'FIELD': 'value'}, timeout=3000)

BLP

def BLP(securityName, fieldMnemonic, overrideNames=None,
        overrideValues=None)

The BLP function allows you to get up-to-date information on any security listed on Bloomberg. A security is specified by a string of text, consisting of the ticker or ticker exchange followed by a market sector key, for example BARC LN Equity. Each security may have several fields of prices and information associated with it, for example LAST_PRICE might be one field.

It is also possible to specify additional request fields by passing extra parameters; two forms are acceptable.

The simplest form requires a Python dictionary (mapping field name to value) as the third parameter.

The more complex, but potentially more convenient form, requires cell ranges as the third and fourth parameters. The first of the ranges should contain the names of the fields and the second the values for the named fields. The two cell ranges must be the same length and the names and values must be in the appropriate order.

BLP also supports the legacy way of passing overrides, by specifying multiple fields in a cell range and override values for a number of them. The call needs to have only three arguments. For example, given the worksheet filled with the following values:

ws = workbook['Sheet']
ws.A1 = 'CUST_TRR_START_DT'
ws.A2 = 'CUST_TRR_END_DT'
ws.A3 = 'CUST_TRR_RETURN_Holding_Per'

ws.B1 = '20080417'
ws.B2 = '20080529'

the formula BLP('TEMN SW Equity', A1:A3, B1:B2) returns a three-element list ['17/04/2008', '29/05/2008', 23.7037], where the two first elements are the values passed in as overrides, and the third element is the value for CUST_TRR_RETURN_Holding_Per, the only field for which there was no override value specified.

BLPH

def BLPH(securityName, fieldMnemonic, date, endDate=None,
         timeout=5000)

The BLPH function allows you to access historical data from Bloomberg. You specify the security you are interested in by a string of text consisting of the ticker or ticker exchange followed by a market sector key, for example "BARC LN Equity". Each security may have several fields associated with it, for example "LAST_PRICE" so this must be specified in the function after the security. Finally, to access the historical data, specify the as a string in quotes in either the "YYYYMMDD" format or using the date format that your computer uses. Alternatively you can use .NET, Resolver One or Python date objects.

BLPH() synchronously returns the value of the requested field on the given date.

Optionally, you can provide the end date as the fourth argument. You can Also specify the maximum time (in milliseconds) that BLPH will wait for a response using the timeout parameter (the default timeout is 5 seconds).

BLPSync

def BLPSync(securityName, fieldMnemonic, overrideNames=None,
            overrideValues=None, timeout=5000)

This function allows you to make synchronous BLP requests: the recalculation will wait for the response from Bloomberg. This can be useful if you want to use the results immediately in other calculations without another recalculation. It should only be used from user code, not from the grid. It accepts the same arguments as BLP, as well as an optional timeout (in milliseconds) which is the maximum time the function should wait for the response (this defaults to 5 seconds).

BLPSync is not imported in user code by default. To call it, import it first.

from Library.BloombergFunctions import BLPSync
result = BLPSync('security', 'fieldname', {'FIELD': 'value'}, timeout=3000)

ParallelBloombergRequests

def ParallelBloombergRequests(requests, timeout=15000)

ParallelBloombergRequests allows you to make a number of synchronous BLP, BLPH, BDH or BDS requests that run at the same time, saving time over doing them sequentially. The performance should be comparable to the the asynchronous versions, although ParallelBloombergRequests will wait until every request has finished.

It expects a dictionary that contains requests in the format of: {requestName : ('functionName', argument1, argument2, ...),} and returns two dictionaries; the first mapping the names of successful requests to their results, and the second mapping any failed requests to the error that occurred.

It also accepts an optional timeout parameter, which specifies the maximum time (in milliseconds) each function should wait for a response. This is passed to the actual BLPSync, BLPH and BDSSync functions.

A complete example:

results, errors = ParallelBloombergRequests({
        'last': ('BLP', 'SECURITY', 'LAST_PRICE'),
        'past': ('BLPH', 'SECURITY', 'EQY_DVD_HIST_GROSS', DateTime.Now),
        'avg':  ('BDS', 'SECURITY', 'AVG_PRICE', {'FIELD_NAME': 'value'})
        'more_history':  ('BDH', 'SECURITY', 'AVG_PRICE', '01/01/2008', '31/12/2008', 'per=cm')
}, timeout=10000)

if errors:
    for key, error in errors.items():
        print key, str(error)

print results['last']
print results['past']
print results['avg']
print results['more_history']

Comments

If you have comments, questions or suggestions about any of the Resolver One documentation, please post them to the Documentation Suggestions Forum.