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=True
is used to denote tick data. Under the covers in the low-level Bloomberg API these are different requests:HistoricalDataRequest
andIntradayTickRequest
respectively.The
blp.bdit
function 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
Override
and anOption
is not always clear. In the Excel=BDH()
function, there is a distinction betweenField Overrides
andOptional Parameters
. Roughly speaking, anOverride
is 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 anOption
changes 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
override
s oroption
s is defined in the Request schema. TheIntradayTickRequest
request does NOT have anyoverride
s. For the APIoverride
s are usually Bloombergfield
s (which can be viewed using theFLDS
function 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,
QRM
is 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
options
parameter to theblp.bdit()
function takes a dictionary of options, with their values.As for the
Dts
flag, 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