From 6519260d64c79ff42c2de5f605fa36f16694b9ec Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Wed, 20 Dec 2023 19:38:04 +0100 Subject: [PATCH 01/14] BUG: DF for FRA is measured as of payment date. --- docs/source/index.rst | 34 ++++++++++++++++++++++++++++ rateslib/instruments.py | 50 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/docs/source/index.rst b/docs/source/index.rst index 66ed5e18..eeb323ad 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -109,9 +109,43 @@ to fully capture the nuances of these products across sectors and geographic reg capturing aspects like trading calendars, day count conventions, payment delays, etc. New specifications and calendars are continually being added as users enquire. +.. list-table:: Instrument classes available + :widths: 30 23 27 20 + :header-rows: 1 + + * - **Derivatives** + - **Multi-currency** + - **Index-linked** + - **Securities** + * - :class:`Interest rate swap (IRS) ` + - :class:`Cross-ccy swap (XCS) ` + - :class:`ZC inflation swap (ZCIS) ` + - :class:`Fixed rate bond ` + * - :class:`Forward rate agreement (FRA) ` + - :class:`FX swap ` + - :class:`Inflation swap (IIRS) ` + - :class:`Floating rate note ` + * - :class:`Single-ccy basis swap (SBS) ` + - :class:`FX exchange ` + - :class:`Index-linked bond ` + - :class:`Bill ` + * - :class:`Zero coupon swap (ZCS) ` + - + - + - :class:`Bond future ` + * - :class:`STIR future ` + - + - + - + A good example is a **US Treasury Bond**, replicated here with *rateslib* and the equivalent ticket in Bloomberg for reference point. +.. ipython:: python + :suppress: + + from rateslib import * + .. ipython:: python ust = FixedRateBond( diff --git a/rateslib/instruments.py b/rateslib/instruments.py index d1405488..7e121d3e 100644 --- a/rateslib/instruments.py +++ b/rateslib/instruments.py @@ -26,6 +26,7 @@ import abc import warnings from functools import partial +from textwrap import dedent # from math import sqrt @@ -5076,6 +5077,32 @@ class IRS(BaseDerivative): _fixed_rate_mixin = True _leg2_float_spread_mixin = True + @classmethod + def example(cls): + print(dedent("""\ + Broker confirmation: + 'You Paid $100mm 5Y USD SOFR IRS at 2.5% with 5d observation shift and normal conventions.' + + Rateslib configuration: + IRS( + effective=dt(2023, 12, 20), + termination="5y", # effective and termination dates required. + frequency="a", + calendar="nyc", + modifier="mf", + roll=20, # schedule configuration + currency="usd", + notional=100e6, # currency and notional + convention="act360", + leg2_fixing_method="rfr_observation_shift", + leg2_method_param=5, + # leg2_fixings=NoInput(0), + fixed_rate=2.50 # pricing parameters + # spec=NoInput(0), # possible auto-defined IRS exist in defaults. + # curves=usdusd, # curves for forecasting and discounting each leg optional. + ) + """)) + def __init__( self, *args, @@ -7662,6 +7689,29 @@ class FXSwap(XCS): _unpriced = True + @classmethod + def example(cls): + print(dedent("""\ + Broker confirmation: + 'You Paid 3M USDEUR FX Swap in $100mm/€105mm (split notional $101.5mm) at -305.5 points.' + + Rateslib configuration: + FXSwap( + effective=dt(2023, 12, 20), + termination="3m", # effective and termination dates required. + calendar="nyc,tgt", + modifier="mf", # calendar and modifier to determine termination. + currency="usd", + leg2_currency="eur", # currencies are specified directly in lowercase. + notional=-100e6, + split_notional=-101.5e6, + fx_fixings=1.05, + points=-305.5, # all pricing parameters are defined + # spec=NoInput(0), # possible auto-defined FXSwaps exist in defaults. + # curves=[None, usdusd, None, eurusd], # curves for discounting each leg optional. + ) + """)) + def _parse_split_flag(self, fx_fixings, points, split_notional): """ Determine the rules for a priced, unpriced or partially priced derivative and whether From 42140e9606a0a713b6f32431fe688dae4caf143e Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Thu, 21 Dec 2023 17:34:06 +0100 Subject: [PATCH 02/14] BUG: DF for FRA is measured as of payment date. --- docs/source/i_whatsnew.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/i_whatsnew.rst b/docs/source/i_whatsnew.rst index a0992b2f..f1a7cb1f 100644 --- a/docs/source/i_whatsnew.rst +++ b/docs/source/i_whatsnew.rst @@ -63,7 +63,7 @@ email contact through **rateslib@gmail.com**. * - Feature - Description * - Bug - - :class:`~rateslib.instruments.FRA.cashflows` now correctly identifies the DF at cash + - FRA :class:`~rateslib.instruments.FRA.cashflows` now correctly identifies the DF at cash settled payment date. From e134d170710bca00e4b6a98b3ed9770c3665a4dd Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Sun, 24 Dec 2023 20:19:06 +0100 Subject: [PATCH 03/14] Add FX Exchange --- docs/source/i_whatsnew.rst | 6 ++++++ rateslib/instruments.py | 32 +++++++++++++++++++++++++++++++- tests/test_instruments.py | 10 +++++----- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/docs/source/i_whatsnew.rst b/docs/source/i_whatsnew.rst index f1a7cb1f..0996e7c8 100644 --- a/docs/source/i_whatsnew.rst +++ b/docs/source/i_whatsnew.rst @@ -62,6 +62,12 @@ email contact through **rateslib@gmail.com**. * - Feature - Description + * - Instruments + - Reverse the notional direction of :class:`~rateslib.instruments.FXExchange` to be more + intuitive. + * - Instruments + - Add a class method: :meth:`~rateslib.instruments.IRS.example` to each *Instrument* to + provide a more intuitive way to initialise. * - Bug - FRA :class:`~rateslib.instruments.FRA.cashflows` now correctly identifies the DF at cash settled payment date. diff --git a/rateslib/instruments.py b/rateslib/instruments.py index 7e121d3e..edb93aaf 100644 --- a/rateslib/instruments.py +++ b/rateslib/instruments.py @@ -842,6 +842,19 @@ def __init__( self.effective = effective self.curves = curves + @classmethod + def example(cls): + print(dedent("""\ + Description: + 'A pseudo-instrument to return a curve value.' + + Rateslib configuration: + Value( + effective=dt(2023, 12, 20), + # curves=usdusd, # curve for extracting the value + ) + """)) + def rate( self, curves: Union[Curve, str, list, NoInput] = NoInput(0), @@ -911,7 +924,7 @@ def __init__( self.settlement = settlement self.pair = f"{currency.lower()}{leg2_currency.lower()}" self.leg1 = Cashflow( - notional=defaults.notional if notional is NoInput.blank else notional, + notional=-defaults.notional if notional is NoInput.blank else -notional, currency=currency.lower(), payment=settlement, stub_type="Exchange", @@ -926,6 +939,23 @@ def __init__( ) self.fx_rate = fx_rate + @classmethod + def example(cls): + print(dedent("""\ + Broker confirmation: + 'You Bought $100mm Selling €105mm for settlement 16th March 2023.' + + Rateslib configuration: + FXExchange( + settlement=dt(2023, 3, 16), + currency="usd", + leg2_currency="eur", + fx_rate=1.05, + notional=100e6, + # curves=usdusd, # curves for forecasting and discounting each leg optional. + ) + """)) + @property def fx_rate(self): return self._fx_rate diff --git a/tests/test_instruments.py b/tests/test_instruments.py index a2e36838..ee7a6b1c 100644 --- a/tests/test_instruments.py +++ b/tests/test_instruments.py @@ -508,7 +508,7 @@ class TestNullPricing: currency="eur", leg2_currency="usd", curves=["eureur", "eureur", "usdusd", "usdusd"], - notional=1e6 * 25 / 74.27, + notional=-1e6 * 25 / 74.27, ), ], ) @@ -1198,9 +1198,9 @@ def test_cashflows(self): "Period": ["Exchange", "Exchange"], "Ccy": ["EUR", "USD"], "Payment": [dt(2022, 10, 1), dt(2022, 10, 1)], - "Notional": [1e6, -2050000.0], + "Notional": [-1e6, 2050000.0], "Rate": [None, 2.05], - "Cashflow": [-1e6, 2050000.0], + "Cashflow": [1e6, -2050000.0], }, index=MultiIndex.from_tuples([("leg1", 0), ("leg2", 0)]) ) @@ -1252,7 +1252,7 @@ def test_npv_fx_numeric(self, curve): # result_ = fxe.npv([curve] * 4, fx=2.0, local=True) with pytest.warns(UserWarning): result = fxe.npv([curve] * 4, fx=2.0) - expected = -993433.103425 * 2.0 + 1200080.27069 + expected = 993433.103425 * 2.0 - 1200080.27069 assert abs(result - expected) < 1e-5 # with pytest.raises(ValueError, match="Cannot calculate `npv`"): @@ -2876,7 +2876,7 @@ def test_xcs(self): ), ( FXExchange(dt(2022, 1, 15), currency="eur", leg2_currency="usd", curves=["eureur", "eureur", "usdusd", "usdeur"]), - DataFrame([[-1000000.0, 1101072.93429]], + DataFrame([[1000000.0, -1101072.93429]], index=Index([dt(2022, 1, 15)], name="payment"), columns=MultiIndex.from_tuples([("EUR", "eur"), ("USD", "eur")], names=["local_ccy", "collateral_ccy"]) From c843763f9615e4a0b4178c08d85cb0f46d3f7d50 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Sun, 24 Dec 2023 20:23:16 +0100 Subject: [PATCH 04/14] Add FX Exchange --- rateslib/instruments.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/rateslib/instruments.py b/rateslib/instruments.py index edb93aaf..f300e97e 100644 --- a/rateslib/instruments.py +++ b/rateslib/instruments.py @@ -943,7 +943,7 @@ def __init__( def example(cls): print(dedent("""\ Broker confirmation: - 'You Bought $100mm Selling €105mm for settlement 16th March 2023.' + 'You Bought $100mm Selling €105mm (USDEUR 1.05) for settlement 16th March 2023.' Rateslib configuration: FXExchange( @@ -952,7 +952,7 @@ def example(cls): leg2_currency="eur", fx_rate=1.05, notional=100e6, - # curves=usdusd, # curves for forecasting and discounting each leg optional. + # curves=[None, usdusd, None, eurusd], # curves for discounting each currency. ) """)) @@ -2320,6 +2320,23 @@ def __init__( # self.notional which is currently assumed to be a fixed quantity raise NotImplementedError("`amortization` for FixedRateBond must be zero.") + @classmethod + def example(cls): + print(dedent("""\ + Broker confirmation: + 'You Bought $100mm Selling €105mm (USDEUR 1.05) for settlement 16th March 2023.' + + Rateslib configuration: + FXExchange( + settlement=dt(2023, 3, 16), + currency="usd", + leg2_currency="eur", + fx_rate=1.05, + notional=100e6, + # curves=[None, usdusd, None, eurusd], # curves for discounting each currency. + ) + """)) + # Licence: Creative Commons - Attribution-NonCommercial-NoDerivatives 4.0 International # Commercial use of this code, and/or copying and redistribution is prohibited. # Contact rateslib at gmail.com if this code is observed outside its intended sphere. From e3f3e7077f56d6bdb36a9695c0aa5b9d1f28ca70 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (MBP)" Date: Sat, 30 Dec 2023 08:56:18 +0100 Subject: [PATCH 05/14] BUG: upload file and correct docs --- rateslib/__init__.py | 22 ++++++++++++++++++++++ rateslib/instruments.py | 27 +++++++++++++++++++++++++++ tests/test_instruments.py | 8 +++++++- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/rateslib/__init__.py b/rateslib/__init__.py index ec952dff..a44aca46 100644 --- a/rateslib/__init__.py +++ b/rateslib/__init__.py @@ -116,6 +116,28 @@ def __exit__(self, *args) -> None: Portfolio, ) +Instruments = [ + Value, + Bill, + FixedRateBond, + IndexFixedRateBond, + FloatRateNote, + BondFuture, + IRS, + STIRFuture, + IIRS, + ZCS, + ZCIS, + FRA, + SBS, + FXSwap, + FXExchange, + XCS, + Spread, + Fly, + Portfolio, +] + # module level doc-string __doc__ = """ RatesLib - An efficient and interconnected fixed income library for Python diff --git a/rateslib/instruments.py b/rateslib/instruments.py index f300e97e..50a13723 100644 --- a/rateslib/instruments.py +++ b/rateslib/instruments.py @@ -6107,6 +6107,33 @@ def __init__( self.leg1 = ZeroFixedLeg(**_get(self.kwargs, leg=1)) self.leg2 = ZeroFloatLeg(**_get(self.kwargs, leg=2)) + @classmethod + def example(cls): + print(dedent("""\ + Broker confirmation: + 'You Received £100mm 15Y ZCS effective 16th March 2023 at IRR of 2.15% (under Act365F), + compounding annually.' + + Rateslib configuration: + ZCS( + effective=dt(2023, 3, 16), + termination="15Y", # effective and termination dates required. + frequency="A", + modifier="mf", + eom=True, + calendar="ldn", # schedule configuration + currency="gbp", + notional=-100e6, # currency and notional + convention="act365f", + fixed_rate=2.15, + leg2_fixing_method="rfr_payment_delay", + # leg2_fixings=NoInput(0), + leg2_method_param=0, # pricing parameters + # curves=gbpgbp, # curves for forecasting and discounting each leg. + # spec=NoInput(0), # possible auto-defined IRS exist in defaults. + ) + """)) + def analytic_delta(self, *args, **kwargs): """ Return the analytic delta of a leg of the derivative object. diff --git a/tests/test_instruments.py b/tests/test_instruments.py index ee7a6b1c..c534e448 100644 --- a/tests/test_instruments.py +++ b/tests/test_instruments.py @@ -5,7 +5,7 @@ import numpy as np import context -from rateslib import defaults, default_context +from rateslib import defaults, default_context, Instruments from rateslib.default import NoInput from rateslib.instruments import ( FixedRateBond, @@ -2959,3 +2959,9 @@ def test_fx_settlements_table_no_fxf(): result = irs_mkt.cashflows_table(solver=solver) assert abs(result.iloc[0, 0] - 69.49810) < 1e-5 assert abs(result.iloc[3, 0] - 69.49810) < 1e-5 + + +@pytest.mark.parametrize("Inst", [Inst for Inst in Instruments]) +def test_examples(Inst): + assert getattr(Inst, "example", None) is not None + # test an example function is written for the class \ No newline at end of file From d31254a52c3bed11ec8a6e7b14d5e58e3b66375b Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Sat, 3 Feb 2024 10:26:08 +0100 Subject: [PATCH 06/14] edit --- docs/source/i_whatsnew.rst | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/source/i_whatsnew.rst b/docs/source/i_whatsnew.rst index 38ea66c6..1b8e8f6f 100644 --- a/docs/source/i_whatsnew.rst +++ b/docs/source/i_whatsnew.rst @@ -60,9 +60,6 @@ email contact through **rateslib@gmail.com**. * - Instruments - Add a class method: :meth:`~rateslib.instruments.IRS.example` to each *Instrument* to provide a more intuitive way to initialise. - * - Bug - - FRA :class:`~rateslib.instruments.FRA.cashflows` now correctly identifies the DF at cash - settled payment date. 1.0.0 (1st Feb 2024) From d664ca36afb7e1e05edc7eb83f57d5a505e7537e Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Sat, 3 Feb 2024 15:32:55 +0100 Subject: [PATCH 07/14] edit --- rateslib/instruments.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/rateslib/instruments.py b/rateslib/instruments.py index 2b0fb61f..ba9f5cd9 100644 --- a/rateslib/instruments.py +++ b/rateslib/instruments.py @@ -2344,16 +2344,27 @@ def __init__( def example(cls): print(dedent("""\ Broker confirmation: - 'You Bought $100mm Selling €105mm (USDEUR 1.05) for settlement 16th March 2023.' + 'You Bought $100mm 3.875% Aug-33 US Treasury Bond.' Rateslib configuration: - FXExchange( - settlement=dt(2023, 3, 16), + FixedRateBond( + effective=dt(2022, 8, 15) + termination=dt(2033, 8, 15), # effective and termination dates required. + frequency="s", + calendar="nyc", + modifier="none", + payment_lag=0, + payment_lag_exchange=0, + roll=15, # schedule configuration currency="usd", - leg2_currency="eur", - fx_rate=1.05, - notional=100e6, - # curves=[None, usdusd, None, eurusd], # curves for discounting each currency. + notional=-100e6, # currency and notional + convention="ActActICMA", + settle=1, + ex_div=1, + calc_mode="ust", + fixed_rate=3.875 # pricing parameters + # spec=NoInput(0), # possible auto-defined US Treasury exist in defaults. + # curves=usdusd, # curves for forecasting and discounting each leg optional. ) """)) From 2d9436712d32180a4eb3d17adc9ed6648dc72303 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Sat, 3 Feb 2024 15:48:56 +0100 Subject: [PATCH 08/14] edit --- rateslib/instruments.py | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/rateslib/instruments.py b/rateslib/instruments.py index ba9f5cd9..34f773fd 100644 --- a/rateslib/instruments.py +++ b/rateslib/instruments.py @@ -3198,6 +3198,29 @@ def __init__( spec=spec, ) + @classmethod + def example(cls): + print(dedent("""\ + Broker confirmation: + 'You Bought $20mm 19-Feb-2004 US T-Bill.' + + Rateslib configuration: + bill = Bill( + effective=dt(2004, 1, 22), + termination=dt(2004, 2, 19), # effective and termination dates required. + calendar="nyc", + modifier="none", + payment_lag=0, # schedule control + currency="usd", + notional=-20e6, # negative notional receives fixed, i.e. buys a bill + convention="Act360", + settle=1, + calc_mode="ustb", # pricing parameters + # spec=NoInput(0), # possible auto-defined US T Bill exist in defaults. + # curves=usdusd, # curves for forecasting and discounting each leg optional. + ) + """)) + @property def dcf(self): # bills will typically have 1 period since they are configured with frequency "z". @@ -3595,6 +3618,37 @@ def __init__( # self.notional which is currently assumed to be a fixed quantity raise NotImplementedError("`amortization` for FloatRateNote must be zero.") + @classmethod + def example(cls): + print(dedent("""\ + Broker confirmation: + 'You Bought $10mm 25-Aug-27 Quarterly FRN at SOFR (5d shift) + 100bps.' + + Rateslib configuration: + FloatRateNote( + effective=dt(2022, 8, 25) + termination=dt(2027, 8, 25), # effective and termination dates required. + frequency="q", + calendar="nyc", + modifier="none", + payment_lag=0, + payment_lag_exchange=0, + roll=25, # schedule configuration + currency="usd", + notional=-10e6, # currency and notional + convention="ActActICMA", + settle=1, + ex_div=1, + spread_compound_method="none_simple", + fixing_method="rfr_observation_shift", + method_param=5, + # fixings=NoInput(0), + float_spread=100.0 # pricing parameters + # spec=NoInput(0), # possible auto-defined FRN types exist in defaults. + # curves=usdusd, # curves for forecasting and discounting each leg optional. + ) + """)) + def _accrual_rate(self, pseudo_period, curve, method_param): """ Take a period and try to forecast the rate which determines the accrual, From 3e9671e5aa53075989142c308713a57ea2686ebd Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Sun, 4 Feb 2024 14:45:45 +0100 Subject: [PATCH 09/14] change specs --- docs/source/g_instruments.rst | 126 ++++++++++++++++++++++++ rateslib/_spec_loader.py | 2 + rateslib/data/__instrument_spec.csv | 146 ++++++++++++++-------------- tests/test_instruments.py | 19 +++- 4 files changed, 218 insertions(+), 75 deletions(-) diff --git a/docs/source/g_instruments.rst b/docs/source/g_instruments.rst index 7b6f8915..ab3c7a31 100644 --- a/docs/source/g_instruments.rst +++ b/docs/source/g_instruments.rst @@ -1,5 +1,10 @@ .. _instruments-toc-doc: +.. ipython:: python + :suppress: + + from rateslib import * + ************ Instruments ************ @@ -50,3 +55,124 @@ The below example demonstrates this composition when creating an :class:`~ratesl # Each leg contains a list of Periods. irs.leg1.periods irs.leg2.periods + + +Examples of Every Instrument +****************************** + +IRS +---- + +Suppose *"You Paid $100mm 5Y USD SOFR IRS at 2.5% with normal conventions including +2d payment delay."* + +.. ipython:: python + + irs = IRS( + effective=dt(2023, 12, 20), + termination="5y", # effective and termination dates required. + frequency="a", + calendar="nyc", + modifier="mf", + payment_lag=2, + roll=20, # schedule configuration + currency="usd", + notional=100e6, # currency and notional + convention="act360", + leg2_fixing_method="rfr_payment_delay", + leg2_method_param=NoInput(0), # not required + leg2_fixings=NoInput(0), # not required + fixed_rate=2.50, # pricing parameters + spec=NoInput(0), # not required: possible auto-defined IRS exist in defaults. + curves=NoInput(0), # not required + ) + +**Available** ``spec`` **defaults:** + +.. container:: twocol + + .. container:: leftside40 + + RFR based swaps: + + - "usd_irs": SOFR swap + - "eur_irs": ESTR swap + - "gbp_irs": SONIA swap + - "sek_irs": SWESTR swap + - "nok_irs": NOWA swap + - "chf_irs": SARON swap + + .. container:: rightside60 + + IBOR based swaps: + + - "eur_irs3": Euribor 3m swap + - "eur_irs6": Euribor 6m swap + - "eur_irs1": Euribor 1m swap + - "sek_irs3": Stibor 3m swap + - "nok_irs3": Nibor 3m swap + - "nok_irs6": Nibor 6m swap + +.. raw:: html + +
+ + +FRA +--- + +Suppose *"You Paid 500m 1x4 28th FRA in EUR at 2.5%".* + +.. ipython:: python + + fra = FRA( + effective=dt(2022, 2, 28), + termination="3m", + frequency="q", + roll=28, + eom=False, + modifier="mf", + calendar="tgt", + payment_lag=0, + notional=500e6, + currency="eur", + convention="act360", + method_param=2, + fixed_rate=2.50, + fixings=NoInput(0), + curves=["euribor3m", "estr"], + spec=NoInput(0), + ) + +**Available** ``spec`` **defaults:** + +- "eur_fra3": Euribor 3M FRA +- "eur_fra6": Euribor 6M FRA +- "sek_fra3": Stibor 3M FRA + +FXSwap +------- + +Suppose *"You Paid 3M EURUSD FX Swap in €100mm/$105mm (split notional €101.5mm) at +40.2 points."* + +.. ipython:: python + + fxs = FXSwap( + effective=dt(2023, 12, 20), + termination="3m", # effective and termination dates required. + calendar="nyc,tgt", + modifier="mf", # calendar and modifier to determine termination. + currency="eur", + leg2_currency="usd", # currencies are specified directly in lowercase. + notional=-100e6, + split_notional=-101.5e6, # split notional defined explicitly. + fx_fixings=1.05, + points=40.2, # all pricing parameters are defined + spec=NoInput(0), # not required. + curves=[None, "eurusd", None, "usdusd"], # curves for discounting each leg optional. + ) + +**Available** ``spec`` **defaults:** + +- "eurusd_fxs": EUR/USD FX swap +- "gbpusd_fxs": GBP/USD FX swap diff --git a/rateslib/_spec_loader.py b/rateslib/_spec_loader.py index 51cbbefa..cff58cb5 100644 --- a/rateslib/_spec_loader.py +++ b/rateslib/_spec_loader.py @@ -107,6 +107,8 @@ def _get_kwargs(spec): "eurusd_xcs": _get_kwargs("eurusd_xcs"), # XCS "gbpusd_xcs": _get_kwargs("gbpusd_xcs"), "eurgbp_xcs": _get_kwargs("eurgbp_xcs"), + "eurusd_fxs": _get_kwargs("eurusd_fxs"), # FXS + "gbpusd_fxs": _get_kwargs("gbpusd_fxs"), "eur_zcis": _get_kwargs("eur_zcis"), # ZCIS "gbp_zcis": _get_kwargs("gbp_zcis"), "usd_zcis": _get_kwargs("usd_zcis"), diff --git a/rateslib/data/__instrument_spec.csv b/rateslib/data/__instrument_spec.csv index 53a716ab..a694371f 100644 --- a/rateslib/data/__instrument_spec.csv +++ b/rateslib/data/__instrument_spec.csv @@ -1,73 +1,73 @@ -kind,leg,kwarg,dtype,test,usd_irs,gbp_irs,eur_irs,sek_irs,nok_irs,chf_irs,eur_irs6,eur_irs3,eur_irs1,sek_irs3,nok_irs3,nok_irs6,eurusd_xcs,gbpusd_xcs,eurgbp_xcs,eur_zcis,gbp_zcis,usd_zcis,gbp_zcs,sek_iirs,eur_sbs36,usd_gb,gbp_gb,gbp_gbi,sek_gb,cad_gb,usd_gbb,sek_gbb,sek_fra3,eur_fra3,eur_fra6,usd_frn5,usd_stir,usd_stir1,eur_stir,eur_stir1,eur_stir3,gbp_stir -meta,meta,currency,str,TES,usd,gbp,eur,sek,nok,chf,eur,eur,eur,sek,nok,nok,eur/usd,gbp/usd,gbp/usd,eur,gbp,usd,gbp,sek_iirs,eur,usd,gbp,gbp,sek,cad,usd,sek,sek,eur,eur,usd,usd,usd,eur,eur,eur,gbp -meta,meta,instrument,str,none,irs,irs,irs,irs,irs,irs,irs,irs,irs,irs,irs,irs,xcs,xcs,xcs,zcis,zcis,zcis,zcs,iirs,sbs,frb,frb,ifrb,frb,frb,bill,bill,fra,fra,fra,frn,stir,stir,stir,stir,stir,stir -meta,meta,sub_type,str,none,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -meta,meta,bloomberg_ticker,str,none,usosfr,bpsws,eeswe,sksws,nks,sfsnt,eusa,eusw_v3,,sksw,nksw_v3,nksw,euxoqq,bpxoqq,ebxoqq,euswi,bpswit,usswit,,,,,,,,,,,,,,,SFR,SF1,KTR,,ER,SFI -meta,meta,eval,str,none,2b,0b,2b,2b,2b,2b,2b,2b,2b,2b,2b,2b,2b,2b,2b,2bx15,0bx15,2b,0b,2b,2b,,,,,,,,,,,,3m SOFR Futures convention,1m Avergaed SOFR Futures,3m ESTR Futures,1m Averaged ESTR futures,Euribor 3m Futures,SONIA 3m Futures -meta,meta,description,str,A test column,SOFR IRS conevntions,SONIA IRS conventions,ESTR IRS conventions,SWESTR IRS conventions,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -base_derivative,leg1,effective,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -base_derivative,leg1,termination,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -base_derivative,leg1,frequency,str,m,a,a,a,a,a,a,a,a,a,a,a,a,q,q,q,a,a,a,a,a,q,s,s,s,a,s,,,q,q,s,q,q,m,q,m,q,q -base_derivative,leg1,stub,str,longfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,,,,,,,,,,,, -base_derivative,leg1,front_stub,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -base_derivative,leg1,back_stub,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -base_derivative,leg1,roll,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,imm,imm,imm,imm,imm,imm -base_derivative,leg1,eom,bool,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,,,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE -base_derivative,leg1,modifier,str,p,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,none,mf,none,none,none,none,none,none,none,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf -base_derivative,leg1,calendar,str,"nyc,tgt,ldn",nyc,ldn,tgt,stk,osl,zur,tgt,tgt,tgt,stk,stk,osl,"tgt,nyc","ldn,nyc","tgt,ldn",tgt,ldn,nyc,ldn,stk,tgt,nyc,ldn,ldn,stk,tro,nyc,stk,stk,tgt,tgt,nyc,nyc,nyc,tgt,tgt,tgt,ldn -base_derivative,leg1,payment_lag,int,4,2,0,1,1,2,2,0,0,0,0,0,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 -base_derivative,leg1,notional,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -base_derivative,leg1,currency,str,tes,usd,gbp,eur,sek,nok,chf,eur,eur,eur,sek,sek,nok,eur,gbp,eur,eur,gbp,usd,gbp,sek,eur,usd,gbp,gbp,sek,cad,usd,sek,sek,eur,eur,usd,usd,usd,eur,eur,eur,gbp -base_derivative,leg1,amortization,float,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -base_derivative,leg1,convention,str,test,act360,act365f,act360,act360,act365f,act360,30e360,30e360,30e360,30e360,30e360,30e360,act360,act365f,act360,1+,1+,1+,act365f,actacticma,act360,actacticma,actacticma,actacticma,actacticma,actacticma_stub365f,act360,act360,act360,act360,act360,act360,act360,act360,act360,act360,act360,act365f -base_derivative,leg2,effective,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -base_derivative,leg2,termination,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -base_derivative,leg2,frequency,str,m,a,a,a,a,a,a,s,q,m,q,q,s,q,q,q,a,a,a,a,q,s,,,,,,,,,,,,q,m,q,m,q,q -base_derivative,leg2,stub,str,longback,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,,,,,,,,,,,,,,,,, -base_derivative,leg2,front_stub,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -base_derivative,leg2,back_stub,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -base_derivative,leg2,roll,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,imm,imm,imm,imm,imm,imm -base_derivative,leg2,eom,bool,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,,,,,,,,,,,,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE -base_derivative,leg2,modifier,str,mp,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,,,,,,,,,,,,mf,mf,mf,mf,mf,mf -base_derivative,leg2,calendar,str,"nyc,tgt,ldn",nyc,ldn,tgt,stk,osl,zur,tgt,tgt,tgt,stk,stk,osl,"tgt,nyc","ldn,nyc","tgt,ldn",tgt,ldn,nyc,ldn,stk,tgt,,,,,,,,,,,,nyc,nyc,tgt,tgt,tgt,ldn -base_derivative,leg2,payment_lag,int,3,2,0,1,1,2,2,0,0,0,0,0,0,2,2,2,0,0,0,0,0,0,,,,,,,,,,,,0,0,0,0,0,0 -base_derivative,leg2,notional,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -base_derivative,leg2,currency,str,,usd,gbp,eur,sek,nok,chf,eur,eur,eur,sek,nok,nok,usd,usd,gbp,eur,gbp,usd,gbp,sek,eur,,,,,,,,,,,,usd,usd,eur,eur,eur,gbp -base_derivative,leg2,amortization,float,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -base_derivative,leg2,convention,str,test2,act360,act365f,act360,act360,act365f,act360,act360,act360,act360,act360,act360,act360,act360,act360,act365f,1+,1+,1+,act365f,act360,act360,,,,,,,,,,,,act360,act360,act360,act360,act360,act365f -fixed,leg1,fixed_rate,float,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -float,leg1,float_spread,float,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -float,leg1,spread_compound_method,str,,,,,,,,,,,,,,none_simple,none_simple,none_simple,,,,,,none_simple,,,,,,,,,,,none_simple,,,,,, -float,leg1,fixings,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -float,leg1,fixing_method,str,,,,,,,,,,,,,,rfr_payment_delay,rfr_payment_delay,rfr_payment_delay,,,,,,ibor,,,,,,,,,,,rfr_observation_shift,,,,,, -float,leg1,method_param,int,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,5,,,,,, -fixed,leg2,fixed_rate,float,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -float,leg2,float_spread,float,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -float,leg2,spread_compound_method,str,,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple,,,,none_simple,none_simple,none_simple,,,,,,,,none_simple,none_simple,none_simple,,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple -float,leg2,fixings,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -float,leg2,fixing_method,str,,rfr_payment_delay,rfr_payment_delay,rfr_payment_delay,rfr_payment_delay,rfr_payment_delay,rfr_payment_delay,ibor,ibor,ibor,ibor,ibor,ibor,rfr_payment_delay,rfr_payment_delay,rfr_payment_delay,,,,rfr_payment_delay,ibor,ibor,,,,,,,,ibor,ibor,ibor,,rfr_payment_delay,rfr_payment_delay_avg,rfr_payment_delay,rfr_payment_delay_avg,rfr_payment_delay,rfr_payment_delay -float,leg2,method_param,int,,,,,,,,2,2,2,2,2,2,,,,,,,,2,2,,,,,,,,2,2,2,,,,,,, -exchange,leg1,initial_exchange,bool,,,,,,,,,,,,,,TRUE,TRUE,TRUE,,,,,,,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,,,,,,,,,, -exchange,leg1,final_exchange,bool,,,,,,,,,,,,,,TRUE,TRUE,TRUE,,,,,,,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,,,,,,,,,, -exchange,leg2,initial_exchange,bool,,,,,,,,,,,,,,TRUE,TRUE,TRUE,,,,,,,,,,,,,,,,,,,,,,, -exchange,leg2,final_exchange,bool,,,,,,,,,,,,,,TRUE,TRUE,TRUE,,,,,,,,,,,,,,,,,,,,,,, -exchange,leg1,fx_fixings,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -exchange,leg2,fx_fixings,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -exchange,leg1,payment_lag_exchange,int,,,,,,,,,,,,,,0,0,0,,,,,,,0,0,0,0,0,0,0,,,,,,,,,, -exchange,leg2,payment_lag_exchange,int,,,,,,,,,,,,,,0,0,0,,,,,,,,,,,,,,,,,,,,,,, -xcs,leg1,fixed,bool,,,,,,,,,,,,,,FALSE,FALSE,FALSE,,,,,,,,,,,,,,,,,,,,,,, -xcs,leg2,fixed,bool,,,,,,,,,,,,,,FALSE,FALSE,FALSE,,,,,,,,,,,,,,,,,,,,,,, -xcs,leg2,mtm,bool,,,,,,,,,,,,,,TRUE,TRUE,TRUE,,,,,,,,,,,,,,,,,,,,,,, -index,leg1,index_method,str,,,,,,,,,,,,,,,,,,,,,daily,,,,daily,,,,,,,,,,,,,, -index,leg1,index_fixings,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -index,leg1,index_base,float,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -index,leg1,index_lag,int,,,,,,,,,,,,,,,,,,,,,3,,,,3,,,,,,,,,,,,,, -index,leg2,index_method,str,,,,,,,,,,,,,,,,,monthly,monthly,daily,,,,,,,,,,,,,,,,,,,, -index,leg2,index_fixings,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -index,leg2,index_base,float,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -index,leg2,index_lag,int,,,,,,,,,,,,,,,,,3,2,3,,,,,,,,,,,,,,,,,,,, -bond,leg1,settle,int,,,,,,,,,,,,,,,,,,,,,,,1,1,1,1,1,1,1,,,,1,,,,,, -bond,leg1,ex_div,int,,,,,,,,,,,,,,,,,,,,,,,1,7,7,5,1,0,0,,,,1,,,,,, -bond,leg1,calc_mode,str,,,,,,,,,,,,,,,,,,,,,,,ust,ukg,ukg,sgb,cadgb,ustb,sgbb,,,,,,,,,, -stir,leg1,bp_value,float,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,25,41.67,25,25,25,25 -stir,leg1,nominal,float,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1000000,5000000,1000000,3000000,1000000,1000000 \ No newline at end of file +kind,leg,kwarg,dtype,test,usd_irs,gbp_irs,eur_irs,sek_irs,nok_irs,chf_irs,eur_irs6,eur_irs3,eur_irs1,sek_irs3,nok_irs3,nok_irs6,eurusd_xcs,gbpusd_xcs,eurgbp_xcs,eurusd_fxs,gbpusd_fxs,eur_zcis,gbp_zcis,usd_zcis,gbp_zcs,sek_iirs,eur_sbs36,usd_gb,gbp_gb,gbp_gbi,sek_gb,cad_gb,usd_gbb,sek_gbb,sek_fra3,eur_fra3,eur_fra6,usd_frn5,usd_stir,usd_stir1,eur_stir,eur_stir1,eur_stir3,gbp_stir +meta,meta,currency,str,TES,usd,gbp,eur,sek,nok,chf,eur,eur,eur,sek,nok,nok,eur/usd,gbp/usd,gbp/usd,eur/usd,gbp/usd,eur,gbp,usd,gbp,sek_iirs,eur,usd,gbp,gbp,sek,cad,usd,sek,sek,eur,eur,usd,usd,usd,eur,eur,eur,gbp +meta,meta,instrument,str,none,irs,irs,irs,irs,irs,irs,irs,irs,irs,irs,irs,irs,xcs,xcs,xcs,fxs,fxs,zcis,zcis,zcis,zcs,iirs,sbs,frb,frb,ifrb,frb,frb,bill,bill,fra,fra,fra,frn,stir,stir,stir,stir,stir,stir +meta,meta,sub_type,str,none,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +meta,meta,bloomberg_ticker,str,none,usosfr,bpsws,eeswe,sksws,nks,sfsnt,eusa,eusw_v3,,sksw,nksw_v3,nksw,euxoqq,bpxoqq,ebxoqq,eur,gbp,euswi,bpswit,usswit,,,,,,,,,,,,,,,SFR,SF1,KTR,,ER,SFI +meta,meta,eval,str,none,2b,0b,2b,2b,2b,2b,2b,2b,2b,2b,2b,2b,2b,2b,2b,2b,2b,2bx15,0bx15,2b,0b,2b,2b,,,,,,,,,,,,3m SOFR Futures convention,1m Avergaed SOFR Futures,3m ESTR Futures,1m Averaged ESTR futures,Euribor 3m Futures,SONIA 3m Futures +meta,meta,description,str,A test column,SOFR IRS conevntions,SONIA IRS conventions,ESTR IRS conventions,SWESTR IRS conventions,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +base_derivative,leg1,effective,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +base_derivative,leg1,termination,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +base_derivative,leg1,frequency,str,m,a,a,a,a,a,a,a,a,a,a,a,a,q,q,q,,,a,a,a,a,a,q,s,s,s,a,s,,,q,q,s,q,q,m,q,m,q,q +base_derivative,leg1,stub,str,longfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,,,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,shortfront,,,,,,,,,,,, +base_derivative,leg1,front_stub,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +base_derivative,leg1,back_stub,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +base_derivative,leg1,roll,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,imm,imm,imm,imm,imm,imm +base_derivative,leg1,eom,bool,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,,,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE +base_derivative,leg1,modifier,str,p,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf,none,mf,none,none,none,none,none,none,none,mf,mf,mf,mf,mf,mf,mf,mf,mf,mf +base_derivative,leg1,calendar,str,"nyc,tgt,ldn",nyc,ldn,tgt,stk,osl,zur,tgt,tgt,tgt,stk,osl,osl,"tgt,nyc","ldn,nyc","tgt,ldn","tgt,nyc","ldn,nyc",tgt,ldn,nyc,ldn,stk,tgt,nyc,ldn,ldn,stk,tro,nyc,stk,stk,tgt,tgt,nyc,nyc,nyc,tgt,tgt,tgt,ldn +base_derivative,leg1,payment_lag,int,4,2,0,1,1,2,2,0,0,0,0,0,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +base_derivative,leg1,notional,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +base_derivative,leg1,currency,str,tes,usd,gbp,eur,sek,nok,chf,eur,eur,eur,sek,sek,nok,eur,gbp,eur,eur,gbp,eur,gbp,usd,gbp,sek,eur,usd,gbp,gbp,sek,cad,usd,sek,sek,eur,eur,usd,usd,usd,eur,eur,eur,gbp +base_derivative,leg1,amortization,float,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +base_derivative,leg1,convention,str,test,act360,act365f,act360,act360,act365f,act360,30e360,30e360,30e360,30e360,30e360,30e360,act360,act365f,act360,act360,act365f,1+,1+,1+,act365f,actacticma,act360,actacticma,actacticma,actacticma,actacticma,actacticma_stub365f,act360,act360,act360,act360,act360,act360,act360,act360,act360,act360,act360,act365f +base_derivative,leg2,effective,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +base_derivative,leg2,termination,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +base_derivative,leg2,frequency,str,m,,,,,,,s,q,m,q,q,s,q,q,q,,,a,a,a,a,q,s,,,,,,,,,,,,q,m,q,m,q,q +base_derivative,leg2,stub,str,longback,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +base_derivative,leg2,front_stub,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +base_derivative,leg2,back_stub,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +base_derivative,leg2,roll,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,imm,imm,imm,imm,imm,imm +base_derivative,leg2,eom,bool,FALSE,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE +base_derivative,leg2,modifier,str,mp,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,mf,mf,mf,mf,mf,mf +base_derivative,leg2,calendar,str,"nyc,tgt,ldn",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,nyc,nyc,tgt,tgt,tgt,ldn +base_derivative,leg2,payment_lag,int,3,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,0,0,0,0,0 +base_derivative,leg2,notional,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +base_derivative,leg2,currency,str,,,,,,,,,,,,,,usd,usd,gbp,usd,usd,,,,,,,,,,,,,,,,,,usd,usd,eur,eur,eur,gbp +base_derivative,leg2,amortization,float,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +base_derivative,leg2,convention,str,test2,act360,act365f,act360,act360,act365f,act360,act360,act360,act360,act360,act360,act360,act360,act360,act365f,act360,act365f,,,,,act360,act360,,,,,,,,,,,,act360,act360,act360,act360,act360,act365f +fixed,leg1,fixed_rate,float,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +float,leg1,float_spread,float,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +float,leg1,spread_compound_method,str,,,,,,,,,,,,,,none_simple,none_simple,none_simple,,,,,,,,none_simple,,,,,,,,,,,none_simple,,,,,, +float,leg1,fixings,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +float,leg1,fixing_method,str,,,,,,,,,,,,,,rfr_payment_delay,rfr_payment_delay,rfr_payment_delay,,,,,,,,ibor,,,,,,,,,,,rfr_observation_shift,,,,,, +float,leg1,method_param,int,,,,,,,,,,,,,,,,,,,,,,,,2,,,,,,,,,,,5,,,,,, +fixed,leg2,fixed_rate,float,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +float,leg2,float_spread,float,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +float,leg2,spread_compound_method,str,,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple,,,,,,none_simple,none_simple,none_simple,,,,,,,,none_simple,none_simple,none_simple,,none_simple,none_simple,none_simple,none_simple,none_simple,none_simple +float,leg2,fixings,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +float,leg2,fixing_method,str,,rfr_payment_delay,rfr_payment_delay,rfr_payment_delay,rfr_payment_delay,rfr_payment_delay,rfr_payment_delay,ibor,ibor,ibor,ibor,ibor,ibor,rfr_payment_delay,rfr_payment_delay,rfr_payment_delay,,,,,,rfr_payment_delay,ibor,ibor,,,,,,,,ibor,ibor,ibor,,rfr_payment_delay,rfr_payment_delay_avg,rfr_payment_delay,rfr_payment_delay_avg,rfr_payment_delay,rfr_payment_delay +float,leg2,method_param,int,,,,,,,,2,2,2,2,2,2,,,,,,,,,,2,2,,,,,,,,2,2,2,,,,,,, +exchange,leg1,initial_exchange,bool,,,,,,,,,,,,,,,,,,,,,,,,,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,,,,,,,,,, +exchange,leg1,final_exchange,bool,,,,,,,,,,,,,,,,,,,,,,,,,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,,,,,,,,,, +exchange,leg2,initial_exchange,bool,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +exchange,leg2,final_exchange,bool,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +exchange,leg1,fx_fixings,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +exchange,leg2,fx_fixings,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +exchange,leg1,payment_lag_exchange,int,,,,,,,,,,,,,,0,0,0,,,,,,,,,0,0,0,0,0,0,0,,,,,,,,,, +exchange,leg2,payment_lag_exchange,int,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +xcs,leg1,fixed,bool,,,,,,,,,,,,,,FALSE,FALSE,FALSE,,,,,,,,,,,,,,,,,,,,,,,,, +xcs,leg2,fixed,bool,,,,,,,,,,,,,,FALSE,FALSE,FALSE,,,,,,,,,,,,,,,,,,,,,,,,, +xcs,leg2,mtm,bool,,,,,,,,,,,,,,TRUE,TRUE,TRUE,,,,,,,,,,,,,,,,,,,,,,,,, +index,leg1,index_method,str,,,,,,,,,,,,,,,,,,,,,,,daily,,,,daily,,,,,,,,,,,,,, +index,leg1,index_fixings,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +index,leg1,index_base,float,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +index,leg1,index_lag,int,,,,,,,,,,,,,,,,,,,,,,,3,,,,3,,,,,,,,,,,,,, +index,leg2,index_method,str,,,,,,,,,,,,,,,,,,,monthly,monthly,daily,,,,,,,,,,,,,,,,,,,, +index,leg2,index_fixings,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +index,leg2,index_base,float,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +index,leg2,index_lag,int,,,,,,,,,,,,,,,,,,,3,2,3,,,,,,,,,,,,,,,,,,,, +bond,leg1,settle,int,,,,,,,,,,,,,,,,,,,,,,,,,1,1,1,1,1,1,1,,,,1,,,,,, +bond,leg1,ex_div,int,,,,,,,,,,,,,,,,,,,,,,,,,1,7,7,5,1,0,0,,,,1,,,,,, +bond,leg1,calc_mode,str,,,,,,,,,,,,,,,,,,,,,,,,,ust,ukg,ukg,sgb,cadgb,ustb,sgbb,,,,,,,,,, +stir,leg1,bp_value,float,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,25,41.67,25,25,25,25 +stir,leg1,nominal,float,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1000000,5000000,1000000,3000000,1000000,1000000 \ No newline at end of file diff --git a/tests/test_instruments.py b/tests/test_instruments.py index c534e448..498d60f9 100644 --- a/tests/test_instruments.py +++ b/tests/test_instruments.py @@ -2849,8 +2849,23 @@ def test_xcs(self): assert xcs.kwargs["currency"] == "eur" assert xcs.kwargs["calendar"] == "ldn,tgt,nyc" assert xcs.kwargs["payment_lag"] == 5 - assert xcs.kwargs["leg2_payment_lag"] == 2 - assert xcs.kwargs["leg2_calendar"] == "tgt,nyc" + assert xcs.kwargs["leg2_payment_lag"] == 5 + assert xcs.kwargs["leg2_calendar"] == "ldn,tgt,nyc" + + def test_fxs(self): + fxs = FXSwap( + effective=dt(2022, 1, 1), + termination="3m", + spec="eurusd_fxs", + payment_lag=5, + calendar="ldn,tgt,nyc", + ) + assert fxs.kwargs["convention"] == "act360" + assert fxs.kwargs["currency"] == "eur" + assert fxs.kwargs["calendar"] == "ldn,tgt,nyc" + assert fxs.kwargs["payment_lag"] == 5 + assert fxs.kwargs["leg2_payment_lag"] == 5 + assert fxs.kwargs["leg2_calendar"] == "ldn,tgt,nyc" @pytest.mark.parametrize("inst, expected", [ From ecdb235e26330724f06b0425dbbb5219555590a9 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Sun, 4 Feb 2024 15:36:07 +0100 Subject: [PATCH 10/14] fra example --- rateslib/instruments.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/rateslib/instruments.py b/rateslib/instruments.py index 34f773fd..357aadc2 100644 --- a/rateslib/instruments.py +++ b/rateslib/instruments.py @@ -7018,6 +7018,33 @@ def __init__( if self.leg1.schedule.n_periods != 1 or self.leg2.schedule.n_periods != 1: raise ValueError("FRA scheduling inputs did not define a single period.") + @classmethod + def example(cls): + print(dedent("""\ + Broker confirmation: + 'You Paid 500m 1x4 28th FRA in EUR at 2.5%.' + + Rateslib configuration: + FRA( + effective=dt(2022, 2, 28), + termination="3m", + frequency="q", # effective, termination and frequency required. + roll=28, + eom=False, + modifier="mf", + calendar="tgt", # calendar and modifier to determine termination. + payment_lag=0, + notional=500e6, + currency="eur", # notional and currency + convention="act360", + method_param=2, # IBOR lag + fixed_rate=2.50, + # fixings=NoInput(0), + # curves=["euribor3m", "estr"], # curves for forecasting and discounting optional. + # spec=NoInput(0), # possible auto-defined FRAs exist in defaults. + ) + """)) + def _set_pricing_mid( self, curves: Union[Curve, str, list, NoInput] = NoInput(0), From 329023e3b35a7f63be6e1d67cd24996f4eb45585 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Sun, 4 Feb 2024 22:29:20 +0100 Subject: [PATCH 11/14] DOC: examples --- docs/source/g_instruments.rst | 77 ++++++++++++++++++++++++++++++++++- rateslib/instruments.py | 33 +++++++++++++++ tests/test_instruments.py | 7 +++- 3 files changed, 114 insertions(+), 3 deletions(-) diff --git a/docs/source/g_instruments.rst b/docs/source/g_instruments.rst index ab3c7a31..6d45b515 100644 --- a/docs/source/g_instruments.rst +++ b/docs/source/g_instruments.rst @@ -57,7 +57,7 @@ The below example demonstrates this composition when creating an :class:`~ratesl irs.leg2.periods -Examples of Every Instrument +Examples of Each Instrument ****************************** IRS @@ -150,6 +150,81 @@ Suppose *"You Paid 500m 1x4 28th FRA in EUR at 2.5%".* - "eur_fra6": Euribor 6M FRA - "sek_fra3": Stibor 3M FRA +SBS +---- + +Suppose *"You Paid 5Y EUR single-swap 3s6s basis at 6.5bp in €100mm."* + +.. ipython:: python + + sbs = SBS( + effective=dt(2023, 12, 20), + termination="5y", + frequency="q", + leg2_frequency="s", # effective, termination and frequency dates required. + calendar="tgt", + modifier="mf", + roll=20, # schedule configuration + currency="eur", + notional=100e6, # currency and notional + convention="act360", + fixing_method="ibor", + method_param=2, + leg2_fixing_method="ibor", + leg2_method_param=2, + # fixings=NoInput(0), + # leg2_fixings=NoInput(0), + float_spread=6.50 # pricing parameters + # spec=NoInput(0), # possible auto-defined IRS exist in defaults. + # curves=["euribor3m", "estr", "euribor6m", "estr"], # curves optional. + ) + +**Available** ``spec`` **defaults:** + +- "eur_sbs36": Euribor 3m vs 6m single basis swap + +ZCS +---- + +Suppose *"You Received £100mm 15Y ZCS effective 16th March 2023 at IRR of 2.15% (under Act365F), +compounding annually."* + +.. ipython:: python + + zcs = ZCS( + effective=dt(2023, 3, 16), + termination="15Y", + frequency="A", # effective, termination and compounding frequency required. + modifier="mf", + eom=True, + calendar="ldn", # schedule configuration + currency="gbp", + notional=-100e6, # currency and notional + convention="act365f", + fixed_rate=2.15, + leg2_fixing_method="rfr_payment_delay", + leg2_fixings=NoInput(0), + leg2_method_param=0, # pricing parameters + curves="gbpgbp", # curves for forecasting and discounting each leg. + spec=NoInput(0), # possible auto-defined ZCS exist in defaults. + ) + +FXExchange +----------- + +Suppose *"You Bought £100mm Selling $125mm (GBPUSD 1.25) for settlement 16th March 2023."* + +.. ipython:: python + + fxe = FXExchange( + settlement=dt(2023, 3, 16), + currency="gbp", + leg2_currency="usd", + fx_rate=1.25, + notional=100e6, + # curves=[None, gbpusd, None, usdusd], # curves for discounting each currency. + ) + FXSwap ------- diff --git a/rateslib/instruments.py b/rateslib/instruments.py index 357aadc2..512d7069 100644 --- a/rateslib/instruments.py +++ b/rateslib/instruments.py @@ -1088,6 +1088,9 @@ def gamma(self, *args, **kwargs): """ return super().gamma(*args, **kwargs) + def analytic_delta(self, *args, **kwargs): + return 0.0 + # Securities @@ -6735,6 +6738,36 @@ def __init__( self.leg1 = FloatLeg(**_get(self.kwargs, leg=1)) self.leg2 = FloatLeg(**_get(self.kwargs, leg=2)) + @classmethod + def example(cls): + print(dedent("""\ + Broker confirmation: + 'You Paid €100mm 5Y EUR 3s6s single-swap basis at 3m + 6.5bps.' + + Rateslib configuration: + SBS( + effective=dt(2023, 12, 20), + termination="5y", + frequency="q", + leg2_frequency="s", # effective, termination and frequency dates required. + calendar="tgt", + modifier="mf", + roll=20, # schedule configuration + currency="eur", + notional=100e6, # currency and notional + convention="act360", + fixing_method="ibor", + method_param=2, + leg2_fixing_method="ibor", + leg2_method_param=2, + # fixings=NoInput(0), + # leg2_fixings=NoInput(0), + float_spread=6.50 # pricing parameters + # spec=NoInput(0), # possible auto-defined IRS exist in defaults. + # curves=["euribor3m", "estr", "euribor6m", "estr"], # curves optional. + ) + """)) + def _set_pricing_mid(self, curves, solver): if self.float_spread is NoInput.blank and self.leg2_float_spread is NoInput.blank: # set a pricing parameter for the purpose of pricing NPV at zero. diff --git a/tests/test_instruments.py b/tests/test_instruments.py index 498d60f9..fddacf46 100644 --- a/tests/test_instruments.py +++ b/tests/test_instruments.py @@ -2978,5 +2978,8 @@ def test_fx_settlements_table_no_fxf(): @pytest.mark.parametrize("Inst", [Inst for Inst in Instruments]) def test_examples(Inst): - assert getattr(Inst, "example", None) is not None - # test an example function is written for the class \ No newline at end of file + # test an example function is written for the Instrument class + try: + getattr(Inst, "example", None)() + except TypeError: # NoneType is not callable + assert False From 0375c1362ddf46b76311157b7fca1bfc88c816a3 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Tue, 6 Feb 2024 07:37:39 +0100 Subject: [PATCH 12/14] DOC: examples --- docs/source/g_instruments.rst | 41 +++++++++++++++++++++++++++++++++-- rateslib/instruments.py | 27 +++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/docs/source/g_instruments.rst b/docs/source/g_instruments.rst index 6d45b515..06396350 100644 --- a/docs/source/g_instruments.rst +++ b/docs/source/g_instruments.rst @@ -186,7 +186,8 @@ Suppose *"You Paid 5Y EUR single-swap 3s6s basis at 6.5bp in €100mm."* ZCS ---- -Suppose *"You Received £100mm 15Y ZCS effective 16th March 2023 at IRR of 2.15% (under Act365F), +Suppose *"You Received £100mm 15Y Zero Coupon Swap effective +16th March 2023 at IRR of 2.15% (under Act365F), compounding annually."* .. ipython:: python @@ -209,6 +210,42 @@ compounding annually."* spec=NoInput(0), # possible auto-defined ZCS exist in defaults. ) +**Available** ``spec`` **defaults:** + +- "gbp_zcs": GBP Zero coupon swap + +ZCIS +----- + +Suppose *"You received €100m 5Y Zero Coupon Inflation Swap at an IRR of 1.15% versus EUR-CPI +with a 3-month lag".* + +.. ipython:: python + + zcis = ZCIS( + effective=dt(2022, 1, 1), + termination="5Y", + frequency="A", + calendar="tgt", + modifier="mf", + currency="eur", + fixed_rate=1.15, + convention="1+", + notional=-100e6, + leg2_index_base=100.0, + leg2_index_method="monthly", + leg2_index_lag=3, + leg2_index_fixings=NoInput(0), + curves=[None, "estr", "eur_cpi", "estr"], + spec=NoInput(0), + ) + +**Available** ``spec`` **defaults:** + +- "eur_zcis": EUR Zero coupon inflation swap +- "gbp_zcis": GBP Zero coupon inflation swap +- "usd_zcis": USD Zero coupon inflation swap + FXExchange ----------- @@ -222,7 +259,7 @@ Suppose *"You Bought £100mm Selling $125mm (GBPUSD 1.25) for settlement 16th Ma leg2_currency="usd", fx_rate=1.25, notional=100e6, - # curves=[None, gbpusd, None, usdusd], # curves for discounting each currency. + curves=[None, "gbpusd", None, "usdusd"], # curves for discounting each currency, optional ) FXSwap diff --git a/rateslib/instruments.py b/rateslib/instruments.py index 512d7069..3a7fb314 100644 --- a/rateslib/instruments.py +++ b/rateslib/instruments.py @@ -6471,6 +6471,33 @@ def __init__( self.leg1 = ZeroFixedLeg(**_get(self.kwargs, leg=1)) self.leg2 = ZeroIndexLeg(**_get(self.kwargs, leg=2)) + @classmethod + def example(cls): + print(dedent("""\ + Broker confirmation: + 'You Received €100mm 5Y ZCIS effective 1st Jan 2022 at IRR of 1.15% vs EUR-CPI with a + 3 month lag, compounding fixed annually.' + + Rateslib configuration: + ZCIS( + effective=dt(2022, 1, 1), + termination="5Y", + frequency="A", + calendar="tgt", + modifier="mf", + currency="eur", + fixed_rate=1.15, + convention="1+", + notional=-100e6, + leg2_index_base=100.0, + leg2_index_method="monthly", + leg2_index_lag=3, + leg2_index_fixings=NoInput(0), + curves=[None, "estr", "eur_cpi", "estr"], + spec=NoInput(0), + ) + """)) + def _set_pricing_mid(self, curves, solver): if self.fixed_rate is NoInput.blank: # set a fixed rate for the purpose of pricing NPV, which should be zero. From c669dfd0771ebc1092c59cc5789a3448d4fba380 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Tue, 6 Feb 2024 19:39:07 +0100 Subject: [PATCH 13/14] DOC: examples --- docs/source/g_instruments.rst | 42 +++++++++++++++++++++++++++++++++++ rateslib/instruments.py | 37 ++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/docs/source/g_instruments.rst b/docs/source/g_instruments.rst index 06396350..d0fa144b 100644 --- a/docs/source/g_instruments.rst +++ b/docs/source/g_instruments.rst @@ -288,3 +288,45 @@ Suppose *"You Paid 3M EURUSD FX Swap in €100mm/$105mm (split notional €101.5 - "eurusd_fxs": EUR/USD FX swap - "gbpusd_fxs": GBP/USD FX swap + +XCS +---- + +Suppose *"You Paid €100mm 5Y EUR/USD MTM Cross currency swap @-15bp under normal RFR conventions, +with initial FX fixing agreed at EURUSD 1.08."* + +.. ipython:: python + + xcs = XCS( + effective=dt(2023, 12, 20), + termination="5y", # effective and termination dates required. + frequency="q", + calendar="tgt,nyc", + modifier="mf", + payment_lag=2, + payment_lag_exchange=0, + roll=20, # schedule configuration + currency="eur", + leg2_currency="usd", + fx_fixings=1.08, + notional=100e6, # currency and notional + fixed=False, + leg2_fixed=False, + leg2_mtm=True, + convention="act360", + fixing_method="rfr_payment_delay", + leg2_fixing_method="rfr_payment_delay", + method_param=NoInput(0), + leg2_method_param=NoInput(0), + fixings=NoInput(0), + leg2_fixings=NoInput(0), + float_spread=-15.0, # pricing parameters + spec=NoInput(0), # possible auto-defined XCS exist in defaults. + curves=["eureur", "eurusd", "usdusd", "usdusd"], # curves optional. + ) + +**Available** ``spec`` **defaults:** + +- "eurusd_xcs": EUR/USD MTM Cross currency swap +- "gbpusd_xcs": GBP/USD MTM Cross currency swap +- "eurgbp_xcs": EUR/GBP MTM Cross currency swap diff --git a/rateslib/instruments.py b/rateslib/instruments.py index 3a7fb314..a023b1ee 100644 --- a/rateslib/instruments.py +++ b/rateslib/instruments.py @@ -7472,6 +7472,43 @@ def __init__( self.leg2 = Leg2(**_get(self.kwargs, leg=2, filter=["leg2_fixed", "leg2_mtm"])) self._initialise_fx_fixings(fx_fixings) + @classmethod + def example(cls): + print(dedent("""\ + Broker confirmation: + 'You Paid €100mm 5Y EUR/USD MTM Cross currency swap -15bp under normal RFR conventions, + with initial FX fixing agreed at EURUSD 1.08.' + + Rateslib configuration: + XCS( + effective=dt(2023, 12, 20), + termination="5y", # effective and termination dates required. + frequency="q", + calendar="tgt,nyc", + modifier="mf", + payment_lag=2, + payment_lag_exchange=0, + roll=20, # schedule configuration + currency="eur", + leg2_currency="usd", + fx_fixings=1.08, + notional=100e6, # currency and notional + fixed=False, + leg2_fixed=False, + leg2_mtm=True, + convention="act360", + fixing_method="rfr_payment_delay", + leg2_fixing_method="rfr_payment_delay", + method_param=NoInput(0), + leg2_method_param=NoInput(0), + fixings=NoInput(0), + leg2_fixings=NoInput(0), + float_spread=-15.0 # pricing parameters + spec=NoInput(0), # possible auto-defined IRS exist in defaults. + curves=["eureur", "eurusd", "usdusd", "usdusd"], # curves optional. + ) + """)) + @property def fx_fixings(self): return self._fx_fixings From bc679cd569e3edfe1b2986700cf98c39f7fbc9bb Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Tue, 6 Feb 2024 22:49:38 +0100 Subject: [PATCH 14/14] DOC: examples --- docs/source/_static/css/overwrites.css | 5 ++++ docs/source/g_instruments.rst | 37 ++++++++++++++++++++++++++ docs/source/i_whatsnew.rst | 6 ++++- rateslib/_spec_loader.py | 2 +- rateslib/data/__instrument_spec.csv | 6 ++--- rateslib/instruments.py | 33 +++++++++++++++++++++++ 6 files changed, 84 insertions(+), 5 deletions(-) diff --git a/docs/source/_static/css/overwrites.css b/docs/source/_static/css/overwrites.css index 24c27ff2..ede4f561 100644 --- a/docs/source/_static/css/overwrites.css +++ b/docs/source/_static/css/overwrites.css @@ -69,4 +69,9 @@ div.tutorial span{ color: #e0e0e0; border-radius: 0.5em; padding: 0.25em; +} + +.red { + color: red; + font-style: italic; } \ No newline at end of file diff --git a/docs/source/g_instruments.rst b/docs/source/g_instruments.rst index d0fa144b..bd5c361e 100644 --- a/docs/source/g_instruments.rst +++ b/docs/source/g_instruments.rst @@ -246,6 +246,43 @@ with a 3-month lag".* - "gbp_zcis": GBP Zero coupon inflation swap - "usd_zcis": USD Zero coupon inflation swap +IIRS +----- + +Suppose *"You bought an inflation asset swap, by Paying £100mm 5Y IIRS effective +1st Jan 2022 at 1.15% indexed at GBP-CPI with a 3 month lag, versus SONIA paid semi-annually +@ -50bps."* + +.. ipython:: python + + iirs = IIRS( + effective=dt(2022, 1, 1), + termination="5Y", + frequency="S", + calendar="ldn", + modifier="none", + leg2_modifier="mf", + currency="gbp", + fixed_rate=1.15, + payment_lag=0, + convention="ActActICMA", + leg2_convention="act365f", + notional=100e6, + index_base=100.0, + index_method="monthly", + index_lag=3, + index_fixings=NoInput(0), + leg2_fixing_method="rfr_payment_delay", + leg2_fixings=NoInput(0), + leg2_float_spread=-50.0, + curves=["gbp_cpi", "sonia", "sonia", "sonia"], + spec=NoInput(0), + ) + +**Available** ``spec`` **defaults:** + +- "sek_iirs3": SEK inflation IRS versus Stibor 3m + FXExchange ----------- diff --git a/docs/source/i_whatsnew.rst b/docs/source/i_whatsnew.rst index 1b8e8f6f..d032d3f1 100644 --- a/docs/source/i_whatsnew.rst +++ b/docs/source/i_whatsnew.rst @@ -1,5 +1,7 @@ .. _whatsnew-doc: +.. role:: red + ************** Release Notes ************** @@ -56,10 +58,12 @@ email contact through **rateslib@gmail.com**. - Description * - Instruments - Reverse the notional direction of :class:`~rateslib.instruments.FXExchange` to be more - intuitive. + intuitive. :red:`Breaking change!` * - Instruments - Add a class method: :meth:`~rateslib.instruments.IRS.example` to each *Instrument* to provide a more intuitive way to initialise. + * - Instruments + - Relabel the specification `sek_iirs` as `sek_iirs3`. :red:`Breaking change!` 1.0.0 (1st Feb 2024) diff --git a/rateslib/_spec_loader.py b/rateslib/_spec_loader.py index cff58cb5..e7536d8c 100644 --- a/rateslib/_spec_loader.py +++ b/rateslib/_spec_loader.py @@ -113,7 +113,7 @@ def _get_kwargs(spec): "gbp_zcis": _get_kwargs("gbp_zcis"), "usd_zcis": _get_kwargs("usd_zcis"), "gbp_zcs": _get_kwargs("gbp_zcs"), # ZCS - "sek_iirs": _get_kwargs("sek_iirs"), # IIRS + "sek_iirs3": _get_kwargs("sek_iirs3"), # IIRS "usd_gb": _get_kwargs("usd_gb"), # FRB "usd_gbb": _get_kwargs("usd_gbb"), "gbp_gb": _get_kwargs("gbp_gb"), diff --git a/rateslib/data/__instrument_spec.csv b/rateslib/data/__instrument_spec.csv index a694371f..03f27b3d 100644 --- a/rateslib/data/__instrument_spec.csv +++ b/rateslib/data/__instrument_spec.csv @@ -1,5 +1,5 @@ -kind,leg,kwarg,dtype,test,usd_irs,gbp_irs,eur_irs,sek_irs,nok_irs,chf_irs,eur_irs6,eur_irs3,eur_irs1,sek_irs3,nok_irs3,nok_irs6,eurusd_xcs,gbpusd_xcs,eurgbp_xcs,eurusd_fxs,gbpusd_fxs,eur_zcis,gbp_zcis,usd_zcis,gbp_zcs,sek_iirs,eur_sbs36,usd_gb,gbp_gb,gbp_gbi,sek_gb,cad_gb,usd_gbb,sek_gbb,sek_fra3,eur_fra3,eur_fra6,usd_frn5,usd_stir,usd_stir1,eur_stir,eur_stir1,eur_stir3,gbp_stir -meta,meta,currency,str,TES,usd,gbp,eur,sek,nok,chf,eur,eur,eur,sek,nok,nok,eur/usd,gbp/usd,gbp/usd,eur/usd,gbp/usd,eur,gbp,usd,gbp,sek_iirs,eur,usd,gbp,gbp,sek,cad,usd,sek,sek,eur,eur,usd,usd,usd,eur,eur,eur,gbp +kind,leg,kwarg,dtype,test,usd_irs,gbp_irs,eur_irs,sek_irs,nok_irs,chf_irs,eur_irs6,eur_irs3,eur_irs1,sek_irs3,nok_irs3,nok_irs6,eurusd_xcs,gbpusd_xcs,eurgbp_xcs,eurusd_fxs,gbpusd_fxs,eur_zcis,gbp_zcis,usd_zcis,gbp_zcs,sek_iirs3,eur_sbs36,usd_gb,gbp_gb,gbp_gbi,sek_gb,cad_gb,usd_gbb,sek_gbb,sek_fra3,eur_fra3,eur_fra6,usd_frn5,usd_stir,usd_stir1,eur_stir,eur_stir1,eur_stir3,gbp_stir +meta,meta,currency,str,TES,usd,gbp,eur,sek,nok,chf,eur,eur,eur,sek,nok,nok,eur/usd,gbp/usd,gbp/usd,eur/usd,gbp/usd,eur,gbp,usd,gbp,sek,eur,usd,gbp,gbp,sek,cad,usd,sek,sek,eur,eur,usd,usd,usd,eur,eur,eur,gbp meta,meta,instrument,str,none,irs,irs,irs,irs,irs,irs,irs,irs,irs,irs,irs,irs,xcs,xcs,xcs,fxs,fxs,zcis,zcis,zcis,zcs,iirs,sbs,frb,frb,ifrb,frb,frb,bill,bill,fra,fra,fra,frn,stir,stir,stir,stir,stir,stir meta,meta,sub_type,str,none,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, meta,meta,bloomberg_ticker,str,none,usosfr,bpsws,eeswe,sksws,nks,sfsnt,eusa,eusw_v3,,sksw,nksw_v3,nksw,euxoqq,bpxoqq,ebxoqq,eur,gbp,euswi,bpswit,usswit,,,,,,,,,,,,,,,SFR,SF1,KTR,,ER,SFI @@ -28,7 +28,7 @@ base_derivative,leg2,front_stub,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, base_derivative,leg2,back_stub,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, base_derivative,leg2,roll,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,imm,imm,imm,imm,imm,imm base_derivative,leg2,eom,bool,FALSE,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE -base_derivative,leg2,modifier,str,mp,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,mf,mf,mf,mf,mf,mf +base_derivative,leg2,modifier,str,mp,,,,,,,,,,,,,,,,,,,,,,mf,,,,,,,,,,,,,mf,mf,mf,mf,mf,mf base_derivative,leg2,calendar,str,"nyc,tgt,ldn",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,nyc,nyc,tgt,tgt,tgt,ldn base_derivative,leg2,payment_lag,int,3,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,0,0,0,0,0 base_derivative,leg2,notional,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, diff --git a/rateslib/instruments.py b/rateslib/instruments.py index a023b1ee..abd2dee6 100644 --- a/rateslib/instruments.py +++ b/rateslib/instruments.py @@ -5874,6 +5874,39 @@ def __init__( self.leg1 = IndexFixedLeg(**_get(self.kwargs, leg=1)) self.leg2 = FloatLeg(**_get(self.kwargs, leg=2)) + @classmethod + def example(cls): + print(dedent("""\ + Broker confirmation: + 'You Paid £100mm 5Y IIRS effective 1st Jan 2022 at 1.15% indexed at GBP-CPI with a + 3 month lag, versus SONIA paid semi-annually -50bps.' + + Rateslib configuration: + IIRS( + effective=dt(2022, 1, 1), + termination="5Y", + frequency="S", + calendar="ldn", + modifier="none", + leg2_modifier="mf", + currency="gbp", + fixed_rate=1.15, + payment_lag=0, + convention="ActActICMA", + leg2_convention="act365f", + notional=100e6, + index_base=100.0, + index_method="monthly", + index_lag=3, + index_fixings=NoInput(0), + leg2_fixing_method="rfr_payment_delay", + leg2_fixings=NoInput(0), + leg2_float_spread=-50.0, + curves=["gbp_cpi", "sonia", "sonia", "sonia"], + spec=NoInput(0), + ) + """)) + def _set_pricing_mid( self, curves: Union[Curve, str, list, NoInput] = NoInput(0),