Resolver One Library Documentation

API for Bloomberg

Back to documentation index page.

This module is only available in Resolver One Financial.

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

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. These must be vertical cell ranges (only the first column of each range will be used). 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):

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.

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 date as a string in quotes and in "DD/MM/YYYY" date format. 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, 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', timeout=3000)

ParallelBloombergRequests

def ParallelBloombergRequests(requests, timeout=60000):

ParallelBloombergRequests allows you to make a number of synchronous BLP, BLPH 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'})
}, timeout=10000)

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

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