matthewgilbert / pdblp

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

list index out of range #53

Open MyBigNurse opened 5 years ago

MyBigNurse commented 5 years ago

con = pdblp.BCon(debug=True, port=8194) con.start() ticker = 'IBM US Equity' sd = datetime.datetime(2018, 12, 12, 0,0,0,0).strftime('%Y%m%d') ed = str(datetime.datetime.today().strftime('%Y%m%d'))

cols = ['TOT_RETURN_INDEX_NET_DVDS','TOT_RETURN_INDEX_GROSS_DVDS'] px_volume_by_day = con.bdh([ticker],cols,sd,ed) px_volume_by_day

Debug options -

px_volume_by_day = con.bdh([ticker],cols,sd,ed) DEBUG:root:Sending Request: HistoricalDataRequest = { securities[] = { "IBM US Equity" } fields[] = { "TOT_RETURN_INDEX_NET_DVDS", "TOT_RETURN_INDEX_GROSS_DVDS" } startDate = "20181212" endDate = "20181217" overrides[] = { } }

DEBUG:root:Message Received: HistoricalDataResponse = { securityData = { security = "IBM US Equity" eidData[] = { } sequenceNumber = 0 fieldExceptions[] = { } fieldData[] = { fieldData = { date = 2018-12-12 TOT_RETURN_INDEX_NET_DVDS = 121.160000 TOT_RETURN_INDEX_GROSS_DVDS = 121.160000 } fieldData = { date = 2018-12-13 TOT_RETURN_INDEX_NET_DVDS = 120.730000 TOT_RETURN_INDEX_GROSS_DVDS = 120.730000 } fieldData = { date = 2018-12-14 TOT_RETURN_INDEX_NET_DVDS = 119.900000 TOT_RETURN_INDEX_GROSS_DVDS = 119.900000 } fieldData = { date = 2018-12-17 TOT_RETURN_INDEX_NET_DVDS = 118.660000 TOT_RETURN_INDEX_GROSS_DVDS = 118.660000 } } } }

px_volume_by_day Traceback (most recent call last): File "", line 1, in File "c:\Python35\lib\site-packages\pandas\core\base.py", line 82, in repr return str(self) File "c:\Python35\lib\site-packages\pandas\core\base.py", line 61, in str return self.unicode() File "c:\Python35\lib\site-packages\pandas\core\frame.py", line 663, in unicode line_width=width, show_dimensions=show_dimensions) File "c:\Python35\lib\site-packages\pandas\core\frame.py", line 1971, in to_string formatter.to_string() File "c:\Python35\lib\site-packages\pandas\io\formats\format.py", line 648, in to_string strcols = self._to_str_columns() File "c:\Python35\lib\site-packages\pandas\io\formats\format.py", line 539, in _to_str_columns str_columns = self._get_formatted_column_labels(frame) File "c:\Python35\lib\site-packages\pandas\io\formats\format.py", line 782, in _get_formatted_column_labels str_columns = _sparsify(str_columns) File "c:\Python35\lib\site-packages\pandas\core\indexes\multi.py", line 2962, in _sparsify prev = pivoted[start] IndexError: list index out of range

MyBigNurse commented 5 years ago

Have noticed some strange behavior such as the following command which fails:

cols = ['PX_VOLUME','TOT_RETURN_INDEX_NET_DVDS'] px_volume_by_day = con.bdh([ticker],cols,sd,ed) px_volume_by_day

Yet the following command (reversing the order of the columns) works - cols = ['TOT_RETURN_INDEX_NET_DVDS','PX_VOLUME'] px_volume_by_day = con.bdh([ticker],cols,sd,ed)

The reported error is ---- Traceback (most recent call last): File "", line 1, in File "c:\Python35\lib\site-packages\pandas\core\base.py", line 82, in repr return str(self) File "c:\Python35\lib\site-packages\pandas\core\base.py", line 61, in str return self.unicode() File "c:\Python35\lib\site-packages\pandas\core\frame.py", line 663, in unicode line_width=width, show_dimensions=show_dimensions) File "c:\Python35\lib\site-packages\pandas\core\frame.py", line 1971, in to_string formatter.to_string() File "c:\Python35\lib\site-packages\pandas\io\formats\format.py", line 648, in to_string strcols = self._to_str_columns() File "c:\Python35\lib\site-packages\pandas\io\formats\format.py", line 539, in _to_str_columns str_columns = self._get_formatted_column_labels(frame) File "c:\Python35\lib\site-packages\pandas\io\formats\format.py", line 782, in _get_formatted_column_labels str_columns = _sparsify(str_columns) File "c:\Python35\lib\site-packages\pandas\core\indexes\multi.py", line 2962, in _sparsify prev = pivoted[start] IndexError: list index out of range

matthewgilbert commented 5 years ago

Please take a look at https://help.github.com/articles/basic-writing-and-formatting-syntax/ for formatting your question. At first glance I cannot reproduce your error

In [4]: import pdblp
   ...: con = pdblp.BCon(port=8194)
   ...: con.start()
   ...: ticker = 'IBM US Equity'
   ...: sd = '20181212'
   ...: ed = '20181217'
   ...: 
   ...: cols = ['TOT_RETURN_INDEX_NET_DVDS','TOT_RETURN_INDEX_GROSS_DVDS']
   ...: px_volume_by_day = con.bdh([ticker], cols, sd, ed)
   ...: 
   ...: 

In [5]: px_volume_by_day
Out[5]: 
ticker                 IBM US Equity                            
field      TOT_RETURN_INDEX_NET_DVDS TOT_RETURN_INDEX_GROSS_DVDS
date                                                            
2018-12-12                    121.16                      121.16
2018-12-13                    120.73                      120.73
2018-12-14                    119.90                      119.90
2018-12-17                    116.90                      116.90