matthewgilbert / blp

Pythonic interface for Bloomberg Open API
Apache License 2.0
115 stars 25 forks source link

TypeError(f"Bulk reference data not supported, expected singleton values but received {data}") #1

Closed gghickman closed 3 years ago

gghickman commented 3 years ago

Hi! I am struggling with this: df1 + df2 are fine. df3 gives me the bulk reference data not supported, followed by unstructured output. Any suggestion?

import datetime import json import pandas as pd from blp import blp bquery = blp.BlpQuery().start()

df1 = pd.DataFrame(bquery.bdh(['MSFT US Equity'],['PX_LAST','PE_RATIO'],start_date='20210601',end_date='20210622')) print(df1.head(3))

df2 = pd.DataFrame(bquery.bdp(['MSFT US Equity', 'GOOG US Equity'],['PX_OPEN', 'PX_LAST'])) print(df2)

df3 = pd.DataFrame(bquery.bdp(['DBR 5.5 31 Govt'],['DES_CASH_FLOW'])) print(df3)

matthewgilbert commented 3 years ago

It's impossible for me to see what is going on if you don't include your output from print.

gghickman commented 3 years ago

Sorry, I am a bit new to this - here is the output:

D:\Users\Gordon\My Documents\Python>bbg_input2.py date security PX_LAST PE_RATIO 0 2021-06-01 MSFT US Equity 247.40 34.2080 1 2021-06-02 MSFT US Equity 247.30 34.1941 2 2021-06-03 MSFT US Equity 245.71 33.9743 security PX_OPEN PX_LAST 0 MSFT US Equity 266.16 266.69 1 GOOG US Equity 2541.07 2545.64 Traceback (most recent call last): File "D:\Users\Gordon\My Documents\Python\bbg_input2.py", line 13, in df3 = pd.DataFrame(bquery.bdp(['DBR 5.5 31 Govt'],['DES_CASH_FLOW'])) File "C:\Users\gordo\AppData\Local\Programs\Python\Python39\lib\site-packages\blp\blp.py", line 821, in bdp df = self.query(query, self.parser, self.collect_to_bdp) File "C:\Users\gordo\AppData\Local\Programs\Python\Python39\lib\site-packages\blp\blp.py", line 646, in query res = collector(res) File "C:\Users\gordo\AppData\Local\Programs\Python\Python39\lib\site-packages\blp\blp.py", line 835, in collect_to_bdp raise TypeError(f"Bulk reference data not supported, expected singleton values but received {data}") TypeError: Bulk reference data not supported, expected singleton values but received {'DES_CASH_FLOW': [{'Payment Date': Timestamp('2022-01-04 00:00:00'), 'Coupon Amount': 55000.0, 'Principal Amount': 0.0}, {'Payment Date': Timestamp('2023-01-04 00:00:00'), 'Coupon Amount': 55000.0, 'Principal Amount': 0.0}, {'Payment Date': Timestamp('2024-01-04 00:00:00'), 'Coupon Amount': 55000.0, 'Principal Amount': 0.0}, {'Payment Date': Timestamp('2025-01-04 00:00:00'), 'Coupon Amount': 55000.0, 'Principal Amount': 0.0}, {'Payment Date': Timestamp('2026-01-04 00:00:00'), 'Coupon Amount': 55000.0, 'Principal Amount': 0.0}, {'Payment Date': Timestamp('2027-01-04 00:00:00'), 'Coupon Amount': 55000.0, 'Principal Amount': 0.0}, {'Payment Date': Timestamp('2028-01-04 00:00:00'), 'Coupon Amount': 55000.0, 'Principal Amount': 0.0}, {'Payment Date': Timestamp('2029-01-04 00:00:00'), 'Coupon Amount': 55000.0, 'Principal Amount': 0.0}, {'Payment Date': Timestamp('2030-01-04 00:00:00'), 'Coupon Amount': 55000.0, 'Principal Amount': 0.0}, {'Payment Date': Timestamp('2031-01-04 00:00:00'), 'Coupon Amount': 55000.0, 'Principal Amount': 1000000.0}]}

matthewgilbert commented 3 years ago

I would take a look at this https://stackoverflow.com/help/minimal-reproducible-example and also look at github code formatting https://docs.github.com/en/github/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks

gghickman commented 3 years ago

Python Code

import datetime
import json
import pandas as pd
from blp import blp
bquery = blp.BlpQuery().start()
df3 = pd.DataFrame(bquery.bdp(['DBR 5.5 31 Govt'],['DES_CASH_FLOW']))

Output

Traceback (most recent call last):
  File "D:\Users\Gordon\My Documents\Python\bbg_input2.py", line 6, in <module>
    df3 = pd.DataFrame(bquery.bdp(['DBR 5.5 31 Govt'],['DES_CASH_FLOW']))
  File "C:\Users\gordo\AppData\Local\Programs\Python\Python39\lib\site-packages\blp\blp.py", line 821, in bdp
    df = self.query(query, self.parser, self.collect_to_bdp)
  File "C:\Users\gordo\AppData\Local\Programs\Python\Python39\lib\site-packages\blp\blp.py", line 646, in query
    res = collector(res)
  File "C:\Users\gordo\AppData\Local\Programs\Python\Python39\lib\site-packages\blp\blp.py", line 835, in collect_to_bdp
    raise TypeError(f"Bulk reference data not supported, expected singleton values but received {data}")
TypeError: Bulk reference data not supported, expected singleton values but received {'DES_CASH_FLOW': [{'Payment Date': Timestamp('2022-01-04 00:00:00'), 'Coupon Amount': 55000.0, 'Principal Amount': 0.0}, {'Payment Date': Timestamp('2023-01-04 00:00:00'), 'Coupon Amount': 55000.0, 'Principal Amount': 0.0}, {'Payment Date': Timestamp('2024-01-04 00:00:00'), 'Coupon Amount': 55000.0, 'Principal Amount': 0.0}, {'Payment Date': Timestamp('2025-01-04 00:00:00'), 'Coupon Amount': 55000.0, 'Principal Amount': 0.0}, {'Payment Date': Timestamp('2026-01-04 00:00:00'), 'Coupon Amount': 55000.0, 'Principal Amount': 0.0}, {'Payment Date': Timestamp('2027-01-04 00:00:00'), 'Coupon Amount': 55000.0, 'Principal Amount': 0.0}, {'Payment Date': Timestamp('2028-01-04 00:00:00'), 'Coupon Amount': 55000.0, 'Principal Amount': 0.0}, {'Payment Date': Timestamp('2029-01-04 00:00:00'), 'Coupon Amount': 55000.0, 'Principal Amount': 0.0}, {'Payment Date': Timestamp('2030-01-04 00:00:00'), 'Coupon Amount': 55000.0, 'Principal Amount': 0.0}, {'Payment Date': Timestamp('2031-01-04 00:00:00'), 'Coupon Amount': 55000.0, 'Principal Amount': 1000000.0}]}
gghickman commented 3 years ago

I hope that is better. Steep learning curve. Help (and patience) appreciated

matthewgilbert commented 3 years ago

As the error indicates, I believe DES_CASH_FLOW is a bulk reference field. Take a look at using bquery.bds. You can see an example in the documentation here https://matthewgilbert.github.io/blp/quickstart.html#Excel-like-functionality

gghickman commented 3 years ago

Thank you. That works. Help appreciated.