Giter Club home page Giter Club logo

pdblp's People

Contributors

euri10 avatar marekozana avatar matthewgilbert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pdblp's Issues

Timeout - Option to override?

Hi Mathew -

Great package, I find your package super useful.

I'm getting a timeout error from calls such as:

con.ref(['X US EQUITY', 'IBM US EQUITY'],['EQY_WEIGHTED_AVG_PX'],[('VWAP_START_DT','20170808'),('VWAP_END_DT','20170808'),('VWAP_START_TIME','11:00:00'),('VWAP_END_TIME','12:00:00')])

Error reads: "RuntimeError: Timeout, increase timeout parameter"

I see you ref timeout in method _parse_ref() ... Is there a simple way for user to override this; I couldn't find one in the docs?

Best,

Noah

override to ref history

Hi
When I try to override ref_hist it errors out when you try to combine overrides with bulk reference data. I think that the overrides are not being combined with the dates.

con.ref_hist(['BAC US EQUITY'] ,['DDIS_AMT_OUTSTANDING'], dates=df1['Quarter'],
             [('DDIS_CURRENCY','USD')] ,date_field="DDIS_HISTORY_OVERRIDE")

Add unit tests

Need to add unit tests to test basic functionality. These will not be able to run with Travis since they require a bloomberg connection however will still be useful for pre commit checks.

Returning Bloomberg blpapi errors.

It would be very useful to be able to use the errors issued by blpapi (e.g., ConnectionError, etc). Is there a way to access these through the API. An example would be very useful.

_create_request function doesn't support list of ovrds for multiple fields?

Hi Matthew,
Thanks for creating this project, and I found it is very helpful. One question that I have is how to do pass in list of ovrds to support multi-fields or same field with multiple version of overrides. For example, to get 2 year weekly beta of GOOG, I used following function:

df = con.ref('GOOG US Equity', 'beta_adj_overridable',
             [('beta_override_rel_index', 'SPX Index'),
              ('beta_override_start_dt', '20160124'),
              ('beta_override_end_dt', '20180124')])

If I want different betas corresponds to different time-frame(like it shows below, one for 2 year beta, the other one for 3 year beta) in the same data frame, does API support such thing?
This is what I tried:

df = con.ref('GOOG US Equity', ['beta_adj_overridable','beta_adj_overridable'],
             [('beta_override_rel_index', 'SPX Index'),
              ('beta_override_start_dt', '20160124'),
              ('beta_override_end_dt', '20180124')],
             [('beta_override_rel_index', 'SPX Index'),
              ('beta_override_start_dt', '20150124'),
              ('beta_override_end_dt', '20180124')]   ). 

Thanks in advance

Currency Override, BBG issus or pdblp?

I'm Trying to download Multiple time series all in the same USD \

for a quick reference I'm going to show SPY US Equity in USD and EUR I think it might be a Bloomberg API issue but can you also check before I go query with them.

con.bdh('SPY US Equity', 'PX_LAST',
                '20150629', '20150630', ovrds=[('Currency', 'USD')])
con.bdh('SPY US Equity', 'PX_LAST',
                '20150629', '20150630', ovrds=[('Currency', 'EUR')])

#Output  USD
DEBUG:root:Sending Request:
 HistoricalDataRequest = {
    securities[] = {
        "SPY US Equity"
    }
    fields[] = {
        "PX_LAST"
    }
    startDate = "20150629"
    endDate = "20150630"
    overrides[] = {
        overrides = {
            fieldId = "Currency"
            value = "USD"
        }
    }
}



DEBUG:root:Message Received:
 HistoricalDataResponse = {
    securityData = {
        security = "SPY US Equity"
        eidData[] = {
        }
        sequenceNumber = 0
        fieldExceptions[] = {
        }
        fieldData[] = {
            fieldData = {
                date = 2015-06-29
                PX_LAST = 205.420000
            }
            fieldData = {
                date = 2015-06-30
                PX_LAST = 205.850000
            }
        }
    }
}

# Output EUR
DEBUG:root:Sending Request:
 HistoricalDataRequest = {
    securities[] = {
        "SPY US Equity"
    }
    fields[] = {
        "PX_LAST"
    }
    startDate = "20150629"
    endDate = "20150630"
    overrides[] = {
        overrides = {
            fieldId = "Currency"
            value = "EUR"
        }
    }
}

DEBUG:root:Message Received:
 HistoricalDataResponse = {
    securityData = {
        security = "SPY US Equity"
        eidData[] = {
        }
        sequenceNumber = 0
        fieldExceptions[] = {
        }
        fieldData[] = {
            fieldData = {
                date = 2015-06-29
                PX_LAST = 205.420000
            }
            fieldData = {
                date = 2015-06-30
                PX_LAST = 205.850000
            }
        }
    }
}

Problem description

I would expect the Values to change as the I change the override currency. I have confirmed that the API works in Excel, but do not have the experience to see why it is not working here.

I'm going to have to pull the currency of the tickers I want and download the FX cross to manually fix, but would be great if you could have a look. This is I think the only BBG python API wrapper that is currently active on github so keep up the excellent work.

Expected Output

To return differen values USD or EUR but just get the same data frame

ticker SPY US Equity
Date value
2015-06-29 205.42
2015-06-30 205.85

Version Information

[paste the output of pdblp.__version__ here below this line]
'0.1.5'

ReferenceDataRequest with various return sizes

Related to #5, when an array of reference data is returned it is ambiguous which values are grouped together

import pdblp

con = pdblp.BCon(debug=True)
con.start()
df = con.ref("BCOM Index", "INDX_MWEIGHT_HIST")
DEBUG:root:Sending Request:
 ReferenceDataRequest = {
    securities[] = {
        "BCOM Index"
    }
    fields[] = {
        "INDX_MWEIGHT_HIST"
    }
    overrides[] = {
    }
}

DEBUG:root:Message Received:
 ReferenceDataResponse = {
    securityData[] = {
        securityData = {
            security = "BCOM Index"
            eidData[] = {
            }
            fieldExceptions[] = {
            }
            sequenceNumber = 0
            fieldData = {
                INDX_MWEIGHT_HIST[] = {
                    INDX_MWEIGHT_HIST = {
                        Index Member = "BON8"
                        Percent Weight = 2.430000
                    }
                    INDX_MWEIGHT_HIST = {
                        Index Member = "C N8"
                        Percent Weight = 6.680000
                    }
                    INDX_MWEIGHT_HIST = {
                        Index Member = "CLN8"
                        Percent Weight = 7.600000
                    }
                [ommitted]
                }
            }
        }
    }
}
df.head()
       ticker                             field value
0  BCOM Index    INDX_MWEIGHT_HIST:Index Member  BON8
1  BCOM Index  INDX_MWEIGHT_HIST:Percent Weight  2.43
2  BCOM Index    INDX_MWEIGHT_HIST:Index Member  C N8
3  BCOM Index  INDX_MWEIGHT_HIST:Percent Weight  6.68
4  BCOM Index    INDX_MWEIGHT_HIST:Index Member  CLN8

Implicitly these are associated in the order they are returned but it would be better to be explicit.

One complication for implementing a coherent interface is that currently both array data and singleton data can be returned from the same call to ref(), e.g.

con.debug = False
con.ref("BCOM Index", ["INDX_MWEIGHT_HIST", "PERCENT_WEIGHT"]).tail()
        ticker                             field value
40  BCOM Index    INDX_MWEIGHT_HIST:Index Member  W N8
41  BCOM Index  INDX_MWEIGHT_HIST:Percent Weight  3.88
42  BCOM Index    INDX_MWEIGHT_HIST:Index Member  XBN8
43  BCOM Index  INDX_MWEIGHT_HIST:Percent Weight  4.23
44  BCOM Index                    PERCENT_WEIGHT   100

Cannot establish connection to Bloomberg API

Code Sample, a copy-pastable example if possible

import pdblp
con = pdblp.BCon(debug=False, port=8194)
con.start()

Problem description

pdblp.pdblp:WARNING:Message Received:
SessionStartupFailure = {
reason = {
source = "Session"
category = "IO_ERROR"
errorCode = 9
description = "Connection failed"
}
}

Expected Output

Want to be able to just get historical data, time series data etc. but first trying to establish connection.

Version Information

I am using desktop version of the API, and have bloomberg terminal on my desktop. Any help would be appreciated

Pure Virtual Method error

Currently there are sporadic pure virtual method called errors when bulkref_hist is called. The general setup looks like

import pdblp
con = pdblp.BCon()
con.sart()
con.bulkref_hist("BCOM Index", "INDX_MWEIGHT_HIST", ["20100201"], date_field="END_DATE_OVERRIDE")

This periodically causes python to terminate with the following message.

pure virtual method called
terminate called without an active exception
Aborted (core dumped)

Unsure what is going on here and determine this is complicated by the fact that this problem appears intermittent.

Missing field error for bulkref

Hi, I have a similar issue to #13, except with con.bulkref - when a field does not exist for a subset of securities I'm trying to query, it throws an error for the entire thing.

test = ['594918BD5 Corp','594918BE3 Corp','88428LAA0 Corp']
bbg = con.bulkref(test, ['INDEX_LIST'])

The query works for the first two securities but not the last, so the whole query fails instead of just returning NaN where appropriate (error reproduced below).

securityData = {
  security = "88428LAA0 Corp"
  eidData[] = {
  }
  fieldExceptions[] = {
  }
  sequenceNumber = 2
  fieldData = {
  }
}
Traceback (most recent call last):

  File "<ipython-input-142-61c895cb719c>", line 1, in <module>
    bbg = con.bulkref(test, ['INDEX_LIST'])

  File "C:\Temp\Jay\Anaconda\envs\py35\lib\site-packages\pdblp\pdblp.py", line 378, in bulkref
    data = self._parse_bulkref(flds)

  File "C:\Temp\Jay\Anaconda\envs\py35\lib\site-packages\pdblp\pdblp.py", line 404, in _parse_bulkref
    if not fieldData.getElement(fld).isArray():

  File "C:\Temp\Jay\Anaconda\envs\py35\lib\site-packages\blpapi\element.py", line 347, in getElement
    _ExceptionUtil.raiseOnError(res[0])

  File "C:\Temp\Jay\Anaconda\envs\py35\lib\site-packages\blpapi\exception.py", line 145, in raiseOnError
    _ExceptionUtil.raiseException(errorCode, description)

  File "C:\Temp\Jay\Anaconda\envs\py35\lib\site-packages\blpapi\exception.py", line 137, in raiseException
    raise errorClass(description, errorCode)

NotFoundException: Attempt to access unavailable sub-element 'INDEX_LIST' of element 'fieldData'. (0x0006000d)

bdib is returning a spurious value

Code Sample, a copy-pastable example if possible

# Your code here, this should be a minimal reproducible example, see 
import pdblp
import pandas
import datetime

con = pdblp.BCon(debug=False, port=8194, timeout=10000)
con.start()
df = con.bdib('IBOXUMAE MKIT Curncy', '2018-12-27T01:00:00', datetime.datetime.today() + datetime.timedelta(hours=15), 'TRADE',  1)[['close']]

This code returns as the last ticker a value that makes no sense. Current market is trading at 67.55 as of 15:43 pm GMT but the query returns as the most recent tick a value from the future at 19.22 GMT and a spread value of 62.

Expected Output

Expected output should include as the most recent tick a timestamp that is less than current time at GMT, not from the future

Version Information

0.1.8

Logging compatibility with user code

Currently the way logging in pdblp is handled, it does not play nice with a user configuring top level logging. The following example illustrates the problematic behavior:

import logging
logger = logging.getLogger()
h = logging.StreamHandler()
formatter = logging.Formatter(
        '%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
        '%Y-%m-%dT%H:%M:%S')
h.setFormatter(formatter)
logger.addHandler(h)
logger.setLevel(logging.DEBUG)

Setting debug=False ignores all logger settings

import pdblp
con = pdblp.BCon(debug=False).start()
con.bdh("SPX Index", "PX_LAST", "20180101", "20180103")
ticker     SPX Index
field        PX_LAST
date                
2018-01-02   2695.81
2018-01-03   2713.06

Setting debug=True when using user defined config settings will ignore these. Note that the user defines here that only CRITICAL level things are logged however this is ignored by pdblp

logger.setLevel(logging.CRITICAL)
con.debug = True
con.bdh("SPX Index", "PX_LAST", "20180101", "20180103")
2018-06-20T17:38:50 root         DEBUG    Sending Request:
 HistoricalDataRequest = {
    securities[] = {
        "SPX Index"
    }
    fields[] = {
        "PX_LAST"
    }
    startDate = "20180101"
    endDate = "20180103"
    overrides[] = {
    }
}

2018-06-20T17:38:51 root         DEBUG    Message Received:
 HistoricalDataResponse = {
    securityData = {
        security = "SPX Index"
        eidData[] = {
        }
        sequenceNumber = 0
        fieldExceptions[] = {
        }
        fieldData[] = {
            fieldData = {
                date = 2018-01-02
                PX_LAST = 2695.810000
            }
            fieldData = {
                date = 2018-01-03
                PX_LAST = 2713.060000
            }
        }
    }
}

ticker     SPX Index
field        PX_LAST
date                
2018-01-02   2695.81
2018-01-03   2713.06

Get dividend fields

Dear Matthew,
thank you for your package. I am trying to use it to get dividend data for the stock.
When I run following code I get an error

con.bdh('CEZ CP Equity', 'DVD_SH_LAST', '20170101', '20170925')

ValueError: Length mismatch: Expected axis has 0 elements, new values have 4 elements

Can you please help me to structure request right?

Thanks,
Anastazie

What is the latest version of python this will work with?

Running into some issues using this with some other code that references packages that are only compatible with python 3.6.

What is the latest version of python that this will work with? And is there any hack if I am working in 3.6 whereby I could get data to run (other than running commands such as os.system('python2.7 etc..')?

Inconsistent behavior when passing list of fields for .ref request

Code Sample

import pdblp

con = pdblp.BCon(debug=True, timeout=10000)
con.start()
test = con.ref(['IS7597250 Index'], ['VEGA_NOTIONAL', 'FIRST_TRADING_DATE'])
con.stop()
print(test)


con = pdblp.BCon(debug=True,timeout=10000)
con.start()
test = con.ref(['IS7597250 Index'], ['FIRST_TRADING_DATE'])
con.stop()
print(test)

Problem description

If I call .ref and pass one field to the request, it works. However, if I pass two fields to the request, the field that originally worked returns nan and the reason seems to be 'Field not applicable'. Since the other request works then the error suggest there might be a typo or syntax issue that is generating a faulty field but the debugger shows that everything is the same. I even changed the order of the fields in the list but the Vega Notional keeps working, while the First Trading Date still fails

pdblp.pdblp:INFO:Sending Request:
ReferenceDataRequest = {
    securities[] = {
        "IS7597250 Index"
    }
    fields[] = {
        "VEGA_NOTIONAL", "FIRST_TRADING_DATE"
    }
    overrides[] = {
    }
}
pdblp.pdblp:INFO:Event Type: 'RESPONSE'
pdblp.pdblp:INFO:Message Received:
ReferenceDataResponse = {
    securityData[] = {
        securityData = {
            security = "IS7597250 Index"
            eidData[] = {
            }
            fieldExceptions[] = {
                fieldExceptions = {
                    fieldId = "FIRST_TRADING_DATE"
                    errorInfo = {
                        source = "65::bbdbl5"
                        code = 9
                        category = "BAD_FLD"
                        message = "Field not applicable to security"
                        subcategory = "NOT_APPLICABLE_TO_REF_DATA"
                    }
                }
            }
            sequenceNumber = 0
            fieldData = {
                VEGA_NOTIONAL = 100000.000000
            }
        }
    }
}
            ticker               field     value
0  IS7597250 Index       VEGA_NOTIONAL  100000.0
1  IS7597250 Index  FIRST_TRADING_DATE       NaN

But if I call only one field, I get the desired result:

pdblp.pdblp:INFO:Sending Request:
ReferenceDataRequest = {
    securities[] = {
        "IS7597250 Index"
    }
    fields[] = {
        "FIRST_TRADING_DATE"
    }
    overrides[] = {
    }
}
pdblp.pdblp:INFO:Event Type: 'RESPONSE'
pdblp.pdblp:INFO:Message Received:
ReferenceDataResponse = {
    securityData[] = {
        securityData = {
            security = "IS7597250 Index"
            eidData[] = {
            }
            fieldExceptions[] = {
            }
            sequenceNumber = 0
            fieldData = {
                FIRST_TRADING_DATE = "01/23/2019 16:48"
            }
        }
    }
}

I still don't discard a syntax error, but it must be very subtle

Version Information

0.1.8

Another BDH Override Returning Error

Hi Matthew,

First of all, thank you for developing this package - I find it very useful. I am trying to override the standard bdh formula to return all working days (or all calendar days) by using the fields from the Bloomberg Open API - Core Developer Guide on page 93:

df = con.bdh("IBM US Equity", "PX_LAST", "20150101", "20150630", ovrds=[("nonTradingDayFillOption", "ALL_CALENDAR_DAYS"), ("nonTradingDayFillMethod", "NIL_VALUE")])

Unfortunately this override is returning an error message:

DEBUG:root:Sending Request:
 HistoricalDataRequest = {
    securities[] = {
        "IBM US Equity"
    }
    fields[] = {
        "PX_LAST"
    }
    startDate = "20150101"
    endDate = "20150630"
    overrides[] = {
        overrides = {
            fieldId = "nonTradingDayFillOption"
            value = "ALL_CALENDAR_DAYS"
        }
        overrides = {
            fieldId = "nonTradingDayFillMethod"
            value = "NIL_VALUE"
        }
    }
}
DEBUG:root:Message Received:
 HistoricalDataResponse = {
    responseError = {
        source = "bbdbh7"
        code = 27
        category = "BAD_ARGS"
        message = "Invalid override field id specified [nid:3626] "
        subcategory = "INVALID_OVERRIDE_FIELD"
    }
}
Traceback (most recent call last):
  File "<input>", line 2, in <module>
  File "C:\Users\nelly\Anaconda3\Lib\site-packages\pdblp\pdblp.py", line 165, in bdh
    elms, ovrds)
  File "C:\Users\nelly\Anaconda3\Lib\site-packages\pdblp\pdblp.py", line 202, in _bdh_list
    if msg.getElement('securityData').hasElement('securityError') or (msg.getElement('securityData').getElement("fieldExceptions").numValues() > 0):  # NOQA
  File "C:\Users\nelly\Anaconda3\Lib\site-packages\blpapi\message.py", line 135, in getElement
    return self.asElement().getElement(name)
  File "C:\Users\nelly\Anaconda3\Lib\site-packages\blpapi\element.py", line 347, in getElement
    _ExceptionUtil.raiseOnError(res[0])
  File "C:\Users\nelly\Anaconda3\Lib\site-packages\blpapi\exception.py", line 145, in raiseOnError
    _ExceptionUtil.raiseException(errorCode, description)
  File "C:\Users\nelly\Anaconda3\Lib\site-packages\blpapi\exception.py", line 137, in raiseException
    raise errorClass(description, errorCode)
blpapi.exception.InvalidArgumentException: Choice sub-element not found for name 'securityData'. (0x00020002)

Any idea how to make it work?

bloomberg logout issue

Hi there. I've been having issues using pdblp after being automatically logged out from bloomberg (main terminal). I often need to manually log back in in order to get pdblp to work. Is it possible to initiate a logon from pdblp?

Remove unecessary restart() method

Previously is was thought that blpapi.CorrelationIds need to be unique to a blpapi.Session, however this is not true.

When subscribing or requesting information an application has
the choice of providing a CorrelationId they construct
themselves or allowing the session to construct one for
them. If the application supplies a CorrelationId it must not
re-use the value contained in it in another CorrelationId
whilst the original request or subscription is still active.

An example shows this

import blpapi
import time

session = blpapi.Session()
session.start()
session.openService("//blp/refdata")
service = session.getService("//blp/refdata")

cid = blpapi.CorrelationId(1)

request = service.createRequest("ReferenceDataRequest")
request.getElement("securities").appendValue("IBM US Equity")
request.getElement("fields").appendValue("PX_LAST")

# same cid provided orginal request is not active is fine
session.sendRequest(request, correlationId=cid)
time.sleep(2)
session.sendRequest(request, correlationId=cid)

# same cid immediately causes errors
session.sendRequest(request, correlationId=cid)
session.sendRequest(request, correlationId=cid)

DuplicateCorrelationIdException: Duplicate correlation id: [ valueType=INT classId=0 value=1 ] (0x00020005)

The restart() method was provided as a hack to avoid managing correlationIds throughout the lifetime of a session. As shown above, this is unnecessary and has several limitations, particularly is we desire to extend the functionality such that the user can pass in a custom session directly.

NotFoundException when a field is missing

I am trying to produce chart of z-spread against next call / maturity for a list of all outstanding Contingent Convertible bonds. This requires to get MATURITY and /or NXT_CALL_DT fields for a list of bonds (where I do not know beforehand which bond has missing which field).
The problem is that pdblp.ref() raises exception whenever a field does not exist for given security (e.g. MATURITY for perpetual bond).
Example (3 bonds, the first having both fields, the second missing MATURITY and the last missing NXT_CALL_DT):

tickers = ["EJ8189684 Corp", "EI862261 Corp", "EJ319090 Corp"]
fields = ["MATURITY", "NXT_CALL_DT"]
df = con.ref(tickers, fields)

raises
NotFoundException: Attempt to access unavailable sub-element 'MATURITY' of element 'fieldData'. (0x0006000d)

Shouldn't pdblp.ref just ignore missing field (or return NaN)? This is exactly what Excel or Rbplapi are doing:

bdp(securities=c("EJ8189684 Corp", "EI862261 Corp", "EJ319090 Corp"), 
        fields=c("MATURITY", "NXT_CALL_DT"))
                 MATURITY NXT_CALL_DT
EJ8189684 Corp 2025-09-18  2020-09-18
EI862261 Corp        <NA>  2017-06-29
EJ319090 Corp  2022-08-17        <NA>

For reference. See below the debug printout:

DEBUG:root:Sending Request:
 ReferenceDataRequest = {
    securities[] = {
        "EJ8189684 Corp", "EI862261 Corp", "EJ319090 Corp"
    }
    fields[] = {
        "MATURITY", "NXT_CALL_DT"
    }
    overrides[] = {
    }
}
DEBUG:root:Message Received:
 ReferenceDataResponse = {
    securityData[] = {
        securityData = {
            security = "EJ8189684 Corp"
            eidData[] = {
            }
            fieldExceptions[] = {
            }
            sequenceNumber = 0
            fieldData = {
                MATURITY = 2025-09-18
                NXT_CALL_DT = 2020-09-18
            }
        }
        securityData = {
            security = "EI862261 Corp"
            eidData[] = {
            }
            fieldExceptions[] = {
                fieldExceptions = {
                    fieldId = "MATURITY"
                    errorInfo = {
                        source = "144::bbdbd4"
                        code = 9
                        category = "BAD_FLD"
                        message = "Field not applicable to security"
                        subcategory = "NOT_APPLICABLE_TO_REF_DATA"
                    }
                }
            }
            sequenceNumber = 1
            fieldData = {
                NXT_CALL_DT = 2017-06-29
            }
        }
        securityData = {
            security = "EJ319090 Corp"
            eidData[] = {
            }
            fieldExceptions[] = {
                fieldExceptions = {
                    fieldId = "NXT_CALL_DT"
                    errorInfo = {
                        source = "144::bbdbd4"
                        code = 9
                        category = "BAD_FLD"
                        message = "Field not applicable to security"
                        subcategory = "NOT_APPLICABLE_TO_REF_DATA"
                    }
                }
            }
            sequenceNumber = 2
            fieldData = {
                MATURITY = 2022-08-17
            }
        }
    }
}

Note that the issue is related to #6 but not the same. The problem is not that we are naming columns of an empty DataFrame like in issue #6 .

Not really issue, more just question about FILL=P and Days=A overrides

Hi Mathew -

I could not find in your tutorial how to override for fill=p (which is a standard override of most bbg fields, to allow for backfilling to the prev value). Days=A also is an override that allows you to force showing every actual day (i.e. not hiding weekends).

I notice the following overrides are not recognized:

con.bdh('GBPUSD Curncy', ['PX_LAST'],'20080101', '20180703',ovrds=[('FILL','P')])
con.bdh('GBPUSD Curncy', ['PX_LAST'],'20080101', '20180703',ovrds=[('DAYS','A')])

con = pdblp.BCon(debug=True, port=8194)
con.start()

13JUL2018_11:50:39.410 14824:9772 WARN blpapi_platformcontroller.cpp:347 blpapi.session.platformcontroller.{4} Connectiv
ity restored.

con.bdh('GBPUSD Curncy', ['PX_LAST'],'20080101', '20180703',ovrds=[('FILL','P')])
DEBUG:root:Sending Request:
HistoricalDataRequest = {
securities[] = {
"GBPUSD Curncy"
}
fields[] = {
"PX_LAST"
}
startDate = "20080101"
endDate = "20180703"
overrides[] = {
overrides = {
fieldId = "FILL"
value = "P"
}
}
}

DEBUG:root:Message Received:
HistoricalDataResponse = {
responseError = {
source = "bbdbh3"
code = 27
category = "BAD_ARGS"
message = "Invalid override field id specified [nid:65] "
subcategory = "INVALID_OVERRIDE_FIELD"
}
}

Traceback (most recent call last):
File "", line 1, in
File "C:\Python35\lib\site-packages\pdblp\pdblp.py", line 165, in bdh
elms, ovrds)
File "C:\Python35\lib\site-packages\pdblp\pdblp.py", line 201, in _bdh_list
has_security_error = (msg.getElement('securityData')
File "C:\Python35\lib\site-packages\blpapi\message.py", line 127, in getElement
return self.asElement().getElement(name)
File "C:\Python35\lib\site-packages\blpapi\element.py", line 347, in getElement
_ExceptionUtil.raiseOnError(res[0])
File "C:\Python35\lib\site-packages\blpapi\exception.py", line 145, in raiseOnError
_ExceptionUtil.raiseException(errorCode, description)
File "C:\Python35\lib\site-packages\blpapi\exception.py", line 137, in raiseException
raise errorClass(description, errorCode)
blpapi.exception.InvalidArgumentException: Choice sub-element not found for name 'securityData'. (0x00020002)

con.bdh('GBPUSD Curncy', ['PX_LAST'],'20080101', '20180703',ovrds=[('DAYS','A')])
DEBUG:root:Sending Request:
HistoricalDataRequest = {
securities[] = {
"GBPUSD Curncy"
}
fields[] = {
"PX_LAST"
}
startDate = "20080101"
endDate = "20180703"
overrides[] = {
overrides = {
fieldId = "DAYS"
value = "A"
}
}
}

DEBUG:root:Message Received:
HistoricalDataResponse = {
responseError = {
source = "bbdbh2"
code = 27
category = "BAD_ARGS"
message = "Invalid override field id specified [nid:65] "
subcategory = "INVALID_OVERRIDE_FIELD"
}
}

Traceback (most recent call last):
File "", line 1, in
File "C:\Python35\lib\site-packages\pdblp\pdblp.py", line 165, in bdh
elms, ovrds)
File "C:\Python35\lib\site-packages\pdblp\pdblp.py", line 201, in _bdh_list
has_security_error = (msg.getElement('securityData')
File "C:\Python35\lib\site-packages\blpapi\message.py", line 127, in getElement
return self.asElement().getElement(name)
File "C:\Python35\lib\site-packages\blpapi\element.py", line 347, in getElement
_ExceptionUtil.raiseOnError(res[0])
File "C:\Python35\lib\site-packages\blpapi\exception.py", line 145, in raiseOnError
_ExceptionUtil.raiseException(errorCode, description)
File "C:\Python35\lib\site-packages\blpapi\exception.py", line 137, in raiseException
raise errorClass(description, errorCode)
blpapi.exception.InvalidArgumentException: Choice sub-element not found for name 'securityData'. (0x00020002)

Maybe there is something strange about these generic overrides though? When you look under FLDS in bloomberg, they are not listed as an override, but they generically work with any field when I pull in Excel.

Let me know if i have specified the syntax incorrectly.

Best!

Add security lookup (SECF) requests

Implementation of the terminal function "SECF" which allows query based lookup of tickers using a search string. This leverages the "instruments" service using the InstrumentListRequest request type.

I can go ahead and open a PR of my implementation of the function, which can be located here

This is quite similar to the request from @dcragusa in issue #45. I've gone ahead and kept consistent by using the same naming convention for opening the related service - self.instrService

list index out of range

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

Error Handling

Hey.

I am doing a program to fetch data from bloomberg. I read a csv file that contains tickers. If a ticker is invalid, how can i do the error handling.

For example USBX@ is not a valid security my code is the following:

con = pdblp.BCon(debug=False, port=8194)
con.start()
try:
    x = con.bdh('USBX@ Curncy', 'PX_BID', '20180509','20180509')
except ValueError:
    print("ERROR")

for example if I run it on Pycharm I get the following string of exceptions. In this I can check that there is an invalid security, but how can I get the subcategory error immediately from try except using ValueError or NameError

Traceback (most recent call last):
  File "C:/Users/hwuhu/PycharmProjects/PRUEBA/PRUEBBA.py", line 22, in <module>
    x = con.bdh('USBX@ Curncy', 'PX_BID', '20180509','20180509')
  File "c:\users\hwuhu\pdblp\pdblp\pdblp.py", line 165, in bdh
    elms, ovrds)
  File "c:\users\hwuhu\pdblp\pdblp\pdblp.py", line 203, in _bdh_list
    raise Exception(msg)
Exception: HistoricalDataResponse = {
    securityData = {
        security = "USBX@ Curncy"
        eidData[] = {
        }
        sequenceNumber = 0
        securityError = {
            source = "4013::bbdbh5"
            code = 15
            category = "BAD_SEC"
            message = "Unknown/Invalid securityInvalid Security [nid:4013] "
            subcategory = "INVALID_SECURITY"
        }
        fieldExceptions[] = {
        }
        fieldData[] = {
        }
    }
}

Add government lookup requests

A function that returns a list of tickers corresponding to a generic govt. security such as 'T Govt'.

I don't feel comfortable opening a pull request due to so many style changes, but an implementation can be found in my fork here.

Question regarding pulling bds like functionality

Hey,

If I have a request to pull the historical composition of a dataset, say:

X = con.ref('TPX500 Index','INDX_MWEIGHT_HIST', [('END_DT','19991231'),])

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\...\Python27\site-packages\pdblp\pdblp.py", line 242, in ref
    ovrds, [])
  File "C:\...\Python27\site-packages\pdblp\pdblp.py", line 116, in _create_req
    request = self.refDataService.createRequest(rtype)
AttributeError: 'BCon' object has no attribute 'refDataService'

Any help?? Not sure what's going on!

pulling field for multiple tickers returns results for only 4 tickers

con = pdblp.BCon(debug=False, port=8194)
con.start()

ticker_list = [lots of tickers]
sd = datetime.datetime(2016, 1, 1, 0,0,0,0).strftime('%Y%m%d')
ed = str(datetime.datetime.today().strftime('%Y%m%d'))
cols = ['PX_VOLUME']
df = con.bdh( tickers, cols,sd,ed) 

Originally i tried pulling for say 100 or more tickers... However, when I paired it down to just 5 tickers, the result set still only returns results for the first 4 tickers in the list.

Am I supposed to override anything, like timeout or call some other function if i am requesting field(s) for an entire portfolio?

returns bulk reference data which is not supported

Code Sample, a copy-pastable example if possible

output = dict()
con = pdblp.BCon(debug=False, port=8194, timeout=gbl_to)
con.start()
expiry_us = con.ref('SPX Index', 'CHAIN_TICKERS', ovrds=[('CHAIN_EXP_DT_OVRD', '1f-9f')])

Problem description

I've used this code before without a problem. However I recently had to uninstall and reinstall my entire Python setup and now when I run my code I get :

Traceback (most recent call last):

File "", line 1, in
runfile('C:/Users/GFloresGonzalez/Documents/Projects/Cap Arb/capArb-runner.py', wdir='C:/Users/GFloresGonzalez/Documents/Projects/Cap Arb')

File "C:\Users\GFloresGonzalez\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 704, in runfile
execfile(filename, namespace)

File "C:\Users\GFloresGonzalez\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/GFloresGonzalez/Documents/Projects/Cap Arb/capArb-runner.py", line 21, in
main()

File "C:\Users\GFloresGonzalez\Documents\Projects\Cap Arb\capArb\option_Generator.py", line 25, in main
option_prices['EU'], mkt_eu = run_option_pricer('EU', tickers['EU'])

File "C:\Users\GFloresGonzalez\Documents\Projects\Cap Arb\capArb\SocGen.py", line 781, in run_option_pricer
mkt_data = get_market_data()

File "C:\Users\GFloresGonzalez\Documents\Projects\Cap Arb\capArb\SocGen.py", line 232, in get_market_data
expiry_us = con.ref('SPX Index', 'CHAIN_TICKERS', ovrds=[('CHAIN_EXP_DT_OVRD', '1f-9f')])

File "C:\Users\GFloresGonzalez\AppData\Local\Continuum\anaconda3\lib\site-packages\pdblp\pdblp.py", line 364, in ref
data = self._parse_ref(flds)

File "C:\Users\GFloresGonzalez\AppData\Local\Continuum\anaconda3\lib\site-packages\pdblp\pdblp.py", line 391, in _parse_ref
.format(fld))

ValueError: Field 'CHAIN_TICKERS' returns bulk reference data which is not supported

Version Information

Version: 0.1.8

Increasing BCon.timeout attribute for Historical Index Composition

Hey!

Great work on the API - using it lots and it's doing a jolly good job.

I'm running into an issue where when I use the following:

X = con.ref('RAY Index','INDX_MWEIGHT_HIST', [('END_DT','19991231'),])

I end up facing the error:

raise RuntimeError("Timeout, increase BCon.timeout attribute")
RuntimeError: Timeout, increase BCon.timeout attribute

How can I manually hack the override in relation to this function call?

ExcelGetGridRequest Response Element Inconsistent with Schema

Data returned from making a ExcelGetGridRequest seems inconsistent with schema. An element is a blpapi.DataType.CHOICE however element.getChoice() raises an error. This is illustrated below.

import blpapi


def get_messages(session):
    msgs = []
    while True:
        ev = session.nextEvent(2000)
        if ev.eventType() == blpapi.Event.TIMEOUT:
            break
        for msg in ev:
            msgs.append(msg)
    return msgs


session = blpapi.Session()
session.start()
session.openService('//blp/exrsvc')
exrService = session.getService('//blp/exrsvc')
request = exrService.createRequest('ExcelGetGridRequest')
request.set('Domain', "COMDTY:VESSEL")
session.sendRequest(request)

grid_msg = get_messages(session)[-1]

print("blpapi.DataType.CHOICE: %s" % blpapi.DataType.CHOICE)
print("Data Type: %s" % grid_msg.asElement().getElement('DataRecords').getValue(0).getElement('DataFields').datatype())
print(grid_msg.asElement().getElement('DataRecords').getValue(0).getElement('DataFields'))
blpapi.DataType.CHOICE: 16
Data Type: 16
DataFields[] = {
    DataFields = {
        StringValue = "IMO9843247 Index"
    }
    DataFields = {
        StringValue = "IHC HOLLAND CO01298"
    }
}
grid_msg.asElement().getElement('DataRecords').getValue(0).getElement('DataFields').getChoice()
---------------------------------------------------------------------------
UnknownErrorException                     Traceback (most recent call last)
<ipython-input-8-b7718a80ff5f> in <module>()
----> 1 grid_msg.asElement().getElement('DataRecords').getValue(0).getElement('DataFields').getChoice()

~/anaconda3/lib/python3.6/site-packages/blpapi/element.py in getChoice(self)
    392         self.__assertIsValid()
    393         res = internals.blpapi_Element_getChoice(self.__handle)
--> 394         _ExceptionUtil.raiseOnError(res[0])
    395         return Element(res[1], self._getDataHolder())
    396 

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

~/anaconda3/lib/python3.6/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

UnknownErrorException: Attempt to getChoice on non-choice element 'DataFields' (0x00000003)

Wrong order of the tickers in the request answers

Hi

This is the example I use to show the problem in my case. The order of the column in DF is not the same than the order of the ticker.

I think it is a big issue when it happens. I do not know from where it comes.

StartYear = 2015
s = "USSWAP"
ticker = [s+ str(x+1)+" Comdty" for x in range(10)]
DF =  con.bdh(ticker, "PX_LAST", datetime.datetime(StartYear, 1,1).strftime("%Y%m%d"), datetime.datetime.now().strftime("%Y%m%d")) 

Error accessing Null scalar blpapi.element.Element

Tried to pull out some historical dividend data through ref() and 'DVD_HIST', but encountered the error "IndexOutOfRangeException".

I did a check on the Bloomberg terminal, there is an empty "payable date" in one of the dividends being pulled out which might cause this issues. Is there a workaround to this "IndexOutOfRangeException" issue?

This codes works perfectly fine

tickers = ['101 HK EQUITY']
flds = ['DVD_HIST']
dates = ['19900430']
ovrds = [ ('DVD_END_DT', '20000430')]
A = con.ref_hist(tickers, flds, dates, date_field='DVD_START_DT', ovrds=ovrds)

But if I change the starting date to include the dividend with the empty "payable date" as follow:

tickers = ['101 HK EQUITY']
flds = ['DVD_HIST']
dates = ['19800430']
ovrds = [ ('DVD_END_DT', '20000430')]
A = con.ref_hist(tickers, flds, dates, date_field='DVD_START_DT', ovrds=ovrds)

I got the error message:

Traceback (most recent call last):

  File "<ipython-input-5-47a18076be67>", line 5, in <module>
    A = con.ref_hist(tickers, flds, dates, date_field='DVD_START_DT', ovrds=ovrds)

  File "C:\Users\otrade\Anaconda3\envs\BloombergAPI\lib\site-packages\pdblp\pdblp.py", line 370, in ref_hist
    timeout=timeout)

  File "C:\Users\otrade\Anaconda3\envs\BloombergAPI\lib\site-packages\pdblp\pdblp.py", line 285, in _parse_ref
    dataj = [ticker, mfld, elm.getValue()]

  File "C:\Users\otrade\Anaconda3\Lib\site-packages\blpapi\element.py", line 505, in getValue
    return valueGetter(self, index)

  File "C:\Users\otrade\Anaconda3\Lib\site-packages\blpapi\element.py", line 436, in getValueAsDatetime
    _ExceptionUtil.raiseOnError(res[0])

  File "C:\Users\otrade\Anaconda3\Lib\site-packages\blpapi\exception.py", line 145, in raiseOnError
    _ExceptionUtil.raiseException(errorCode, description)

  File "C:\Users\otrade\Anaconda3\Lib\site-packages\blpapi\exception.py", line 137, in raiseException
    raise errorClass(description, errorCode)

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

Thanks

BDH with multiple start and end dates

I'm looking to pull a time series of prices for a vector of securities, but I would like to specify different start and end dates for each security. Is that possible with BDH?

I tried something like this but obviously it didn't work -
con.bdh(['VIX Index', 'UX1 Index'], ['PX_LAST'], ['20170101', '20170201'],['20170831','20171031'])

BDH Override Returning Error

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.

raise ConnectionError("Could not start a blpapi.session")

I have installed pdblp
pip install -e pdblp
I am on Ubuntu 16.04
My code

import pdblp
con = pdblp.BCon(debug=True, port=8194)
con.start()
con.bdh('SPY US Equity', 'PX_LAST','20150629', '20150630')

I got

python t15.py

08JAN2018_11:28:53.155 12856:140190920144640 WARN blpapi_platformtransporttcp.cpp:137 blpapi.session.transporttcp.{1}.localhost:8194 127.0.0.1:8194, session pool state=Failed

08JAN2018_11:28:53.155 12856:140190920144640 WARN blpapi_platformcontroller.cpp:508 blpapi.session.platformcontroller.{1} Platform failed 1 consecutive connect attempts, stopped trying to reconnect. { PlatformId=0 }
INFO:root:Failed to start session.
Traceback (most recent call last):
File "t15.py", line 4, in
con.start()
File "/home/milenko/pdblp/pdblp/pdblp.py", line 81, in start
raise ConnectionError("Could not start a blpapi.session")
ConnectionError: Could not start a blpapi.session

Why?

bdib data not consistent with starting time

I create a query to fetch intraday hourly data for VIX. The first day data is fetch properly, at the 0 minutes mark, but when the next day comes the timestamp shifts to the 15 minutes mark.

This is the actual code I'm running:

import pdblp
con = pdblp.BCon(debug=True, port=8194)
con.start()
VIX = con.bdib('VIX Index', '2017-12-13T14:00:00', '2018-01-24T21:00:00','TRADE',60) 
VIX.index = VIX.index.tz_localize('UTC',).tz_convert('US/Eastern').tz_localize(None)
VIX.head(20)

The output can be verified with

VIX.head(20)

Clumsy start and stop

Matthew, you can use the contextmanager to make the construction of your connectivity a lot more slick, e.g. with

import pdblp
from contextlib import contextmanager


@contextmanager
def b_berg(debug=False):
    con = pdblp.BCon(debug=debug)
    con.start()
    try:
        yield con
    finally:
        con.stop()

you can now use

        with b_berg(debug=False) as bb:
            return bb.ref(tickers, fields, ovrds=ovrds)

Please update

Adding a limit to brsch

Hi,

Thanks a lot for your work, I use this project a lot and really like it!
I currently started using the bsrch function and it seems it uses the standard limit of 5,000 results. In excel you can get up to 20,000 results with this function:
=BSRCH("FI:BONDS","LIMIT=20000")
Would it be possible to add this limit as well? I am fairly new to python, so struggling a bit programming it myself.

Thanks,
Tobias

bdh() gives value error when no data is returned

import pdblp

con =pdblp.BCon(debug=False, port=8194)
con.start()

df = con.bdh(tickers=['AAPL US Equity', '1437355D US Equity', '1630887D US Equity'],
             flds=['PX_LAST'],
             start_date='19970101',
             end_date='20180511',
             elms = [('nonTradingDayFillMethod','PREVIOUS_VALUE'),('nonTradingDayFillOption','ALL_CALENDAR_DAYS')],
             ovrds=[],
             longdata=True)
# Your code here, this should be a minimal reproducible example, see https://stackoverflow.com/help/mcve
import pdblp

con =pdblp.BCon(debug=False, port=8194)
con.start()

# historical:
df = con.bdh(tickers=['1437355D US Equity', '1630887D US Equity'],
             flds=['PX_LAST'],
             start_date='19970101',
             end_date='20180511',
             elms = [('nonTradingDayFillMethod','PREVIOUS_VALUE'),('nonTradingDayFillOption','ALL_CALENDAR_DAYS')],
             ovrds=[],
             longdata=True)

Problem description

Pulling prices for the bloomberg tickers in the example (when including an active stock AAPL US Equity) yields a dataframe as expected. However when removing AAPL US Equity from the list and rerunning I get the error below. These two tickers are delisted and in this case they do not have any data. Is it not possible to return an empty dataframe instead of the error in this case?
Great library though, thanks.

Expected Output

Empty dataframe

Version Information

pdblp==0.1.5

Output

05JUL2018_17:58:49.698 4188:5996 WARN blpapi_platformcontroller.cpp:347 blpapi.session.platformcontroller.{1} Connectivity restored. 
Traceback (most recent call last):
  File "C:/repos/de_003/scratchpad_bloomberg_api_raw.py", line 40, in <module>
    longdata=True)
  File "C:\venv\de_003\lib\site-packages\pdblp\pdblp.py", line 168, in bdh
    df.columns = ["date", "ticker", "field", "value"]
  File "C:\venv\de_003\lib\site-packages\pandas\core\generic.py", line 4385, in __setattr__
    return object.__setattr__(self, name, value)
  File "pandas\_libs\properties.pyx", line 69, in pandas._libs.properties.AxisProperty.__set__
  File "C:\venv\de_003\lib\site-packages\pandas\core\generic.py", line 645, in _set_axis
    self._data.set_axis(axis, labels)
  File "C:\venv\de_003\lib\site-packages\pandas\core\internals.py", line 3323, in set_axis
    'values have {new} elements'.format(old=old_len, new=new_len))
ValueError: Length mismatch: Expected axis has 0 elements, new values have 4 elements

Column misalignment

Bug when pulling multiple columns where data is not available for every time period, results in column misalignment. Code below shows example of problem

con = pdblp.BCon(debug=True)
con.start()
tickers = ["ACTUAL_RELEASE", "BN_SURVEY_MEDIAN", "FIRST_REVISION",
           "FIRST_REVISION DATE", "ECO_RELEASE_DT"]
con.bdh("GDP CQOQ Index", tickers, "20140410", "20160210")

column_bug

BDS type of call

Hey Guys,

If I want to do a BDS type of call, say:

=BDS("SPX Index","INDX_MWEIGHT_HIST", "END_DATE_OVERRIDE=20151231")

I assume it's along the lines of:

con.ref(["SPX Index"],"INDX_MWEIGHT_HIST", [("END_DATE_OVERRIDE","20150715")])

But this seems to throw up:
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "...\Python27\site-packages\pdblp\pdblp.py", line 242, in ref
    ovrds, [])
  File "...\Python27\site-packages\pdblp\pdblp.py", line 125, in _create_req
    for ovrd_fld, ovrd_val in ovrds:
ValueError: need more than 1 value to unpack

Know what's going on?

bsrch() function

I am big fan of your package, it significantly simplifies my work. Thanks!
The only thing I am missing is BSRCH() function which allows one to pull the results of saved bond search (SRCH <GO>).
I did fast and dirty modification of your pdblp.py on my clone. Basically I just added new service to start():

       if not self.session.openService("//blp/exrsvc"):
            logging.error("Failed to open //blp/exrsvc")
            raise ConnectionError("Could not open a //blp/exrsvc service")
        # Obtain previously opened service
        self.exrService = self.session.getService("//blp/exrsvc")

and then implemented bsrch(domain):

    def bsrch(self, domain):
        """This function uses the Bloomberg API to retrieve 'bsrch'
        (Bloomberg SRCH Data) queries. Returns list of tickers.

        Parameters
        ----------
        domain: string
        A character string with the name of the domain to execute.
        It can be a user defined SRCH screen, commodity screen or
        one of the variety of Bloomberg examples. All domains are in the format 
        <domain>:<search_name>. Example "COMDTY:NGFLOW"
        Returns
        -------
        data: list(string) 
        List of bloomberg tickers from the BSRCH
        """
        request = self.exrService.createRequest("ExcelGetGridRequest")
        request.set("Domain", domain)
        self.session.sendRequest(request)
        data = []
        # Process received events
        while True:
            # We provide timeout to give the chance for Ctrl+C handling:
            event = self.session.nextEvent(0)
            if event.eventType() == blpapi.Event.RESPONSE or \
               event.eventType() == blpapi.Event.PARTIAL_RESPONSE:
                for msg in event:
                    logging.debug(msg)
                    for v in msg.getElement("DataRecords").values():
                        for f in v.getElement("DataFields").values():
                            data.append(f.getElementAsString("StringValue"))
            if event.eventType() == blpapi.Event.RESPONSE:
                break
        return pd.DataFrame(data)

Would you be interested to add implementation of bsrch to your code?
Thanks for your time!
Marek

Return numpy nan value if does not exist

I usually get this error;
ValueError: Length mismatch: Expected axis has 0 elements, new values have 3 elements

when the value does not exist. Why not just return np.nan?

Unknown security from a list of valid securities

I'm querying ten tickers using
con.ref(_tickers, "PX_MID")
However, one of them refers to an option whose strike is so large that there is no trading and thus, there is no such ticker in bloomberg.
The way pdblp works is that if I query 9 valid tickers and one invalid ticker then my entire execution stops. How can I handle the code such that execution continues? Is is possible to just ignore the invalid ticker?

how to retrieve the not adjust price data ?

Hi , I have a question : how to retrieve the not adjust price data,
I found the parameters that are 'CshAdjAbnormal', 'CapChg', 'CshAdjNormal'.

So I try like this:

con = pb.BCon(port=8194, timeout=5000)
con.start()

fields = ['HIGH', 'OPEN', 'LOW', 'VOLUME', 'PX_LAST']
start = '20181101'
end = '20181201'

df = con.bdh("MSFT US Equity",fields,
start,
end,
ovrds=[('CshAdjAbnormal', False),
('CapChg', False),
('CshAdjNormal', False)])

But it's error:


InvalidArgumentException Traceback (most recent call last)
in ()
8 ovrds=[('CshAdjAbnormal', False),
9 ('CapChg', False),
---> 10 ('CshAdjNormal', False)])

C:\ProgramData\Anaconda3\lib\site-packages\pdblp\pdblp.py in bdh(self, tickers, flds, start_date, end_date, elms, ovrds, longdata)
259
260 data = self._bdh_list(tickers, flds, start_date, end_date,
--> 261 elms, ovrds)
262
263 df = pd.DataFrame(data, columns=["date", "ticker", "field", "value"])

C:\ProgramData\Anaconda3\lib\site-packages\pdblp\pdblp.py in _bdh_list(self, tickers, flds, start_date, end_date, elms, ovrds)
290 # Process received events
291 for msg in self._receive_events():
--> 292 has_security_error = (msg.getElement('securityData')
293 .hasElement('securityError'))
294 has_field_exception = (msg.getElement('securityData')

C:\ProgramData\Anaconda3\lib\site-packages\blpapi\message.py in getElement(self, name)
171 def getElement(self, name):
172 """Equivalent to asElement().getElement(name)."""
--> 173 return self.asElement().getElement(name)
174
175 def getElementAsBool(self, name):

C:\ProgramData\Anaconda3\lib\site-packages\blpapi\element.py in getElement(self, nameOrIndex)
345 name[0],
346 name[1])
--> 347 _ExceptionUtil.raiseOnError(res[0])
348 return Element(res[1], self._getDataHolder())
349 self.__assertIsValid()

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

C:\ProgramData\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

InvalidArgumentException: Choice sub-element not found for name 'securityData'. (0x00020002)

what should I do?
Thank you !

blpapi.Event attribute throwing error

I am running python 3.6 on windows and have successfully installed blpapi, but am getting the below when trying to import pdblp (importing blpapi works fine)

>>> import blpapi
>>> import pdblp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\pdblp\__init__.py", line 1, in <module>
    from .pdblp import BCon  # NOQA
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\pdblp\pdblp.py", line 8, in <module>
    _RESPONSE_TYPES = [blpapi.Event.RESPONSE, blpapi.Event.PARTIAL_RESPONSE]
AttributeError: module 'blpapi' has no attribute 'Event'

Version Information

pdblp 0.1.7

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.