matthewgilbert / pdblp

pandas wrapper for Bloomberg Open API
MIT License
240 stars 69 forks source link

Override missing PX_LAST to get last available price #90

Open youngfella93 opened 3 years ago

youngfella93 commented 3 years ago

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!

matthewgilbert commented 3 years ago

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.

youngfella93 commented 3 years ago

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!