Exemplo n.º 1
0
def inflation_swap_rate(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) -> Series:
    """
    GS end-of-day Zero Coupon Inflation Swap curves across major currencies.

    :param asset: asset object loaded from security master
    :param swap_tenor: relative date representation of expiration date e.g. 1m
    :param index_type: benchmark type e.g. UKRPI
    :param forward_tenor: absolute / relative date representation of forward starting point eg: '1y' or 'Spot' for
            spot starting swaps, 'imm1' or 'frb1'
    :param clearing_house: Example - "LCH", "EUREX", "JSCC", "CME"
    :param source: name of function caller
    :param real_time: whether to retrieve intraday data instead of EOD
    :return: swap rate curve
    """
    df = _get_inflation_swap_data(asset=asset,
                                  swap_tenor=swap_tenor,
                                  index_type=index_type,
                                  forward_tenor=forward_tenor,
                                  clearing_house=clearing_house,
                                  source=source,
                                  real_time=real_time,
                                  query_type=QueryType.SWAP_RATE)

    series = ExtendedSeries() if df.empty else ExtendedSeries(df['swapRate'])
    series.dataset_ids = getattr(df, 'dataset_ids', ())
    return series
Exemplo n.º 2
0
def vol_swap_strike(asset: Asset,
                    expiry_tenor: str,
                    strike_type: str = None,
                    location: PricingLocation = None,
                    *,
                    source: str = None,
                    real_time: bool = False) -> Series:
    """
    GS end-of-day FX Vol Swaps volatilities across major crosses.

    :param asset: asset object loaded from security master
    :param expiry_tenor: relative date representation of expiration date e.g. 1m
    :param strike_type: option type (e.g. Put, Call or Straddle )
    :param location: Example - "TKO", "LDN", "NYC"
    :param source: name of function caller
    :param real_time: whether to retrieve intraday data instead of EOD
    :return: curve of vol swap strike
    """
    df = _get_fx_vol_swap_data(asset=asset,
                               expiry_tenor=expiry_tenor,
                               strike_type=strike_type,
                               location=location,
                               source=source,
                               real_time=real_time,
                               query_type=QueryType.STRIKE_VOL)

    series = ExtendedSeries() if df.empty else ExtendedSeries(df['strikeVol'])
    series.dataset_ids = getattr(df, 'dataset_ids', ())
    return series
Exemplo n.º 3
0
def test_swaption_vol2_return__empty_data():
    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(2019, 1, 2), dt.date(2019, 1, 5)]
    replace('gs_quant.timeseries.measures_rates._market_data_timed', Mock()).return_value = df

    actual = tm_rates.swaption_vol(Currency("GBP", name="GBP"))
    assert_series_equal(ExtendedSeries(), actual)
    replace.restore()
Exemplo n.º 4
0
def test_swaption_vol_smile2_returns_no_data():
    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_smile(Currency("GBP", name="GBP"), '3m', '10y')
    assert_series_equal(ExtendedSeries(), actual)
    replace.restore()
Exemplo n.º 5
0
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()
Exemplo n.º 6
0
def implied_volatility_new(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) -> Series:
    """
    GS end-of-day FX vanilla implied volatilities across major crosses.

    :param asset: asset object loaded from security master
    :param expiry_tenor: relative date representation of expiration date e.g. 1m
    :param strike: option strike
    :param option_type: option type (e.g. Put, Call or Straddle )
    :param expiration_location: location indicating the time of the option expiry
    :param location: Example - "TKO", "LDN", "NYC"
    :param premium_payment_date: payment date of the premium Example: Fwd Settle vs Spot
    :param source: name of function caller
    :param real_time: whether to retrieve intraday data instead of EOD
    :return: swap rate curve
    """

    df = _get_fxo_data(asset=asset,
                       expiry_tenor=expiry_tenor,
                       strike=strike,
                       option_type=option_type,
                       expiration_location=expiration_location,
                       location=location,
                       premium_payment_date=premium_payment_date,
                       source=source,
                       real_time=real_time,
                       query_type=QueryType.IMPLIED_VOLATILITY)

    series = ExtendedSeries() if df.empty else ExtendedSeries(
        df['impliedVolatility'])
    series.dataset_ids = getattr(df, 'dataset_ids', ())
    return series
Exemplo n.º 7
0
def inflation_swap_term(asset: Asset,
                        index_type: str = None,
                        forward_tenor: Optional[GENERIC_DATE] = None,
                        pricing_date: Optional[GENERIC_DATE] = None,
                        clearing_house: tm_rates._ClearingHouse = None,
                        location: PricingLocation = None,
                        *,
                        source: str = None,
                        real_time: bool = False,
                        request_id: Optional[str] = None) -> Series:
    """
    Forward term structure of GS end-of-day inflation swaps.

    :param asset: asset object loaded from security master
    :param index_type: benchmark type e.g. UKRPI
    :param forward_tenor: absolute / relative date representation of forward starting point eg: '1y' or 'Spot' for
            spot starting swaps, 'imm1' or 'frb1'
    :param pricing_date: YYYY-MM-DD or relative date
    :param clearing_house: Example - "LCH", "EUREX", "JSCC", "CME"
    :param location: Example - "TKO", "LDN", "NYC"
    :param source: name of function caller
    :param real_time: whether to retrieve intraday data instead of EOD
    :param request_id: service request id, if any
    :return: inflation swap forward term curve
    """
    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))
    if location is None:
        location = tm_rates._default_pricing_location(currency)
    else:
        location = PricingLocation(location)
    calendar = location.value
    if pricing_date is not None and pricing_date in list(
            GsCalendar.get(calendar).holidays):
        raise MqValueError(
            'Specified pricing date is a holiday in {} calendar'.format(
                calendar))
    start, end = _range_from_pricing_date(calendar, pricing_date)
    with DataContext(start, end):
        df = _get_inflation_swap_data(asset=asset,
                                      swap_tenor=None,
                                      index_type=index_type,
                                      forward_tenor=forward_tenor,
                                      clearing_house=clearing_house,
                                      source=source,
                                      real_time=real_time,
                                      query_type=QueryType.SWAP_RATE,
                                      location=location,
                                      allow_many=True,
                                      request_id=request_id)
    if df.empty:
        series = ExtendedSeries(dtype=float)
    else:
        latest = df.index.max()
        # TODO: add forward tenor to latest. Technically series index should be latest + forwardTenor + terminationTenor
        # TODO: but that would make it hard to compare term structure btwn different forwardTenors
        # TODO: may be implemented some day when plot can handle different x-axes
        # TODO: As-is, this is consistent with other swap term measures axis handling
        _logger.info('selected pricing date %s', latest)
        df = df.loc[latest]
        biz_day = _get_custom_bd(calendar)
        df['expirationDate'] = df['terminationTenor'].apply(
            _get_term_struct_date, args=(latest, biz_day))
        df = df.set_index('expirationDate')
        df.sort_index(inplace=True)
        df = df.loc[DataContext.current.start_date:DataContext.current.
                    end_date]
        series = ExtendedSeries(
            dtype=float) if df.empty else ExtendedSeries(df['swapRate'])
        series.dataset_ids = getattr(df, 'dataset_ids', ())
    if series.empty:  # Raise descriptive error if no data returned + historical date context
        check_forward_looking(None, source, 'inflation_swap_term')
    return series