BloombergBeapHapiDataProvider

class qf_lib.data_providers.bloomberg_beap_hapi.bloomberg_beap_hapi_data_provider.BloombergBeapHapiDataProvider(settings: Settings, reply_timeout: int = 5, timer: Optional[Timer] = None)[source]

Bases: AbstractPriceDataProvider, TickersUniverseProvider, FuturesDataProvider

Data Provider which provides financial data from Bloomberg BEAP HAPI.

The settings file requires the following variables: - hapi_credentials.client_id - hapi_credentials.client_secret - hapi_credentials.expiration_date - output_directory

Other optional settings parameters: - hapi_credentials.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) - hapi_crenetials.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)

Methods:

expiration_date_field_str_map([ticker])

Method has to be implemented in each data provider in order to be able to use get_futures_chain_tickers.

get_current_values(tickers, fields[, ...])

Gets from the Bloomberg HAPI the current values of fields for given tickers.

get_history(tickers, fields, start_date[, ...])

Gets historical data from Bloomberg HAPI from the (start_date - end_date) time range.

get_tickers_universe(universe_ticker[, ...])

Returns a list of all members of an index.

get_tickers_universe_with_weights(...[, ...])

Returns a list of all members of an index.

get_unique_tickers(universe_ticker)

Retrieves a list of unique tickers that belong to the specified universe, regardless of the date.

price_field_to_str_map()

Method has to be implemented in each data provider in order to be able to use get_price.

supported_ticker_types()

Returns classes of tickers which are supported by this DataProvider.

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: Union[BloombergTicker, Sequence[BloombergTicker]], fields: Union[str, Sequence[str]], universe_creation_time: datetime = None, overrides: Optional[Dict[str, str]] = None, pricing_source: Optional[str] = 'BGN') Union[None, float, str, List, QFSeries, QFDataFrame][source]

Gets from the Bloomberg HAPI the current values of fields for given tickers.

Parameters:
  • tickers (BloombergTicker, Sequence[BloombergTicker]) – tickers for securities which should be retrieved

  • fields (str, Sequence[str]) – fields of securities which should be retrieved

  • universe_creation_time (datetime) – Used only if we want to get previously created universe, fields universe or request

  • overrides (Optional[Dict[str, str]]) – A dictionary where each key is a field name (as a string) that corresponds to a default field in the Bloomberg request, and the value is the new value (as a string) to override the default value for that field. The dictionary allows for multiple fields to be overridden at once, with each key representing a specific field to be modified, and the associated value specifying the replacement value for that field. If not provided, the default values for all fields will be used. Example: {‘INCLUDE_EXPIRED_CONTRACTS’: ‘Y’}

  • pricing_source (Optional[str]) – Allows a user to specify a pricing source that is 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 dimensions: ticker of field (depending if many tickers or fields were provided) is returned.

Return type:

float, QFSeries, QFDataFrame

Raises:

BloombergError – When unexpected response from Bloomberg HAPI happened

get_history(tickers: Union[BloombergTicker, Sequence[BloombergTicker]], fields: Union[str, Sequence[str]], start_date: datetime, end_date: datetime = None, frequency: Frequency = Frequency.DAILY, universe_creation_time: Optional[datetime] = None, currency: Optional[str] = None, pricing_source: Optional[str] = 'BGN', look_ahead_bias: bool = False, **kwargs) Union[QFSeries, QFDataFrame, QFDataArray][source]

Gets historical data from Bloomberg HAPI from the (start_date - end_date) time range.

Parameters:
  • tickers (BloombergTicker, Sequence[BloombergTicker]) – tickers for securities which should be retrieved

  • fields (str, 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) – date representing the end of historical period from which data should be retrieved; if no end_date was provided, by default the current date will be used

  • frequency (Frequency) – frequency of the data

  • universe_creation_time (datetime) – Used only if we want to get previously created universe, fields universe or request

  • currency (Optional[str]) – currency which should be used to obtain the historical data (by default local currency is used)

  • pricing_source (Optional[str]) – Allows a user to specify a pricing source that is 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

Returns:

If possible the result will be squeezed, so that instead of returning QFDataArray, data of lower dimensionality will be returned. The results will be either an QFDataArray (with 3 dimensions: date, ticker, field), a QFDataFrame (with 2 dimensions: date, ticker or field; it is also possible to get 2 dimensions ticker and field if single date was provided) or QFSeries (with 1 dimensions: date). If no data is available in the database or an non existing ticker was provided an empty structure (QFSeries, QFDataFrame or QFDataArray) will be returned returned.

Return type:

QFSeries, QFDataFrame, QFDataArray

Raises:

BloombergError – When unexpected response from Bloomberg HAPI happened

get_tickers_universe(universe_ticker: BloombergTicker, date: Optional[datetime] = 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) – date for which current universe members’ tickers will be returned.

  • display_figi – the following flag can be used to have this field return Financial Instrument Global Identifiers (FIGI).

get_tickers_universe_with_weights(universe_ticker: BloombergTicker, date: Optional[datetime] = None, display_figi: bool = False) QFSeries[source]

Returns a list of all members of an index. It will not return any data for indices with more than 20,000 members.

Parameters:
  • universe_ticker – ticker that describes a specific universe, which members will be returned

  • date – date for which current universe members’ tickers will be returned

  • display_figi – the following flag can be used to have this field return Financial Instrument Global Identifiers (FIGI).

Returns:

a series of the weights of all BloombergTickers within the requested Index, indexed by those tickers

Return type:

QFSeries

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.

Parameters:

universe_ticker (Ticker) – The ticker symbol representing the index or universe for which the tickers are being queried.

Returns:

A list of unique tickers (Ticker objects) that are part of the specified universe (regardless of the date).

Return type:

List[Ticker]

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]

supported_ticker_types()[source]

Returns classes of tickers which are supported by this DataProvider.