Skip to content

Instantly share code, notes, and snippets.

@vmetnev
Last active December 31, 2024 13:42
Show Gist options
  • Save vmetnev/786194e23c8c2c7d0ce1c56dd9feb7e1 to your computer and use it in GitHub Desktop.
Save vmetnev/786194e23c8c2c7d0ce1c56dd9feb7e1 to your computer and use it in GitHub Desktop.
Bloomberg queries
# python3 -m pip install blp
# https://pypi.org/project/blp/
# https://matthewgilbert.github.io/blp/quickstart.html
import datetime
import json
import pandas
from blp import blp
bquery = blp.BlpQuery().start()
# Request PX_LAST for a specific security
data = bquery.bdp(["IMB US EQUITY"], ["NAME", "PX_LAST"])
print((data))
# print(type(data))
index_members = bquery.bds("INDU Index", "INDX_MWEIGHT")
# print((index_members))
historical_data = bquery.bdh(
["SPY US Equity", "TLT US Equity"],
["PX_LAST", "VOLUME"],
start_date="20190101",
end_date="20190110",
options={"adjustmentSplit": True}
)
# print((historical_data))
with blp.BlpQuery() as bq:
df = bq.bdh(
["GME US Equity"],
["PX_LAST", "VOLUME"],
start_date="20210101",
end_date="20210130",
)
# print(df)
# this_bql = bquery.bql("get(px_last) for(['IBM US Equity', 'AAPL US Equity'])")
# print((this_bql))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment