matthewgilbert / pdblp

pandas wrapper for Bloomberg Open API
MIT License
242 stars 67 forks source link

BDH Override Returning Error #28

Closed NoahKauffman closed 6 years ago

NoahKauffman commented 6 years ago

Question RE override not working for following bdh call:

con = pdblp.BCon(debug=True, port=8194)
con.start()
con.bdh('IBM US EQUITY', 'TRAIL_12M_NET_SALES','20020101','20180319',[('FUND_PER', 'Y')])

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\Python27\lib\site-packages\pdblp\pdblp.py", line 161, in bdh
    elms, ovrds)
  File "c:\Python27\lib\site-packages\pdblp\pdblp.py", line 186, in _bdh_list
    ovrds, setvals)
  File "c:\Python27\lib\site-packages\pdblp\pdblp.py", line 118, in _create_req
    request.set(name, val)
  File "c:\Python27\lib\site-packages\blpapi\request.py", line 61, in set
    self.asElement().setElement(name, value)
  File "c:\Python27\lib\site-packages\blpapi\element.py", line 640, in setElement
    traits[0](self.__handle, name[0], name[1], value))
  File "c:\Python27\lib\site-packages\blpapi\exception.py", line 145, in raiseOnError
    _ExceptionUtil.raiseException(errorCode, description)
  File "c:\Python27\lib\site-packages\blpapi\exception.py", line 137, in raiseException
    raise errorClass(description, errorCode)
blpapi.exception.NotFoundException: Sub-element '(null)' does not exist. (0x0006000d)

If you call this without the override, it returns quarterly data. In excel using either the override "FUND_PER=Y" correctly returns the results in yearly frequency.

matthewgilbert commented 6 years ago

Please copy the actual output from your screen which is printed out when debug=True into your message.

matthewgilbert commented 6 years ago

If you look at the docstring for bdh you will see

Signature: con.bdh(tickers, flds, start_date, end_date, elms=[], ovrds=[], longdata=False)
Docstring:
Get tickers and fields, return pandas Dataframe with columns as
MultiIndex with levels "ticker" and "field" and indexed by "date".
If long data is requested return DataFrame with columns
["date", "ticker", "field", "value"].

Parameters
----------
tickers: {list, string}
    String or list of strings corresponding to tickers
flds: {list, string}
    String or list of strings corresponding to FLDS
start_date: string
    String in format YYYYmmdd
end_date: string
    String in format YYYYmmdd
elms: list of tuples
    List of tuples where each tuple corresponds to the other elements
    to be set, e.g. [("periodicityAdjustment", "ACTUAL")]
    Refer to A.2.4 HistoricalDataRequest in the Developers Guide for
    more info on these values
ovrds: list of tuples
    List of tuples where each tuple corresponds to the override
    field and value
longdata: boolean
    Whether data should be returned in long data format or pivoted

elms comes before ovrds, so you are specifying an elms in your call not ovrds. You need to provide the key value pair, i.e.

con.bdh('IBM US EQUITY', 'TRAIL_12M_NET_SALES', '20020101', '20180319',
        ovrds=[('FUND_PER', 'Y')])
gflores87 commented 6 years ago

Hi, I'm having a similar trouble when attempting to specify overrides. The excel function is =BDH("SPX Index","IVOL_DELTA","1/1/2016","12/31/2017","IVOL_DELTA_LEVEL=DELTA_LVL_25","IVOL_DELTA_PUT_OR_CALL=IVOL_PUT","IVOL_MATURITY=MATURITY_90D")

and my python proxy is:

import pdblp
import datetime
con = pdblp.BCon(debug=True, port=8194, timeout = 5000)
con.start()
start_date = datetime.datetime(2014,3,26).date().strftime('%Y%m%d')
end_date = datetime.datetime.today().strftime('%Y%m%d')
df = con.bdh('SPX Index', 'IVOL_DELTA', start_date, end_date, elms=[("calendarCodeOverride", 'US'),("IVOL_DELTA_LEVEL", "DELTA_LVL_25")])
con.close()

with output: NotFoundException: Sub-element '(null)' does not exist. (0x0006000d)

Should I use ovrds instead of elms? The appropiate api implementation according to BBG is among the lines of

override1.setElement("fieldId", "IVOL_DELTA_LEVEL") override1.setElement("value", "DELTA_LVL_25")

Thanks for your help!

gflores87 commented 6 years ago

Solved it, proper syntax is:

df = con.bdh('SPX Index', 'IVOL_DELTA', start_date, end_date, 
             ovrds=[("IVOL_DELTA_LEVEL","DELTA_LVL_25"),("IVOL_DELTA_PUT_OR_CALL","IVOL_PUT"),("IVOL_MATURITY","MATURITY_90D")], 
             elms=[("calendarCodeOverride", 'US')])

:)

matthewgilbert commented 6 years ago

I'm marking this as closed since it appears to be a syntax error.