From db48646186da436b5d5e44947ff7c9bbacc47fd7 Mon Sep 17 00:00:00 2001 From: Karolina Cynk Date: Fri, 30 Aug 2024 16:25:03 +0200 Subject: [PATCH 1/2] Provided adjustment to security types in bbg_figi_mapper --- .../bbg_figi_mapper.py | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/qf_lib/backtesting/contract/contract_to_ticker_conversion/bbg_figi_mapper.py b/qf_lib/backtesting/contract/contract_to_ticker_conversion/bbg_figi_mapper.py index f9e64f3b..1deafe5c 100644 --- a/qf_lib/backtesting/contract/contract_to_ticker_conversion/bbg_figi_mapper.py +++ b/qf_lib/backtesting/contract/contract_to_ticker_conversion/bbg_figi_mapper.py @@ -70,15 +70,21 @@ def preload_tickers_mapping(self, tickers: Union[Sequence[BloombergTicker], Bloo ----------- tickers: Union[Sequence[BloombergTicker], BloombergTicker] ticker(s) for which the mapping should be fetched and saved + + Returns + -------- + results: List[Dict] + returns a list of dictionaries, containing """ tickers, _ = convert_to_list(tickers, BloombergTicker) requests = [self._ticker_into_openfigi_requests(ticker) for ticker in tickers] - results = asyncio.run(self._distribute_mapping_requests(requests)) + results = list(asyncio.run(self._distribute_mapping_requests(requests))) figi_values = map(lambda r: r.get('figi', None), itertools.chain(*results)) self.ticker_to_contract_data.update(dict(zip(tickers, figi_values))) self.contract_data_to_ticker.update(dict(zip(figi_values, tickers))) + return results def preload_figi_mapping(self, figis: Union[Sequence[str], str]): """ @@ -94,11 +100,12 @@ def preload_figi_mapping(self, figis: Union[Sequence[str], str]): figis, _ = convert_to_list(figis, str) requests = [{"idType": "ID_BB_GLOBAL", "idValue": f} for f in figis] - results = itertools.chain(*asyncio.run(self._distribute_mapping_requests(requests))) + results = list(itertools.chain(*asyncio.run(self._distribute_mapping_requests(requests)))) mapping = dict(self._ticker_from_openfigi_response(r, f) for (r, f) in zip(results, figis)) self.ticker_to_contract_data.update(mapping) self.contract_data_to_ticker.update({val: key for key, val in mapping.items()}) + return results def contract_to_ticker(self, figi: str) -> BloombergTicker: """ Maps Broker specific contract objects onto corresponding Tickers. @@ -175,14 +182,15 @@ def _ticker_from_openfigi_response(self, contract_data: Dict[str, str], figi: st security_type_map = { 'Index': (SecurityType.INDEX, ['ticker']), 'Equity': (SecurityType.STOCK, ['ticker', 'exchCode', 'marketSector']), - 'Mutual Fund': (SecurityType.STOCK, ['ticker', 'exchCode', 'marketSector']), - 'Future': (SecurityType.FUTURE, ['ticker', 'marketSector']), - 'CROSS': (SecurityType.FX, ['securityDescription']), - 'SPOT': (SecurityType.FX, ['securityDescription']), + 'Comdty': (SecurityType.FUTURE, ['ticker', 'marketSector']), + 'Curncy': (SecurityType.FX, ['securityDescription']), + 'Corp': (SecurityType.STOCK, ['securityDescription', 'marketSector']), + 'Govt': (SecurityType.STOCK, ['securityDescription']), + 'Pfd': (SecurityType.STOCK, ['securityDescription']), } try: - security_type, fields = security_type_map[contract_data.get('securityType2', '')] + security_type, fields = security_type_map[contract_data.get('marketSector', '')] fields_data = [contract_data.get(f) for f in fields if contract_data.get(f)] ticker_str = " ".join(fields_data) From a20eba048026f751b7511f5d3ac9e9442de346ad Mon Sep 17 00:00:00 2001 From: Karolina Cynk Date: Fri, 30 Aug 2024 16:26:36 +0200 Subject: [PATCH 2/2] Fixed doc strings --- .../contract_to_ticker_conversion/bbg_figi_mapper.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/qf_lib/backtesting/contract/contract_to_ticker_conversion/bbg_figi_mapper.py b/qf_lib/backtesting/contract/contract_to_ticker_conversion/bbg_figi_mapper.py index 1deafe5c..e50e46b4 100644 --- a/qf_lib/backtesting/contract/contract_to_ticker_conversion/bbg_figi_mapper.py +++ b/qf_lib/backtesting/contract/contract_to_ticker_conversion/bbg_figi_mapper.py @@ -74,7 +74,7 @@ def preload_tickers_mapping(self, tickers: Union[Sequence[BloombergTicker], Bloo Returns -------- results: List[Dict] - returns a list of dictionaries, containing + returns a list of dictionaries, containing all data extracted from openfigi for additional reference """ tickers, _ = convert_to_list(tickers, BloombergTicker) @@ -96,6 +96,11 @@ def preload_figi_mapping(self, figis: Union[Sequence[str], str]): ----------- figis: Union[Sequence[str], str] FIGI(s) for which the mapping should be fetched and saved + + Returns + -------- + results: List[Dict] + returns a list of dictionaries, containing all data extracted from openfigi for additional reference """ figis, _ = convert_to_list(figis, str)