Skip to content

Commit

Permalink
Chore: Make release 1.0.64
Browse files Browse the repository at this point in the history
  • Loading branch information
martinroberson authored and DominicCYK committed Feb 26, 2024
1 parent 37e11ef commit dc0a5e7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 61 deletions.
28 changes: 1 addition & 27 deletions gs_quant/api/gs/data.py
Expand Up @@ -480,32 +480,6 @@ def get_many_coordinates(
def _to_zulu(cls, d):
return d.strftime('%Y-%m-%dT%H:%M:%SZ')

@classmethod
def _resolve_default_csa_for_builder(cls, builder):
dict_builder = builder.to_dict()
properties = dict_builder.get('properties')

if not properties:
return 'USD-1'

clearing_house = properties.get('clearinghouse')

if 'payccy' in properties:
pay_ccy = properties['payccy']
if pay_ccy == 'USD':
default_csa = 'USD-SOFR'
elif pay_ccy == 'EUR':
default_csa = 'EUR-EUROSTR'
else:
default_csa = pay_ccy + "-1"

if clearing_house and clearing_house != 'LCH':
default_csa = f'CB LCH/{clearing_house.upper()} {default_csa}'

return default_csa
else:
return "USD-1"

@classmethod
def get_mxapi_curve_measure(cls, curve_type=None, curve_asset=None, curve_point=None, curve_tags=None,
measure=None, start_time=None, end_time=None, request_id=None,
Expand Down Expand Up @@ -604,7 +578,7 @@ def get_mxapi_backtest_data(cls, builder, start_time=None, end_time=None, num_sa
end_time = DataContext.current.end_date

if not csa:
csa = cls._resolve_default_csa_for_builder(builder)
csa = 'Default'

if not real_time and not close_location:
close_location = 'NYC'
Expand Down
8 changes: 3 additions & 5 deletions gs_quant/test/timeseries/test_measures.py
Expand Up @@ -411,13 +411,11 @@ def test_swap_rate_calc(mocker):
except MqValueError:
assert True

asset = Currency('MA890', 'EGP')
bbid_mock.return_value = 'EGP'
try:
val = tm_rates.swap_rate_calc(asset, swap_tenor='10y', benchmark_type='SOFR', real_time=True)
assert False
except NotImplementedError:
val = tm_rates.swap_rate_calc(asset, swap_tenor='10y', benchmark_type='SOFR', csa='CME', real_time=True)
assert True
except MqValueError:
assert False

replace.restore()

Expand Down
52 changes: 23 additions & 29 deletions gs_quant/timeseries/measures_rates.py
Expand Up @@ -665,15 +665,15 @@ def _get_swap_data(asset: Asset, swap_tenor: str, benchmark_type: str = None, fl


def _get_swap_data_calc(asset: Asset, swap_tenor: str, benchmark_type: str = None, floating_rate_tenor: str = None,
forward_tenor: Optional[GENERIC_DATE] = None, clearing_house: _ClearingHouse = None,
forward_tenor: Optional[GENERIC_DATE] = None, csa: str = None,
real_time: bool = False, location: PricingLocation = None) -> pd.DataFrame:
currency = CurrencyEnum(asset.get_identifier(AssetIdentifier.BLOOMBERG_ID))

if currency.value not in SUPPORTED_INTRADAY_CURRENCY_TO_DUMMY_SWAP_BBID.keys():
raise NotImplementedError(f'Data not available for {currency.value} calculated swap rates')
benchmark_type = _check_benchmark_type(currency, benchmark_type)

clearing_house = _check_clearing_house(clearing_house)
clearing_house = SwapClearingHouse.LCH
if csa in ['EUREX', 'JSCC', 'CME']:
clearing_house = SwapClearingHouse(csa)

defaults = _get_swap_leg_defaults(currency, benchmark_type, floating_rate_tenor)

Expand All @@ -682,7 +682,7 @@ def _get_swap_data_calc(asset: Asset, swap_tenor: str, benchmark_type: str = Non

forward_tenor = _check_forward_tenor(forward_tenor)

builder = IRSwap(notional_currency=currency, clearing_house=SwapClearingHouse(clearing_house.value),
builder = IRSwap(notional_currency=currency, clearing_house=clearing_house,
floating_rate_designated_maturity=defaults['floating_rate_tenor'],
floating_rate_option=defaults['benchmark_type'],
fixed_rate=0.0, termination_date=swap_tenor)
Expand All @@ -693,7 +693,7 @@ def _get_swap_data_calc(asset: Asset, swap_tenor: str, benchmark_type: str = Non
_logger.debug(f'where builder={builder.as_dict()}')

location = location or PricingLocation.NYC
q = GsDataApi.get_mxapi_backtest_data(builder, close_location=location.value, real_time=real_time)
q = GsDataApi.get_mxapi_backtest_data(builder, close_location=location.value, real_time=real_time, csa=csa)
return q


Expand Down Expand Up @@ -1282,7 +1282,7 @@ def swap_rate(asset: Asset, swap_tenor: str, benchmark_type: str = None, floatin
[MeasureDependency(id_provider=_currency_to_tdapi_swap_rate_asset_for_intraday,
query_type=QueryType.SPOT)])
def swap_rate_calc(asset: Asset, swap_tenor: str, benchmark_type: str = None, floating_rate_tenor: str = None,
forward_tenor: Optional[GENERIC_DATE] = None, clearing_house: _ClearingHouse = _ClearingHouse.LCH,
forward_tenor: Optional[GENERIC_DATE] = None, csa: str = None,
location: PricingLocation = None, *,
source: str = None, real_time: bool = False) -> Series:
"""
Expand All @@ -1296,34 +1296,27 @@ def swap_rate_calc(asset: Asset, swap_tenor: str, benchmark_type: str = None, fl
:param floating_rate_tenor: floating index rate
: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", "CME"
:param csa: Collateral type or clearing house for cleared swaps - set to Default for standard domestic funding.
:param location: Example - "TKO", "LDN", "NYC"
:param source: name of function caller
:param real_time: whether to retrieve intraday data instead of EOD
:return: swap rate curve
"""

df = _get_swap_data_calc(asset=asset, swap_tenor=swap_tenor, benchmark_type=benchmark_type,
floating_rate_tenor=floating_rate_tenor, forward_tenor=forward_tenor,
clearing_house=clearing_house, real_time=real_time, location=location)
csa=csa, real_time=real_time, location=location)

series = ExtendedSeries(dtype=float) if df.empty else ExtendedSeries(df['ATMRate'])
series.dataset_ids = ()
return series


def _csa_default(csa=None, currency=None):
if not csa:
if currency.value in CURRENCY_TO_CSA_DEFAULT_MAP:
csa = CURRENCY_TO_CSA_DEFAULT_MAP[currency.value]
else:
csa = f'{currency.value}-1'
return csa


@plot_measure((AssetClass.Cash,), (AssetType.Currency,),
[MeasureDependency(id_provider=_currency_to_tdapi_swap_rate_asset_for_intraday,
query_type=QueryType.SPOT)])
def forward_rate(asset: Asset, forward_start_tenor: str = None, forward_term: str = None, csa: str = None,
def forward_rate(asset: Asset, forward_start_tenor: str = None, forward_term: str = None,
csa: str = None,
close_location: str = None, *, source: str = None, real_time: bool = False) -> Series:
"""
GS Forward Rate across major currencies.
Expand All @@ -1333,15 +1326,15 @@ def forward_rate(asset: Asset, forward_start_tenor: str = None, forward_term: st
:param asset: asset object loaded from security master
:param forward_start_tenor: Relative date of start of forward e.g. 1y
:param forward_term: Term of forward, e.g. 3m
:param csa: Collateral code of curve, e.g. GBP-1. If not specified, default CSA is chosen
:param csa: Collateral code of curve, e.g. GBP-1. If set to default, default CSA is chosen
:param close_location: For EOD data, gives location of close
:param source: name of function caller
:param real_time: whether to retrieve intra-day data instead of EOD
:return: annualised instantaneous forward rate
"""

currency = CurrencyEnum(asset.get_identifier(AssetIdentifier.BLOOMBERG_ID))
csa = _csa_default(csa, currency)
csa = csa or 'Default'
close_location = close_location or 'NYC'
if not forward_term:
raise MqValueError("Forward rate term not specified")
Expand Down Expand Up @@ -1369,8 +1362,8 @@ def discount_factor(asset: Asset, tenor: str = None, csa: str = None, close_loca
:param asset: asset object loaded from security master
:param tenor: tenor of IFR e.g. 1m
:param csa: Collateral code of curve to fetch IFR, e.g. GBP-1. If not specified, default CSA is chosen
:param tenor: tenor of discount factor e.g. 1m
:param csa: Collateral code of curve to fetch discount factor, e.g. GBP-1. If not specified, default CSA is chosen
:param close_location: For EOD data, gives location of close
:param source: name of function caller
:param real_time: whether to retrieve intra-day data instead of EOD
Expand All @@ -1382,7 +1375,7 @@ def discount_factor(asset: Asset, tenor: str = None, csa: str = None, close_loca
if not tenor:
raise MqValueError("Discount Curve start and end date not specified")

csa = _csa_default(csa, currency)
csa = csa or 'Default'

measure = f'DF:{tenor}'
df = GsDataApi.get_mxapi_curve_measure('DISCOUNT CURVE', currency.value, [], [csa], measure,
Expand All @@ -1396,7 +1389,8 @@ def discount_factor(asset: Asset, tenor: str = None, csa: str = None, close_loca
@plot_measure((AssetClass.Cash,), (AssetType.Currency,),
[MeasureDependency(id_provider=_currency_to_tdapi_swap_rate_asset_for_intraday,
query_type=QueryType.SPOT)])
def instantaneous_forward_rate(asset: Asset, tenor: str = None, csa: str = None, close_location: str = None,
def instantaneous_forward_rate(asset: Asset, tenor: str = None, csa: str = None,
close_location: str = None,
*, source: str = None, real_time: bool = False) -> Series:
"""
GS Floating Rate Benchmark annualised instantaneous forward rates across major currencies.
Expand All @@ -1405,7 +1399,7 @@ def instantaneous_forward_rate(asset: Asset, tenor: str = None, csa: str = None,
:param asset: asset object loaded from security master
:param tenor: tenor of IFR e.g. 1m
:param csa: Collateral code of curve to fetch IFR
:param csa: Collateral code of curve to fetch IFR. Set to default for default collateral
:param close_location: For EOD data, gives location of close
:param source: name of function caller
:param real_time: whether to retrieve intraday data instead of EOD
Expand All @@ -1417,7 +1411,7 @@ def instantaneous_forward_rate(asset: Asset, tenor: str = None, csa: str = None,
if not tenor:
raise MqValueError("Forward rate tenor not specified")

csa = _csa_default(csa, currency)
csa = csa or 'Default'

measure = f'IFR:{tenor}'
df = GsDataApi.get_mxapi_curve_measure('DISCOUNT CURVE', currency.value, [], [csa], measure,
Expand All @@ -1429,8 +1423,8 @@ def instantaneous_forward_rate(asset: Asset, tenor: str = None, csa: str = None,


@plot_measure((AssetClass.Cash,), (AssetType.Currency,),
[MeasureDependency(id_provider=_currency_to_tdapi_swap_rate_asset,
query_type=QueryType.SWAP_RATE)])
[MeasureDependency(id_provider=_currency_to_tdapi_swap_rate_asset_for_intraday,
query_type=QueryType.SPOT)])
def index_forward_rate(asset: Asset, forward_start_tenor: str = None, benchmark_type: str = None,
fixing_tenor: str = None, close_location: str = None, *,
source: str = None, real_time: bool = False) -> Series:
Expand Down

0 comments on commit dc0a5e7

Please sign in to comment.