matthewgilbert / blp

Pythonic interface for Bloomberg Open API
Apache License 2.0
112 stars 24 forks source link

Portfolio Data #12

Open nickmik33 opened 2 years ago

nickmik33 commented 2 years ago

How difficult would it be to add in Portfolio Data (PortfolioDataRequest/PortfolioDataResponse)?

In excel, it’s a bds formula, but not with the api.

I’m fairly new to python, but was hopeful this could be a quick edit. Thank you for putting this package together.

rafaelelter commented 2 years ago

The PortfolioDataRequest request type is missing from the _SERVICES dictionary of BlpQuery. Adding it should allow you to make the call you want, although not through the bds() method, which is configured to make calls of the ReferenceDataRequest request type. You would have to use the query() method.

MarekOzana commented 5 months ago

If you're just looking to get the positions of a portfolio, then you can do it using the bql() (no need to implement PortfolioDataRequest in this case)

with blp.BlpQuery() as bq:
    data = bq.bql("get(id().weights) for(Members('PORTF-ID-HERE', type='PORT'))")

Replace 'PORTF-ID-HERE' with your actual portfolio ID. This code will give you the positions in your portfolio.