def _get_inflation_swap_data( asset: Asset, swap_tenor: str, index_type: str = None, forward_tenor: Optional[GENERIC_DATE] = None, clearing_house: tm_rates._ClearingHouse = None, source: str = None, real_time: bool = False, query_type: QueryType = QueryType.SWAP_RATE) -> pd.DataFrame: if real_time: raise NotImplementedError( 'realtime inflation swap data not implemented') currency = CurrencyEnum(asset.get_identifier(AssetIdentifier.BLOOMBERG_ID)) if currency.value not in CURRENCY_TO_INDEX_BENCHMARK.keys(): raise NotImplementedError( 'Data not available for {} inflation swap rates'.format( currency.value)) index_type = _check_inflation_index_type(currency, index_type) clearing_house = tm_rates._check_clearing_house(clearing_house) defaults = _get_inflation_swap_leg_defaults(currency, index_type) if not (tm_rates._is_valid_relative_date_tenor(swap_tenor)): raise MqValueError('invalid swap tenor ' + swap_tenor) forward_tenor = tm_rates._check_forward_tenor(forward_tenor) fixed_rate = 'ATM' kwargs = dict(type='InflationSwap', asset_parameters_termination_date=swap_tenor, asset_parameters_index=defaults['index_type'], asset_parameters_fixed_rate=fixed_rate, asset_parameters_clearing_house=clearing_house.value, asset_parameters_effective_date=forward_tenor, asset_parameters_notional_currency=currency.name) rate_mqid = _get_tdapi_inflation_rates_assets(**kwargs) _logger.debug( f'where asset= {rate_mqid}, swap_tenor={swap_tenor}, index={defaults["index_type"]}, ' f'forward_tenor={forward_tenor}, pricing_location={defaults["pricing_location"].value}, ' f'clearing_house={clearing_house.value}, notional_currency={currency.name}' ) q = GsDataApi.build_market_data_query([rate_mqid], query_type, source=source, real_time=real_time) _logger.debug('q %s', q) df = _market_data_timed(q) return df
def _get_fxo_data(asset: Asset, expiry_tenor: str, strike: str, option_type: str = None, expiration_location: str = None, location: PricingLocation = None, premium_payment_date: str = None, source: str = None, real_time: bool = False, query_type: QueryType = QueryType.IMPLIED_VOLATILITY) \ -> pd.DataFrame: if real_time: raise NotImplementedError( 'realtime inflation swap data not implemented') cross = asset.get_identifier(AssetIdentifier.BLOOMBERG_ID) if cross not in FX_DEFAULTS.keys(): raise NotImplementedError( 'Data not available for {} FX Vanilla options'.format(cross)) defaults = _get_fxo_defaults(cross) if not (tm_rates._is_valid_relative_date_tenor(expiry_tenor)): raise MqValueError('invalid expiry ' + expiry_tenor) if expiration_location is None: # expirationtime = defaults["expirationTime"] _ = defaults["expirationTime"] else: # expirationtime = expiration_location _ = expiration_location if premium_payment_date is None: premium_date = defaults["premiumPaymentDate"] else: premium_date = premium_payment_date if option_type == "Put": call_ccy = defaults["over"] put_ccy = defaults["under"] else: call_ccy = defaults["under"] put_ccy = defaults["over"] kwargs = dict( asset_class='FX', type='Option', asset_parameters_call_currency=call_ccy, asset_parameters_put_currency=put_ccy, asset_parameters_expiration_date=expiry_tenor, # asset_parameters_expiration_time=expirationtime, asset_parameters_option_type=option_type, asset_parameters_premium_payment_date=premium_date, asset_parameters_strike_price_relative=strike, ) rate_mqid = _get_tdapi_fxo_assets(**kwargs) if location is None: pricing_location = PricingLocation.NYC else: pricing_location = PricingLocation(location) where = dict(pricingLocation=pricing_location.value) # _logger.debug(f'where asset= {rate_mqid}, swap_tenor={swap_tenor}, index={defaults["index_type"]}, ' # f'forward_tenor={forward_tenor}, pricing_location={pricing_location.value}, ' # f'clearing_house={clearing_house.value}, notional_currency={currency.name}') q = GsDataApi.build_market_data_query([rate_mqid], query_type, where=where, source=source, real_time=real_time) _logger.debug('q %s', q) df = _market_data_timed(q) return df
def _get_crosscurrency_swap_data( asset1: Asset, asset2: Asset, swap_tenor: str, rateoption_type: str = None, forward_tenor: Optional[GENERIC_DATE] = None, clearing_house: tm_rates._ClearingHouse = None, source: str = None, real_time: bool = False, query_type: QueryType = QueryType.SWAP_RATE, location: PricingLocation = None) -> pd.DataFrame: if real_time: raise NotImplementedError( 'realtime swap_rate not implemented for anything but rates') currency1 = CurrencyEnum( asset1.get_identifier(AssetIdentifier.BLOOMBERG_ID)) currency2 = CurrencyEnum( asset2.get_identifier(AssetIdentifier.BLOOMBERG_ID)) if currency1.value not in CURRENCY_TO_XCCY_SWAP_RATE_BENCHMARK.keys(): raise NotImplementedError( 'Data not available for {} crosscurrency swap rates'.format( currency1.value)) if currency2.value not in CURRENCY_TO_XCCY_SWAP_RATE_BENCHMARK.keys(): raise NotImplementedError( 'Data not available for {} crosscurrency swap rates'.format( currency2.value)) rateoption_type1 = _check_crosscurrency_rateoption_type( currency1, rateoption_type) rateoption_type2 = _check_crosscurrency_rateoption_type( currency2, rateoption_type) if rateoption_type1 != rateoption_type2: raise MqValueError( 'The two currencies do not both support the rate Option type ' + rateoption_type) rateoption_type = rateoption_type1 clearing_house = tm_rates._check_clearing_house(clearing_house) defaults1 = _get_crosscurrency_swap_leg_defaults(currency1, rateoption_type) defaults2 = _get_crosscurrency_swap_leg_defaults(currency2, rateoption_type) if not (tm_rates._is_valid_relative_date_tenor(swap_tenor)): raise MqValueError('invalid swap tenor ' + swap_tenor) if defaults1["pricing_location"] == PricingLocation.NYC: default_location = defaults2["pricing_location"] currency = currency2 else: default_location = defaults1["pricing_location"] currency = currency1 if location is None: pricing_location = PricingLocation(default_location) else: pricing_location = PricingLocation(location) pricing_location = tm_rates._pricing_location_normalized( pricing_location, currency) where = dict(pricingLocation=pricing_location.value) forward_tenor = tm_rates._check_forward_tenor(forward_tenor) fixed_rate = 'ATM' kwargs = dict( asset_class='Rates', type='XccySwapMTM', asset_parameters_termination_date=swap_tenor, asset_parameters_effective_date=forward_tenor, asset_parameters_payer_spread=fixed_rate, # asset_parameters_payer_currency=defaults1['currency'].value, asset_parameters_payer_rate_option=defaults1['rateOption'], # asset_parameters_payer_designated_maturity=defaults1['designatedMaturity'], # asset_parameters_receiver_currency=defaults2['currency'].value, asset_parameters_receiver_rate_option=defaults2['rateOption'], # asset_parameters_receiver_designated_maturity=defaults2['designatedMaturity'], asset_parameters_clearing_house=clearing_house.value, pricing_location=pricing_location) rate_mqid = _get_tdapi_crosscurrency_rates_assets(**kwargs) _logger.debug( f'where asset= {rate_mqid}, swap_tenor={swap_tenor}, forward_tenor={forward_tenor}, ' f'payer_currency={defaults1["currency"].value}, payer_rate_option={defaults1["rateOption"]}, ' f'payer_designated_maturity={defaults1["designatedMaturity"]}, ' f'receiver_currency={defaults2["currency"].value}, receiver_rate_option={defaults2["rateOption"]}, ' f'receiver_designated_maturity={defaults2["designatedMaturity"]}, ' f'clearing_house={clearing_house.value}, pricing_location={pricing_location.value}' ) q = GsDataApi.build_market_data_query([rate_mqid], query_type, where=where, source=source, real_time=real_time) _logger.debug('q %s', q) df = _market_data_timed(q) return df
def _get_inflation_swap_data(asset: Asset, swap_tenor: str, index_type: str = None, forward_tenor: Optional[GENERIC_DATE] = None, clearing_house: tm_rates._ClearingHouse = None, source: str = None, real_time: bool = False, query_type: QueryType = QueryType.SWAP_RATE, location: PricingLocation = None, allow_many=False, request_id: Optional[str] = None) -> pd.DataFrame: if real_time: raise NotImplementedError( 'realtime inflation swap data not implemented') currency = CurrencyEnum(asset.get_identifier(AssetIdentifier.BLOOMBERG_ID)) if currency.value not in CURRENCY_TO_INDEX_BENCHMARK.keys(): raise NotImplementedError( 'Data not available for {} inflation swap rates'.format( currency.value)) index_type = _check_inflation_index_type(currency, index_type) clearing_house = tm_rates._check_clearing_house(clearing_house) defaults = _get_inflation_swap_leg_defaults(currency, index_type) if not (tm_rates._is_valid_relative_date_tenor(swap_tenor)): raise MqValueError('invalid swap tenor ' + swap_tenor) forward_tenor = tm_rates._check_forward_tenor(forward_tenor) fixed_rate = 'ATM' kwargs = dict(asset_class='Rates', type='InflationSwap', asset_parameters_termination_date=swap_tenor, asset_parameters_index=defaults['index_type'], asset_parameters_fixed_rate=fixed_rate, asset_parameters_clearing_house=clearing_house.value, asset_parameters_effective_date=forward_tenor, asset_parameters_notional_currency=currency.name) rate_mqids = _get_tdapi_inflation_rates_assets(allow_many=allow_many, **kwargs) if location is None: pricing_location = tm_rates._default_pricing_location(currency) else: pricing_location = PricingLocation(location) pricing_location = tm_rates._pricing_location_normalized( pricing_location, currency) where = dict(pricingLocation=pricing_location.value) entity_ids = [rate_mqids ] if not isinstance(rate_mqids, list) else rate_mqids _logger.debug( f'where asset= {rate_mqids}, swap_tenor={swap_tenor}, index={defaults["index_type"]}, ' f'forward_tenor={forward_tenor}, pricing_location={pricing_location.value}, ' f'clearing_house={clearing_house.value}, notional_currency={currency.name}, ' f'request_id={request_id}') q = GsDataApi.build_market_data_query(entity_ids, query_type, where=where, source=source, real_time=real_time) _logger.debug(f'q: {q}, request_id: {request_id}') df = _market_data_timed(q) return df