matthewgilbert / pdblp

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

Update pdblp.py #8

Closed Robuko closed 7 years ago

Robuko commented 7 years ago

@matthewgilbert added a function to create dataframe from a portfolio

The developers guide says that

The BDS() function requests bulk reference data for a single security and bulk field. In the API, there is no difference in the request type and options for reference data and bulk reference data (the field dictates if it is bulk). The difference between the two lies in parsing the response—bulk data responses are returned in a different format.

This is not quite the case, a portfolio data request requires a different request type.

The added function bdsp(self, tickers, flds=[], ovrds=[]) will return a BDS style dataframe for a portfolio. Usage is the same as ref.

df = con.bdsp(portfolio , field )

Where portfolio = 'portfolioID Client' and field is from PORTFOLIO_ASSET_CLASS The type of assets held within a user's custom portfolio. PORTFOLIO_BASE_CURRENCY The currency in which a user's custom portfolio is denominated. PORTFOLIO_BENCHMARK The name of the security, index, or custom portfolio used as the benchmark associated with a user's portfolio. PORTFOLIO_DATA The list of the identifiers, positions, market values, cost, cost date, and cost foreign exchange rate of each security in a user's custom portfolio. PORTFOLIO_MEMBERS The list of identifiers for the members of a user's custom portfolio. PORTFOLIO_MPOSITION The list of identifiers and the position for each security in a user's custom portfolio. PORTFOLIO_MWEIGHT The list of identifiers and the percentage weight for each security in a user's custom portfolio. PORTFOLIO_NAME The name assigned to the user's custom portfolio. PORTFOLIO_POSITION_TYPE The manner in which securities are represented in a user's custom portfolio. Position types include: shares / par amount, fixed weight, and drifting weight.

eg df1 = con.bdsp("U123456-78 Client", "PORTFOLIO_MEMBERS" )

Robuko commented 7 years ago

Thank you very much for the feedback. I have gone in a different direction, I am now returning dataframes with the fields as column headers for ref and bdh, rather than the long dataframe format. I think these changes would conflict with your code and usage, so it may be better to keep it as a separate fork.

matthewgilbert commented 7 years ago

Okay sure, I will close the pull request for the time being than.