BloombergDLDataProvider#
- class qf_lib.data_providers.bloomberg_dl.bloomberg_dl_data_provider.BloombergDLDataProvider(settings: Settings, reply_timeout: int = 5, timer: Timer | None = None, save_to_disk: bool = False, push_notification: bool = True, check_existing_first: bool = False)[source]#
Bases:
AbstractPriceDataProvider,TickersUniverseProvider,FuturesDataProviderData Provider which provides financial data from Bloomberg Data License REST API.
The settings file requires the following variables:
bbg_dl.client_id
bbg_dl.client_secret
Other optional settings parameters:
bbg_dl.user (parameter to link the Data License to a Bloomberg Anywhere or Bloomberg Professional account; the User value can be obtained by running IAM <GO> in the Bloomberg terminal)
bbg_dl.sn (parameter to link the Data License to a Bloomberg Professional account; the S/N value can be obtained by running IAM <GO> in the Bloomberg terminal)
- Parameters:
settings (Settings) – Settings object containing bbg_dl credentials and output_directory.
reply_timeout (int) – Maximum time in minutes to wait for an SSE delivery notification.
timer (Timer, optional) – Timer instance used for end-date calculations.
save_to_disk (bool) – If True, raw JSON responses are persisted under the output_directory.
push_notification (bool) – If True (default), SSE Event Stream for DL Platform Content Endpoint Notifications is used to notify about the delivered content. If False, the endpoints are polled regularly every 30 seconds.
check_existing_first (bool) – If True, before POSTing a new request, first polls Bloomberg to see if data for this request already exists (using a deterministic request name from the payload hash). If found, fetches it via GET; otherwise creates a new request.
- expiration_date_field_str_map(ticker: BloombergTicker = None) Dict[ExpirationDateField, str][source]#
Method has to be implemented in each data provider in order to be able to use get_futures_chain_tickers. Returns dictionary containing mapping between ExpirationDateField and corresponding string that has to be used by get_futures_chain_tickers method.
- Parameters:
ticker (None, Ticker) – ticker is optional and might be uses by particular data providers to create appropriate dictionary
- Returns:
mapping between ExpirationDateField and corresponding strings
- Return type:
Dict[ExpirationDateField, str]
- get_current_values(tickers: BloombergTicker | Sequence[BloombergTicker], fields: str | Sequence[str], overrides: Dict[str, str] | None = None, pricing_source: str | None = 'BGN') None | float | str | list | QFSeries | QFDataFrame[source]#
Gets from the Bloomberg DL REST API the current values of fields for given tickers.
- Parameters:
tickers (BloombergTicker or Sequence[BloombergTicker]) – Tickers for securities which should be retrieved.
fields (str or Sequence[str]) – Fields of securities which should be retrieved.
overrides (dict, optional) – A dictionary where each key is a field mnemonic and the value is the override string. Example: {‘INCLUDE_EXPIRED_CONTRACTS’: ‘Y’}.
pricing_source (str, optional) – Pricing source applied to all financial instruments in the request universe. By default equals to ‘BGN’.
- Returns:
Either QFDataFrame with 2 dimensions: ticker, field or QFSeries with 1 dimension: ticker or field (depending on whether many tickers or fields were provided).
- Return type:
float or QFSeries or QFDataFrame
- Raises:
BloombergError – When unexpected response from Bloomberg DL REST API occurred.
- get_history(tickers: BloombergTicker | Sequence[BloombergTicker], fields: str | Sequence[str], start_date: datetime, end_date: datetime | None = None, frequency: Frequency = Frequency.DAILY, currency: str | None = None, pricing_source: str | None = 'BGN', look_ahead_bias: bool = False, overrides: Dict[str, str] | None = None, **kwargs) QFSeries | QFDataFrame | QFDataArray[source]#
Gets historical data from Bloomberg DL REST API from the (start_date - end_date) time range.
- Parameters:
tickers (BloombergTicker or Sequence[BloombergTicker]) – Tickers for securities which should be retrieved.
fields (str or Sequence[str]) – Fields of securities which should be retrieved.
start_date (datetime) – Date representing the beginning of historical period from which data should be retrieved.
end_date (datetime, optional) – Date representing the end of historical period from which data should be retrieved; if not provided, the current date will be used.
frequency (Frequency) – Frequency of the data.
currency (str, optional) – Currency which should be used to obtain the historical data (by default local currency is used).
pricing_source (str, optional) – Pricing source applied to all financial instruments in the request universe. By default equals to ‘BGN’.
look_ahead_bias (bool) – If set to False, the look-ahead bias will be taken care of to make sure no future data is returned.
overrides (dict, optional) – A dictionary of field overrides, e.g. {‘INCLUDE_EXPIRED_CONTRACTS’: ‘Y’}.
- Returns:
If possible the result will be squeezed so that instead of returning QFDataArray, data of lower dimensionality will be returned.
- Return type:
QFSeries or QFDataFrame or QFDataArray
- Raises:
BloombergError – When unexpected response from Bloomberg DL REST API occurred.
- get_tickers_universe(universe_ticker: BloombergTicker, date: datetime | None = None, display_figi: bool = False) List[BloombergTicker][source]#
Returns a list of all members of an index. Bloomberg Data License supports only fetching constituents for the current date and it will not return any data for indices with more than 20,000 members.
- Parameters:
universe_ticker (BloombergTicker) – Ticker that describes a specific universe, which members will be returned.
date (datetime, optional) – Date for which current universe members’ tickers will be returned.
display_figi (bool) – If True, return Financial Instrument Global Identifiers (FIGI) instead of standard tickers.
- get_tickers_universe_with_weights(universe_ticker: BloombergTicker, date: datetime | None = None, display_figi: bool = False) QFSeries[source]#
Returns a series of all members of an index with their weights. It will not return any data for indices with more than 20,000 members.
- Parameters:
universe_ticker (BloombergTicker) – Ticker that describes a specific universe, which members will be returned.
date (datetime, optional) – Date for which current universe members’ tickers will be returned.
display_figi (bool) – If True, return Financial Instrument Global Identifiers (FIGI) instead of standard tickers.
- Returns:
A series of the weights of all BloombergTickers within the requested index, indexed by those tickers.
- Return type:
- get_unique_tickers(universe_ticker: BloombergTicker) List[BloombergTicker][source]#
Retrieves a list of unique tickers that belong to the specified universe, regardless of the date.
- price_field_to_str_map() Dict[PriceField, str][source]#
Method has to be implemented in each data provider in order to be able to use get_price. Returns dictionary containing mapping between PriceField and corresponding string that has to be used by get_history method to get appropriate type of price series.
- Returns:
mapping between PriceFields and corresponding strings
- Return type:
Dict[PriceField, str]