def test_fx_vol_measure_legacy(mocker): replace = Replacer() args = dict(tenor='1m', strike_reference=tm_fxo.VolReference('delta_neutral'), relative_strike=0, location=None, legacy_implementation=True) mock_gbp = Cross('MA26QSMPX9990G66', 'GBPUSD') args['asset'] = mock_gbp expected = tm.ExtendedSeries([1, 2, 3], index=_index * 3, name='impliedVolatility') expected.dataset_ids = _test_datasets mocker.patch.object(tm_rates, 'implied_volatility', return_value=expected) actual = tm_fxo.implied_volatility_fxvol(**args) assert_series_equal(expected, actual) replace.restore() args['legacy_implementation'] = False xrefs = replace('gs_quant.timeseries.measures.Asset.get_identifier', Mock()) xrefs.return_value = None with pytest.raises(MqValueError): tm_fxo.implied_volatility_fxvol(**args) xrefs = replace('gs_quant.timeseries.measures.Asset.get_identifier', Mock()) xrefs.return_value = 'GBPUSD' xrefs = replace('gs_quant.timeseries.measures._cross_stored_direction_helper', Mock()) xrefs.return_value = 'GBPUSD' mocker.patch.object(tm_fxo, 'implied_volatility_new', return_value=expected) actual = tm_fxo.implied_volatility_fxvol(**args) assert_series_equal(expected, actual) xrefs = replace('gs_quant.timeseries.measures.Asset.get_identifier', Mock()) xrefs.return_value = 'USDUSD' xrefs = replace('gs_quant.timeseries.measures_fx_vol._cross_stored_direction_helper', Mock()) xrefs.return_value = 'GBPUSD' assets = replace('gs_quant.markets.securities.SecurityMaster.get_asset', Mock()) assets.return_value = mock_gbp actual = tm_fxo.implied_volatility_fxvol(**args) assert_series_equal(expected, actual) args['strike_reference'] = tm_fxo.VolReference('delta_call') args['relative_strike'] = 25 actual = tm_fxo.implied_volatility_fxvol(**args) assert_series_equal(expected, actual) args['strike_reference'] = tm_fxo.VolReference('delta_put') args['relative_strike'] = 25 actual = tm_fxo.implied_volatility_fxvol(**args) assert_series_equal(expected, actual) args['strike_reference'] = tm_fxo.VolReference('spot') args['relative_strike'] = 100 actual = tm_fxo.implied_volatility_fxvol(**args) assert_series_equal(expected, actual) args['strike_reference'] = tm_fxo.VolReference('forward') args['relative_strike'] = 100 actual = tm_fxo.implied_volatility_fxvol(**args) assert_series_equal(expected, actual) args['strike_reference'] = tm_fxo.VolReference('normalized') args['relative_strike'] = 100 xrefs = replace('gs_quant.timeseries.measures_fx_vol._preprocess_implied_vol_strikes_fx', Mock()) xrefs.return_value = ['normalized', 0] with pytest.raises(MqValueError): tm_fxo.implied_volatility_fxvol(**args) replace.restore()
def test_fx_vol_measure(mocker): replace = Replacer() args = dict( expiry_tenor='1m', strike='ATMF', option_type='Put', expiration_location=None, location=None, premium_payment_date=None, ) mock_gbp = Cross('MA26QSMPX9990G66', 'GBPUSD') args['asset'] = mock_gbp xrefs = replace('gs_quant.timeseries.measures.Asset.get_identifier', Mock()) xrefs.return_value = 'GBPUSD' args['expiry_tenor'] = '1yr' with pytest.raises(MqValueError): tm_fxo.implied_volatility_new(**args) args['expiry_tenor'] = '1m' args['real_time'] = True with pytest.raises(NotImplementedError): tm_fxo.implied_volatility_new(**args) args['real_time'] = False args['asset'] = Cross('MA666', 'USDAED') xrefs = replace('gs_quant.timeseries.measures.Asset.get_identifier', Mock()) xrefs.return_value = 'AEDUSD' with pytest.raises(NotImplementedError): tm_fxo.implied_volatility_new(**args) args['asset'] = mock_gbp args['asset'] = Bond('MA667', 'TEST') with pytest.raises(NotImplementedError): tm_fxo.implied_volatility_new(**args) args['asset'] = mock_gbp args['asset'] = Cross('MA667', 'GBPUSD') xrefs = replace('gs_quant.timeseries.measures.Asset.get_identifier', Mock()) xrefs.return_value = 'GBPUSD' identifiers = replace( 'gs_quant.timeseries.measures_fx_vol._get_tdapi_fxo_assets', Mock()) identifiers.return_value = {'MA7F5P92330NGKAR'} mocker.patch.object(GsDataApi, 'get_market_data', return_value=mock_curr(None, None)) actual = tm_fxo.implied_volatility_new(**args) expected = tm.ExtendedSeries([1, 2, 3], index=_index * 3, name='impliedVolatility') expected.dataset_ids = _test_datasets assert_series_equal(expected, actual) assert actual.dataset_ids == _test_datasets args['asset'] = Cross('MA667', 'USDCAD') args['location'] = PricingLocation.LDN args['premium_payment_date'] = 'Fwd Settle' args['expiration_location'] = 'NYC' xrefs = replace('gs_quant.timeseries.measures.Asset.get_identifier', Mock()) xrefs.return_value = 'USDCAD' identifiers = replace( 'gs_quant.timeseries.measures_fx_vol._get_tdapi_fxo_assets', Mock()) identifiers.return_value = {'MA7F5P92330NGKAR'} mocker.patch.object(GsDataApi, 'get_market_data', return_value=mock_curr(None, None)) actual = tm_fxo.implied_volatility_new(**args) expected = tm.ExtendedSeries([1, 2, 3], index=_index * 3, name='impliedVolatility') expected.dataset_ids = _test_datasets assert_series_equal(expected, actual) assert actual.dataset_ids == _test_datasets args['option_type'] = 'Call' xrefs = replace('gs_quant.timeseries.measures.Asset.get_identifier', Mock()) xrefs.return_value = 'GBPUSD' identifiers = replace( 'gs_quant.timeseries.measures_fx_vol._get_tdapi_fxo_assets', Mock()) identifiers.return_value = {'MA7F5P92330NGKAR'} mocker.patch.object(GsDataApi, 'get_market_data', return_value=mock_curr(None, None)) actual = tm_fxo.implied_volatility_new(**args) expected = tm.ExtendedSeries([1, 2, 3], index=_index * 3, name='impliedVolatility') expected.dataset_ids = _test_datasets assert_series_equal(expected, actual) assert actual.dataset_ids == _test_datasets replace.restore()
def test_crosscurrency_swap_rate(mocker): replace = Replacer() args = dict(swap_tenor='5y', rateoption_type='LIBOR', clearing_house='LCH', forward_tenor='5y', real_time=False) mock_gbp = Currency('MA26QSMPX9990G66', 'GBP') args['asset'] = mock_gbp xrefs = replace('gs_quant.timeseries.measures.Asset.get_identifier', Mock()) xrefs.return_value = 'GBP' xrefs = replace('gs_quant.timeseries.measures.SecurityMaster.get_asset', Mock()) mock_usd = Currency('MA26QSMPX9990G63', 'USD') xrefs.return_value = mock_usd args['swap_tenor'] = '5yr' with pytest.raises(MqValueError): tm.crosscurrency_swap_rate(**args) args['swap_tenor'] = '5y' args['forward_tenor'] = '5yr' with pytest.raises(MqValueError): tm.crosscurrency_swap_rate(**args) args['forward_tenor'] = '5y' args['real_time'] = True with pytest.raises(NotImplementedError): tm.crosscurrency_swap_rate(**args) args['real_time'] = False args['asset'] = Currency('MA666', 'AED') xrefs = replace('gs_quant.timeseries.measures.Asset.get_identifier', Mock()) xrefs.return_value = 'AED' with pytest.raises(NotImplementedError): tm.crosscurrency_swap_rate(**args) args['asset'] = mock_gbp args['asset'] = Bond('MA667', 'TEST') with pytest.raises(MqValueError): tm.crosscurrency_swap_rate(**args) args['asset'] = mock_gbp args['asset'] = Cross('MA667', 'USDAED') xrefs = replace('gs_quant.timeseries.measures.Asset.get_identifier', Mock()) xrefs.side_effect = ['AED', 'USD'] with pytest.raises(NotImplementedError): tm.crosscurrency_swap_rate(**args) args['asset'] = Cross('MA667', 'USDAED') xrefs = replace('gs_quant.timeseries.measures.Asset.get_identifier', Mock()) xrefs.side_effect = ['USD', 'AED'] with pytest.raises(NotImplementedError): tm.crosscurrency_swap_rate(**args) args['asset'] = Cross('MA667', 'USDGBP') xrefs = replace('gs_quant.timeseries.measures.Asset.get_identifier', Mock()) xrefs.return_value = 'GBP' xrefs = replace('gs_quant.timeseries.measures_xccy._check_crosscurrency_rateoption_type', Mock()) xrefs.side_effect = [tm.CrossCurrencyRateOptionType.LIBOR, tm.CrossCurrencyRateOptionType.OIS] with pytest.raises(MqValueError): tm.crosscurrency_swap_rate(**args) replace.restore() xrefs = replace('gs_quant.timeseries.measures.SecurityMaster.get_asset', Mock()) xrefs.return_value = mock_usd args['asset'] = Cross('MA667', 'USDGBP') xrefs = replace('gs_quant.timeseries.measures.Asset.get_identifier', Mock()) xrefs.return_value = 'GBP' identifiers = replace('gs_quant.timeseries.measures_xccy._get_tdapi_crosscurrency_rates_assets', Mock()) identifiers.return_value = {'MA26QSMPX9990G66'} mocker.patch.object(GsDataApi, 'get_market_data', return_value=mock_curr(None, None)) actual = tm.crosscurrency_swap_rate(**args) expected = tm.ExtendedSeries([1, 2, 3], index=_index * 3, name='xccySwapSpread') expected.dataset_ids = _test_datasets assert_series_equal(expected, actual) assert actual.dataset_ids == _test_datasets args['asset'] = Cross('MA667', 'USDCAD') xrefs = replace('gs_quant.timeseries.measures.Asset.get_identifier', Mock()) xrefs.return_value = 'CAD' identifiers = replace('gs_quant.timeseries.measures_xccy._get_tdapi_crosscurrency_rates_assets', Mock()) identifiers.return_value = {'MA26QSMPX9990G66'} mocker.patch.object(GsDataApi, 'get_market_data', return_value=mock_curr(None, None)) actual = tm.crosscurrency_swap_rate(**args) expected = tm.ExtendedSeries([1, 2, 3], index=_index * 3, name='xccySwapSpread') expected.dataset_ids = _test_datasets assert_series_equal(expected, actual) assert actual.dataset_ids == _test_datasets args['asset'] = mock_gbp xrefs = replace('gs_quant.timeseries.measures.Asset.get_identifier', Mock()) xrefs.return_value = 'GBP' args['rateoption_type'] = tm.CrossCurrencyRateOptionType.TestRateOption with pytest.raises(MqValueError): tm.crosscurrency_swap_rate(**args) args['rateoption_type'] = tm.CrossCurrencyRateOptionType.LIBOR xrefs = replace('gs_quant.timeseries.measures.Asset.get_identifier', Mock()) xrefs.return_value = 'GBP' identifiers = replace('gs_quant.timeseries.measures_xccy._get_tdapi_crosscurrency_rates_assets', Mock()) identifiers.return_value = {'MA26QSMPX9990G66'} mocker.patch.object(GsDataApi, 'get_market_data', return_value=mock_curr(None, None)) actual = tm.crosscurrency_swap_rate(**args) expected = tm.ExtendedSeries([1, 2, 3], index=_index * 3, name='xccySwapSpread') expected.dataset_ids = _test_datasets assert_series_equal(expected, actual) assert actual.dataset_ids == _test_datasets xrefs = replace('gs_quant.timeseries.measures.Asset.get_identifier', Mock()) xrefs.return_value = 'EUR' identifiers = replace('gs_quant.timeseries.measures_xccy._get_tdapi_crosscurrency_rates_assets', Mock()) identifiers.return_value = {'MAZBW57ZPS54ET7K'} mocker.patch.object(GsDataApi, 'get_market_data', return_value=mock_curr(None, None)) args['asset'] = Currency('MAZBW57ZPS54ET7K', 'EUR') args['rateoption_type'] = 'OIS' actual = tm.crosscurrency_swap_rate(**args) expected = tm.ExtendedSeries([1, 2, 3], index=_index * 3, name='xccySwapSpread') expected.dataset_ids = _test_datasets assert_series_equal(expected, actual) assert actual.dataset_ids == _test_datasets replace.restore()