def test_swaption_swaption_vol_term2_throws(): with pytest.raises(NotImplementedError): tm_rates.swaption_vol_term(Currency("GBP", name="GBP"), tm.SwaptionTenorType.SWAP_MATURITY, '5y', 0, real_time=True)
def test_swaption_swaption_vol_term2_returns_data(): replace = Replacer() df = MarketDataResponseFrame( data=dict(expirationTenor=['1m', '6m', '1y'], terminationTenor=['1y', '2y', '3y'], swaptionVol=[1, 2, 3]), index=_index * 3) replace('gs_quant.timeseries.measures.Asset.get_identifier', Mock()).return_value = "GBP" replace('gs_quant.timeseries.measures_rates._get_tdapi_rates_assets', Mock(), Mock()).return_value = [ "MADWG3WHCKNE1DJA", "MAH6JK3TZJJGFQ65"] replace('gs_quant.timeseries.measures_rates._range_from_pricing_date', Mock(), Mock()).return_value = [ dt.date(2020, 1, 2), dt.date(2020, 1, 2)] replace('gs_quant.timeseries.measures_rates._market_data_timed', Mock()).return_value = df with DataContext('2019-01-01', '2025-01-01'): actual = tm_rates.swaption_vol_term(Currency("GBP", name="GBP"), tm.SwaptionTenorType.SWAP_MATURITY, '5y', 0) expected = pd.Series([1, 2, 3], index=pd.to_datetime(['2019-02-01', '2019-07-01', '2020-01-01'])) assert_series_equal(expected, pd.Series(actual), check_names=False) with DataContext('2019-01-01', '2025-01-01'): actual = tm_rates.swaption_vol_term(Currency("GBP", name="GBP"), tm.SwaptionTenorType.OPTION_EXPIRY, '5y', 0) expected = pd.Series([1, 2, 3], index=pd.to_datetime(['2020-01-01', '2021-01-01', '2021-12-31'])) assert_series_equal(expected, pd.Series(actual), check_names=False) replace.restore()
def test_swaption_swaption_vol_term2_returns_empty(): replace = Replacer() df = ExtendedSeries() replace('gs_quant.timeseries.measures.Asset.get_identifier', Mock()).return_value = "GBP" replace('gs_quant.timeseries.measures_rates._get_tdapi_rates_assets', Mock(), Mock()).return_value = [ "MADWG3WHCKNE1DJA", "MAH6JK3TZJJGFQ65"] replace('gs_quant.timeseries.measures_rates._range_from_pricing_date', Mock(), Mock()).return_value = [ dt.date(2020, 1, 2), dt.date(2020, 1, 2)] replace('gs_quant.timeseries.measures_rates._market_data_timed', Mock()).return_value = df with DataContext('2019-01-01', '2025-01-01'): actual = tm_rates.swaption_vol_term(Currency("GBP", name="GBP"), tm.SwaptionTenorType.SWAP_MATURITY, '5y', 0) assert_series_equal(ExtendedSeries(), actual, check_names=False) replace.restore()