BloombergDataProvider#
- class qf_lib.data_providers.bloomberg.bloomberg_data_provider.BloombergDataProvider(settings: Settings, timer: Timer | None = None)[source]#
Bases:
AbstractPriceDataProvider,TickersUniverseProvider,FuturesDataProvider,ExchangeRateProviderData Provider which provides financial data from Bloomberg.
- 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: BloombergTicker | Sequence[BloombergTicker], fields: str | Sequence[str], overrides: Dict[str, str] | None = None) 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:
QFDataFrame/QFSeries – 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.
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.
- Raises:
BloombergError – When couldn’t get the data from Bloomberg Service
- get_history(tickers: BloombergTicker | Sequence[BloombergTicker], fields: str | Sequence[str], start_date: datetime, end_date: datetime = None, frequency: Frequency = None, currency: str = None, overrides: Dict | None = None, look_ahead_bias: bool = False, **kwargs) 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’ of 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)
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.
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 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.
- get_tabular_data(ticker: BloombergTicker, field: str, overrides: Dict[str, str] | None = None) List[source]#
Provides current tabular data from Bloomberg. It is a wrapper around get_current_values.
- Parameters:
ticker (BloombergTicker) – ticker for security that should be retrieved
field (str) – field of security that should be retrieved
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.
- Returns:
tabular data for the given ticker and field
- Return type:
List
- 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. It will not return any data for indices with more than 20,000 members.
- Parameters:
universe_ticker (Ticker) – The ticker symbol representing the index or universe for which the tickers are being queried.
date (datetime) – The date for which the tickers’ universe data is requested.
display_figi (bool) – The following flag can be used to have this field return Financial Instrument Global Identifiers (FIGI). By default set to False, which results in returning tickers identifiers instead of FIGI.
- Returns:
A list of tickers (Ticker objects) that were included in the index on the specified date.
- Return type:
List[Ticker]
- get_tickers_universe_with_weights(universe_ticker: BloombergTicker, date: datetime | None = None, display_figi: bool = False) QFSeries[source]#
Returns the tickers belonging to a specified universe, along with their corresponding weights, at a given date. The result is a QFSeries indexed by ticker objects, with the values representing the respective weights of each ticker in the universe.
Important: It will not return any data for indices with more than 20,000 members.
- Parameters:
universe_ticker (Ticker) – The ticker symbol representing the index or universe for which the tickers are being queried.
date (datetime) – The date for which the tickers’ universe data is requested. If not provided, it defaults to current date.
display_figi (bool) – The following flag can be used to have this field return Financial Instrument Global Identifiers (FIGI). By default set to False, which results in returning tickers identifiers instead of FIGI.
- Returns:
A QFSeries indexed by Ticker objects, where the values are the weights of the respective tickers in the universe at a given date.
- Return type:
- get_unique_tickers(universe_ticker: Ticker) List[Ticker][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]