I'm trying to extract bloomberg data using the BDS formula in python and I have downloaded the pybbg library. I want to include several overrides but I get an error. What I'm trying to extract is done following with the excel API addin: =BDS("SUBC NO Equity","PG_REVENUE","PRODUCT_GEO_OVERRIDE=G","FUND_PER=Q"= For one override, following code works (https://github.com/kyuni22/pybbg):
import unittest
import datetime
import pybg
class TestPybbg(unittest.TestCase):
def test_bds(self):
tester = pybbg.Pybbg()
data = tester.bds('SUBC NO Equity','PG_REVENUE',overrides={'FUND_PER': 'Q'})
print(data)
if __name__ == '__main__':
unittest.main()
Following Error arises if the Company doesn't have that level detail:
Traceback (most recent call last):
File "C:/Users/bloomberg/.spyder-py3/temp.py", line 23, in test_bds_override
data = tester.bds('AKSO NO Equity','PG_REVENUE',overrides={'PRODUCT_GEO_OVERRIDE':'G','FUND_PER':'Q'})
File "C:\Users\bloomberg\AppData\Local\Continuum\Miniconda3\envs\work\lib\site-packages\pybbg-0.0.1-py3.6.egg\pybbg\pybbg_k.py", line 295, in bds
fieldData = securityData.getValue(i).getElement("fieldData").getElement(field)
File "C:\Users\bloomberg\AppData\Local\Continuum\Miniconda3\envs\work\lib\site-packages\blpapi\element.py", line 347, in getElement
_ExceptionUtil.raiseOnError(res[0])
File "C:\Users\bloomberg\AppData\Local\Continuum\Miniconda3\envs\work\lib\site-packages\blpapi\exception.py", line 145, in raiseOnError
_ExceptionUtil.raiseException(errorCode, description)
File "C:\Users\bloomberg\AppData\Local\Continuum\Miniconda3\envs\work\lib\site-packages\blpapi\exception.py", line 137, in raiseException
raise errorClass(description, errorCode)
blpapi.exception.NotFoundException: Attempt to access unavailable sub-element 'PG_REVENUE' of element 'fieldData'. (0x0006000d)
I figured it out, if you add the following to the formula you can include several overrides:
data = tester.bds('SUBC NO Equity','PG_REVENUE',overrides={'PRODUCT_GEO_OVERRIDE':'G','FUND_PER':'Q'})