matthewgilbert / blp

Pythonic interface for Bloomberg Open API
Apache License 2.0
112 stars 24 forks source link

Inconsistent Data Pulls for Bigger Tables #4

Closed philiphossu closed 2 years ago

philiphossu commented 2 years ago

I've noticed an issue using the package and could use some pointer in determining if it's an issue on my end, or with the package, or just with bloomberg's API.

I'm pulling a number of fields using bdh for a specific date in the past (using start_date == end_date) for a long list of mortgage cusips. Running the same query multiple times does not return consistent results sometimes. As an example, the query will successfully return 1m CPR, 6m CPR, 12m CPR, but for 3m CPR I only get "None", even though this doesn't match what my Bloomberg terminal says. See images below for reference -- all rows are correct except 297:

image image

When I re-run the code to populate cpr_df, as previously stated, any of the following outcomes may take place without any apparent rhyme or reason: (1) the df remains with bug, (2) the bug is fixed, (3) some other bug is populated.

image

I've included snipets of the relevant parts of my script below.

Thank you for your input. Happy to provide more details if helpful.


def bbg_query(q_list, q_fields, src, start_dt = None, end_dt = None, orides = None):
    if(src == 'bds'):
        df = bquery.bds(q_list, q_fields)
    elif(src == 'bdh'):
        df = bquery.bdh(q_list, q_fields, start_date = start_dt, end_date = end_dt)
        df = df.sort_values(by='security')
    elif(src == 'bdp'):
        df = bquery.bdp(q_list, q_fields, orides)
    else:
        logging.info('Bad bbg data request in bbg_query().')
        exit(1)
    return(df)

cpr_df = bbg_query(bbg_cusips, ['CPN', 'MTG_PL_CPR_1M', 'MTG_PL_CPR_3M', 'MTG_PL_CPR_6M', 'MTG_PL_CPR_12M', 'MTG_WHLN_NUMBER_LOAN'], 'bdh', start_end_dt, start_end_dt)
cpr_df = cpr_df.sort_values(by='security')
cpr_df = cpr_df.reset_index(drop = True)```
matthewgilbert commented 2 years ago

Apologies for the late response I don't get much time to maintain this library these days.

For this type of issue generally the best approach is to look at the raw Bloomberg response data. If this is an issue with an inconsistency in the underlying data there isn't much blp can do and you are best of contacting Bloomberg directly. To get back the underlying data unparsed you can take a look at the example here https://matthewgilbert.github.io/blp/quickstart.html#Retrieve-json-data, in particular something like

query = blp.create_query(
    request_type="HistoricalDataRequest",
    values={
        "securities": ["SPY US Equity"],
        "fields": ["VOLUME"],
        "startDate": "20190101",
        "endDate": "20190105",
    },
)

resp = bquery.query(query, parse=False, collector=list)
philiphossu commented 2 years ago

I have attempted this earlier on and the data was still inconsistent between pulls for the same fields/time period/securities, again only on the bdh endpoint.

I suppose have to assume it's on bloomberg's end, but unfortunately they don't provide any feedback as they say 'we don't support anything in python' and only refer me back to the general API guidelines.

Guess I'm just out of luck for the time being.