kyuni22 / pybbg

Bloomberg Open API with pandas
101 stars 46 forks source link

Error with bds() with DVD_HIST_ALL field for AAPL US Equity #27

Open chepurko opened 6 years ago

chepurko commented 6 years ago
import pybbg
from datetime import datetime, date, time

import pandas as pd

bbg = pybbg.Pybbg()
bbg.service_refData()

bds_data = bbg.bds('AAPL US Equity', 'DVD_HIST_ALL')

Trying to retrieve bulk static data with the 'bds()' function. It works fine on a ticker like MSFT US Equity but doesn't work for AAPL US Equity and returns the following error:

---------------------------------------------------------------------------
IndexOutOfRangeException                  Traceback (most recent call last)
<ipython-input-15-865841f87f3b> in <module>()
----> 1 bds_data = bbg.bds('AAPL US Equity', 'DVD_HIST_ALL')

~\Anaconda3\lib\site-packages\pybbg\pybbg_k.py in bds(self, security, field, overrides)
    323                             e = row.getElement(j)
    324                             k = str(e.name())
--> 325                             v = e.getValue()
    326                             if k not in data:
    327                                 data[k] = list()

~\Anaconda3\lib\site-packages\blpapi\element.py in getValue(self, index)
    503         valueGetter = _ELEMENT_VALUE_GETTER.get(datatype,
    504                                                 Element.getValueAsString)
--> 505         return valueGetter(self, index)
    506 
    507     def values(self):

~\Anaconda3\lib\site-packages\blpapi\element.py in getValueAsDatetime(self, index)
    434         self.__assertIsValid()
    435         res = internals.blpapi_Element_getValueAsDatetime(self.__handle, index)
--> 436         _ExceptionUtil.raiseOnError(res[0])
    437         return _DatetimeUtil.convertToNative(res[1])
    438 

~\Anaconda3\lib\site-packages\blpapi\exception.py in raiseOnError(errorCode, description)
    143         """
    144         if errorCode:
--> 145             _ExceptionUtil.raiseException(errorCode, description)
    146 
    147 __copyright__ = """

~\Anaconda3\lib\site-packages\blpapi\exception.py in raiseException(errorCode, description)
    135                 description = "Unknown"
    136         errorClass = _ExceptionUtil.__getErrorClass(errorCode)
--> 137         raise errorClass(description, errorCode)
    138 
    139     @staticmethod

IndexOutOfRangeException: Attempt to access an empty scalar element 'Record Date' (0x0005000b)

Works fine for other tickers like GE, IBM... not sure where to start with this one...

chepurko commented 6 years ago

Tried this in Excel to see what the data actually looks like - pulled up AAPL and compared versus MSFT. My guess is on Ex-Date 2/13/1996 where I'm guessing the dividend was suspended when they were having trouble - and the Record Date, Payable Date, and Dividend Amount fields are blank (null).

trentmaetzold commented 3 years ago

I tried to pull div history for 129 names and got the exception on 25 of them. I think we need to catch the IndexOutOfRangeException on line 325. I'll test it on my local version.