BloombergBeapHapiDataProvider
- class qf_lib.data_providers.bloomberg_beap_hapi.bloomberg_beap_hapi_data_provider.BloombergBeapHapiDataProvider(settings: Settings, reply_timeout: int = 5)[source]
Bases:
AbstractPriceDataProvider
,TickersUniverseProvider
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[, date])- param universe_ticker:
ticker that describes a specific universe, which members will be returned
get_unique_tickers
(universe_ticker)Returns the unique list of Tickers belonging to a specified universe regardless of the date.
Method has to be implemented in each data provider in order to be able to use get_price.
Returns classes of tickers which are supported by this DataProvider.
- expiration_date_field_str_map(ticker: Optional[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: Optional[datetime] = None, fields_overrides: Optional[List[Tuple]] = None) 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
fields_overrides (Optional[List[Tuple]]) – list of tuples representing overrides, where first element is always the name of the override and second element is the value e.g. in case if we want to download ‘FUT_CHAIN’ and include expired contracts we add the following overrides [(‘INCLUDE_EXPIRED_CONTRACTS’, ‘Y’),]
- 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: Optional[datetime] = None, frequency: Frequency = Frequency.DAILY, universe_creation_time: Optional[datetime] = None, currency: Optional[str] = None) 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)
- 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:
- Raises:
BloombergError – When unexpected response from Bloomberg HAPI happened
- get_tickers_universe(universe_ticker: BloombergTicker, date: Optional[datetime] = None) List[BloombergTicker] [source]
- 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
- get_unique_tickers(universe_ticker: BloombergTicker) List[BloombergTicker] [source]
Returns the unique list of Tickers belonging to a specified universe regardless of the date.
- Parameters:
universe_ticker – ticker that describes a specific universe, which members will be returned
- Returns:
list of Tickers belonging to the universe
- 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]