How to translate a BDS excel-formula to XBBG API for Python

I have the following Bloomberg BDS excel-formula: (“;” is substituted with “,” due to different settings in excel)

=@BSD(”TSLA US Equity”;”CHAIN_TICKERS”;”CHAIN_EXP_DT_OVRD=20210917”;”CHAIN_PUT_CALL_TYPE_OVRD=CALL”;”CHAIN_POINTS_OVRD=1000”)

In this instance, from this I get a list of all call option tickers for tickers, with expiration on 17/09/2021 (DDMMYYYY) for TSLA.

When trying to translate it to the XBBG API for Bloomberg, I have done the following (based on earlier helpful advice from SO’er):

import xbbg as blp
df = blp.bds(['TSLA US Equity'],
['CHAIN_TICKERS'],
CHAIN_EXP_DT_OVRD='CHAIN_EXP_DT_OVRD=20210917',
CHAIN_PUT_CALL_TYPE_OVRD='CHAIN_PUT_CALL_TYPE_OVRD=CALL',
CHAIN_POINTS_OVRD='CHAIN_POINTS_OVRD=1000')

But I only get a single data point returned, not the entire list.

What am I doing wrong?

Answer

You are specifying the parameters incorrectly. The function does not understand the CHAIN_POINTS_OVRD value, so is falling back to the default of 1, which is why the returned dataframe only has one value.

With xbbg you can usually supply Python types, with the override name becoming the parameter name (no quotes) in the bds call. So in this case the date override can be a datetime value, and the chain points override can be a number.

from xbbg import blp
from datetime import datetime

df = blp.bds('TSLA US Equity',
             'CHAIN_TICKERS',
             CHAIN_EXP_DT_OVRD=datetime(2021,9,17),
             CHAIN_PUT_CALL_TYPE_OVRD='CALL',
             CHAIN_POINTS_OVRD=1000)

print(df)

Output:

                                ticker
TSLA US Equity     TSLA US 09/17/21 C1
TSLA US Equity     TSLA US 09/17/21 C2
TSLA US Equity     TSLA US 09/17/21 C3
TSLA US Equity     TSLA US 09/17/21 C4
TSLA US Equity     TSLA US 09/17/21 C5
...                                ...
TSLA US Equity  TSLA US 09/17/21 C1600
TSLA US Equity  TSLA US 09/17/21 C1625
TSLA US Equity  TSLA US 09/17/21 C1650
TSLA US Equity  TSLA US 09/17/21 C1675
TSLA US Equity  TSLA US 09/17/21 C1700

[334 rows x 1 columns]