I m trying to convert this excel formula into python:
=@BDH("MZBZ4C 75.00 Comdty","Trade,Settle","2024-02-20 09:00:00","","Dir=V","IntrRw=true","Headers=Y","Dts=S","QRM=S","cols=4;rows=4")
I tried with the blp library using this:
from blp import blp
bquery = blp.BlpQuery().start()
df = bquery.bdh("MZBZ4C 75.00 Comdty", ["Trade", "Settle"],
start_date="20240219",
end_date="",
options={"adjustmentSplit": True})
But I get a field error saying the field is invalid. That library worked for my other types of data pulls.
Any idea how I could make this work please?
You need to call a different function for Intraday Tick data:
The Excel
=BDH()function combines requests for static historic end-of-day data AND intraday tick data. The switchIntrRw=Trueis used to denote tick data. Under the covers in the low-level Bloomberg API these are different requests:HistoricalDataRequestandIntradayTickRequestrespectively.The
blp.bditfunction returns intraday data using start and end UTC datetime parameters. Here's the reference.NB. Bloomberg only stores intraday tick data going back 6 months or so.
EDIT: Overrides and Options
The distinction between an
Overrideand anOptionis not always clear. In the Excel=BDH()function, there is a distinction betweenField OverridesandOptional Parameters. Roughly speaking, anOverrideis a user-supplied value that changes how Bloomberg calculates each data item (eg: in some cases you can ask for the number to be converted to a different currency), while anOptionchanges which data items are returned.The override and option names that Excel uses, are NOT always the same names that the underlying API will understand. Whether an API call accepts
overrides oroptions is defined in the Request schema. TheIntradayTickRequestrequest does NOT have anyoverrides. For the APIoverrides are usually Bloombergfields (which can be viewed using theFLDSfunction in the Terminal).The API definition is here, and the relevant information for Tick Data is on Page 95, where you can see the Excel option and the API equivalent.
In the OP's example,
QRMis anoption, but the API does not have the nameQRM. Instead, reading the API docs, we see that the corresponding API option is the somewhat cryptic:includeNonPlottableEvents.The
optionsparameter to theblp.bdit()function takes a dictionary of options, with their values.As for the
Dtsflag, I think the API returns the dates/times whatever you specify, so this parameter is redundant. As is the case for some of the Excel=BDH()parameters they simple govern how the data is displayed in Excel and do not have an API equivalent. Another example isSort: the API does not offer sorting, this flag is applied to the data by Excel.So the OP's request becomes:
The IntradayTickRequest schema