BloombergDataProvider
- class qf_lib.data_providers.bloomberg.bloomberg_data_provider.BloombergDataProvider(settings: Settings, timer: Optional[Timer] = None)[source]
Bases:
AbstractPriceDataProvider,TickersUniverseProvider,FuturesDataProvider,ExchangeRateProviderData Provider which provides financial data from Bloomberg.
Methods:
connect()Connects to Bloomberg data service and holds a connection.
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 the current values of fields for given tickers.
get_history(tickers, fields, start_date[, ...])Gets historical data from Bloomberg from the (start_date - end_date) time range.
get_last_available_exchange_rate(...[, ...])Get last available exchange rate from the base currency to the quote currency in the provided frequency.
get_tabular_data(ticker, field[, ...])Provides current tabular data from Bloomberg.
get_tickers_universe(universe_ticker[, ...])Returns a list of all members of an index.
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.
- connect()[source]
Connects to Bloomberg data service and holds a connection. Connecting might take about 10-15 seconds
- 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]], override_name: str = None, override_value: str = None) Union[None, float, str, QFSeries, QFDataFrame][source]
Gets 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
- Returns:
Either QFDataFrame with 2 dimensions: ticker, field or QFSeries with 1 dimensions: ticker of field (depending if many tickers or fields was provided) is returned.
- Return type:
QFDataFrame/QFSeries
- Raises:
BloombergError – When couldn’t get the data from Bloomberg Service
- get_history(tickers: Union[BloombergTicker, Sequence[BloombergTicker]], fields: Union[str, Sequence[str]], start_date: datetime, end_date: datetime = None, frequency: Frequency = None, currency: str = None, override_name: str = None, override_value: str = None, look_ahead_bias: bool = False, **kwargs) Union[QFSeries, QFDataFrame, QFDataArray][source]
Gets historical data from Bloomberg from the (start_date - end_date) time range. In case of frequency, which is higher than daily frequency (intraday data), the data is indexed by the start_date. E.g. Time range: 8:00 - 8:01, frequency: 1 minute - indexed with the 8:00 timestamp
- Parameters:
tickers (Ticker, Sequence[Ticker]) – tickers for securities which should be retrieved
fields (None, str, Sequence[str]) – fields of securities which should be retrieved. If None, all available fields will be returned (only supported by few DataProviders)
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. It defaults to DAILY.
currency (str) –
override_name (str) –
override_value (str) –
look_ahead_bias (bool) –
- 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 a non existing ticker was provided an empty structure (QFSeries, QFDataFrame or QFDataArray) will be returned returned.
- Return type:
- get_last_available_exchange_rate(base_currency: str, quote_currency: str, frequency: Frequency = Frequency.DAILY)[source]
Get last available exchange rate from the base currency to the quote currency in the provided frequency.
- Parameters:
base_currency (str) – ISO code of the base currency (ex. ‘USD’ for US Dollar)
quote_currency (str) – ISO code of the quote currency (ex. ‘EUR’ for Euro)
frequency (Frequency) – frequency of the returned data
- Returns:
last available exchange rate
- Return type:
float
- get_tabular_data(ticker: BloombergTicker, field: str, override_names: Optional[Union[str, Sequence[str]]] = None, override_values: Optional[Union[str, Sequence[str]]] = None) List[source]
Provides current tabular data from Bloomberg.
Was tested on ‘INDX_MEMBERS’ and ‘MERGERS_AND_ACQUISITIONS’ requests. There is no guarantee that all other request will be handled, as returned data structures might vary.
- Parameters:
ticker (BloombergTicker) – ticker for security that should be retrieved
field (str) – field of security that should be retrieved
override_names (str) –
override_values (str) –
- Returns:
tabular data for the given ticker and field
- Return type:
List
- 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. 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).
- get_unique_tickers(universe_ticker: Ticker) List[Ticker][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]