pdblp icon indicating copy to clipboard operation
pdblp copied to clipboard

Override missing PX_LAST to get last available price

Open youngfella93 opened this issue 4 years ago • 2 comments

Hello guys,

So I am trying to retrieve equity prices from Bloomberg using the pdblp module with the BDH function like this below. For some securities, there are dates for which there is no PX_LAST reported and thus I would like to take the previously available in that case. I am using the syntax below but to no success, I believe it's doable but it's probably a detail that I'm missing in the syntax/wording. Note that without the ovrds=[("Fill","P")] part the code executes successfully.

 pref_px_bbg= con.bdh(CUSIPS,['PX_LAST'],Date2,Date1,ovrds=[("Fill","P")],longdata=True)

I get the following error when I run this line:

 KeyError: 'securityData'

If I change the ovrds= to elms=, I get the following error:

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

Please advice on how to solve this.

Thanks!

youngfella93 avatar Nov 19 '20 06:11 youngfella93

I would get in touch with Bloomberg Help or post to stack overflow with the tag blpapi since this looks like a Bloomberg specific issue as opposed to pdblp issue, which is just a wrapper on top of blpapi.

matthewgilbert avatar Nov 20 '20 13:11 matthewgilbert

Hey

I finally solved my issue by using the xbbg module instead.

By looking at the source code for the pdblp bdh function, I see that there isn't really a parameter meant to capture those additional optional parameters (if I understand it well), could it be the reason why it wasn't able to recognize these commands? Like it isn't really part of the elms nor ovrds which refers to other things when I looked at the API documentation.

    def bdh(self, tickers, flds, start_date, end_date, elms=None,ovrds=None, longdata=False):

where as in the xbbg bdh source code I see a place for other args (in the **kwargs)

  def bdh( tickers, flds=None, start_date=None, end_date='today', adjust=None, **kwargs) -> pd.DataFrame:

which allows me to do something like this:

  pref_px_bbg = blp.bdh(tickers=CUSIPS, flds=['PX_Last'], start_date=Date2, end_date=Date1,Fill='P', Days='A')

That's what I observed, but maybe I am wrong about it..

Thanks!

youngfella93 avatar Nov 20 '20 14:11 youngfella93