Legs#
The rateslib.legs
module creates Legs which
typically contain a list of Periods. The pricing, and
risk, calculations of Legs resolves to a linear sum of those same calculations
looped over all of the individual Periods.
Like Periods, it is probably quite
rare that Legs will be instantiated directly, rather they will form the
components of Instruments, but none-the-less, this page
describes their construction.
The following Legs are provided, click on the links for a full description of each Leg type:
|
Abstract base class with common parameters for all |
|
Abstract base class with common parameters for all |
|
Create a fixed leg composed of |
|
Create a floating leg composed of |
|
Create a leg of |
|
Create a zero coupon floating leg composed of |
|
Create a zero coupon fixed leg composed of a single |
|
Create a zero coupon index leg composed of a single |
|
Create a leg of |
|
Create a leg of |
|
Create a leg contained of user specified |
Legs, similar to Periods, are defined as having the following the methods:
|
Return the NPV of the Leg via summing all periods. |
|
Return the analytic delta of the Leg via summing all periods. |
|
Return the properties of the Leg used in calculating cashflows. |
Basic Leg Inputs#
The BaseLeg
is an abstract base class providing the shared
input arguments used by all Leg types. Besides fixed_rate
, a
FixedLeg
can demonstrate all of the standard arguments to
a BaseLeg.
For complete documentation of some of these inputs see Scheduling.
In [1]: fixed_leg = FixedLeg(
...: effective=dt(2022, 1, 15), # <- Scheduling options start here
...: termination=dt(2022, 12, 7),
...: frequency="Q",
...: stub="ShortFrontShortBack",
...: front_stub=dt(2022, 2, 28),
...: back_stub=dt(2022, 11, 30),
...: roll=31,
...: eom=True,
...: modifier="MF",
...: calendar="nyc",
...: payment_lag=2,
...: payment_lag_exchange=0,
...: notional=2000000, # <- Generic options start here
...: currency="usd",
...: amortization=250000,
...: convention="act360",
...: initial_exchange=False,
...: final_exchange=False,
...: fixed_rate=1.0, # <- FixedLeg only options start here
...: )
...:
In [2]: fixed_leg.cashflows(curve)
Out[2]:
Type Period Ccy Acc Start Acc End Payment Convention DCF Notional DF Collateral Rate Spread Cashflow NPV FX Rate NPV Ccy
0 FixedPeriod Stub USD 2022-01-18 2022-02-28 2022-03-02 act360 0.11 2000000.00 1.00 None 1.00 None -2277.78 -2274.02 1.00 -2274.02
1 FixedPeriod Regular USD 2022-02-28 2022-05-31 2022-06-02 act360 0.26 1750000.00 1.00 None 1.00 None -4472.22 -4453.54 1.00 -4453.54
2 FixedPeriod Regular USD 2022-05-31 2022-08-31 2022-09-02 act360 0.26 1500000.00 0.99 None 1.00 None -3833.33 -3807.67 1.00 -3807.67
3 FixedPeriod Regular USD 2022-08-31 2022-11-30 2022-12-02 act360 0.25 1250000.00 0.99 None 1.00 None -3159.72 -3130.71 1.00 -3130.71
4 FixedPeriod Stub USD 2022-11-30 2022-12-07 2022-12-09 act360 0.02 1000000.00 0.99 None 1.00 None -194.44 -192.62 1.00 -192.62
FloatLeg
offer the same arguments with the additional
inputs that are appropriate for calculating a FloatPeriod
.
In [3]: float_leg = FloatLeg(
...: effective=dt(2022, 1, 15), # <- Scheduling options start here
...: termination=dt(2022, 12, 7),
...: frequency="Q",
...: stub="ShortFrontShortBack",
...: front_stub=dt(2022, 2, 28),
...: back_stub=dt(2022, 11, 30),
...: roll=31,
...: eom=True,
...: modifier="MF",
...: calendar="nyc",
...: payment_lag=2,
...: payment_lag_exchange=0,
...: notional=2000000, # <- Generic options start here
...: currency="usd",
...: amortization=250000,
...: convention="act360",
...: initial_exchange=False,
...: final_exchange=False,
...: float_spread=1.0, # <- FloatLeg only options start here
...: fixings=NoInput(0),
...: fixing_method="rfr_payment_delay",
...: method_param=NoInput(0),
...: spread_compound_method="none_simple",
...: )
...:
In [4]: float_leg.cashflows(curve)
Out[4]:
Type Period Ccy Acc Start Acc End Payment Convention DCF Notional DF Collateral Rate Spread Cashflow NPV FX Rate NPV Ccy
0 FloatPeriod Stub USD 2022-01-18 2022-02-28 2022-03-02 act360 0.11 2000000.00 1.00 None 1.00 1.00 -2281.94 -2278.17 1.00 -2278.17
1 FloatPeriod Regular USD 2022-02-28 2022-05-31 2022-06-02 act360 0.26 1750000.00 1.00 None 1.00 1.00 -4483.50 -4464.78 1.00 -4464.78
2 FloatPeriod Regular USD 2022-05-31 2022-08-31 2022-09-02 act360 0.26 1500000.00 0.99 None 1.00 1.00 -3843.00 -3817.27 1.00 -3817.27
3 FloatPeriod Regular USD 2022-08-31 2022-11-30 2022-12-02 act360 0.25 1250000.00 0.99 None 1.00 1.00 -3167.65 -3138.56 1.00 -3138.56
4 FloatPeriod Stub USD 2022-11-30 2022-12-07 2022-12-09 act360 0.02 1000000.00 0.99 None 1.00 1.00 -194.71 -192.88 1.00 -192.88
These basic Legs are most commonly used in the construction
of IRS
and SBS
.
Legs with Exchanged Notionals#
Bonds
, CrossCurrencySwaps
and IndexSwaps
involve Legs with exchanged
notionals, which are represented as Cashflow
s.
These Legs have the option of an initial exchange and also of a
final exchange. Interim exchanges (amortization) will only be applied if
there is also a final exchange.
The arguments are the same as the previous FixedLeg
and FloatLeg
classes, except attention is drawn to the
provided arguments:
initial_exchange
,final_exchange
,payment_lag_exchange
,
This allows for configuration of separate payment lags for notional exchanges and regular period flows, which is common practice on CrossCurrencySwaps for example.
In [5]: fixed_leg_exch = FixedLeg(
...: effective=dt(2022, 1, 15), # <- Scheduling options start here
...: termination=dt(2022, 7, 15),
...: frequency="Q",
...: stub=NoInput(0),
...: front_stub=NoInput(0),
...: back_stub=NoInput(0),
...: roll=NoInput(0),
...: eom=True,
...: modifier="MF",
...: calendar="nyc",
...: payment_lag=2,
...: payment_lag_exchange=0,
...: notional=2000000, # <- Generic options start here
...: currency="usd",
...: amortization=250000,
...: convention="act360",
...: initial_exchange=True,
...: final_exchange=True,
...: fixed_rate=5.0, # <- FixedLeg only options start here
...: )
...:
In [6]: fixed_leg_exch.cashflows(curve)
Out[6]:
Type Period Ccy Acc Start Acc End Payment Convention DCF Notional DF Rate Spread Cashflow NPV FX Rate NPV Ccy Collateral
0 Cashflow Exchange USD NaT NaT 2022-01-18 None NaN -2000000.00 1.00 NaN None 2000000.00 1999064.02 1.00 1999064.02 None
1 FixedPeriod Regular USD 2022-01-18 2022-04-18 2022-04-20 act360 0.25 2000000.00 1.00 5.00 None -25000.00 -24925.08 1.00 -24925.08 None
2 Cashflow Amortization USD NaT NaT 2022-04-18 None NaN 250000.00 1.00 NaN None -250000.00 -249264.52 1.00 -249264.52 None
3 FixedPeriod Regular USD 2022-04-18 2022-07-15 2022-07-19 act360 0.24 1750000.00 0.99 5.00 None -21388.89 -21272.01 1.00 -21272.01 None
4 Cashflow Exchange USD NaT NaT 2022-07-15 None NaN 1750000.00 0.99 NaN None -1750000.00 -1740628.81 1.00 -1740628.81 None
Mark-to-Market Exchanged Legs#
LegMtm
objects are common on CrossCurrencySwaps
.
Whilst the other leg types are technically indifferent regarding the currency
they are initialised with, LegMtms require a domestic currency and an alternative
currency against which MTM calculations can be measured. The notional
of the
MtmLeg
is variable according to the fixed alt_notional
and the forward
FX rates. Thus the additional arguments in this leg are:
alt_notional
alt_currency
fx_fixings
notional
is not used in this leg type and is overwritten.
Otherwise, the arguments are the same as the
previous FixedLeg
and FloatLeg
.
In [7]: float_leg_exch = FloatLegMtm(
...: effective=dt(2022, 1, 3), # <- Scheduling options start here
...: termination=dt(2022, 7, 3),
...: frequency="Q",
...: stub=NoInput(0),
...: front_stub=NoInput(0),
...: back_stub=NoInput(0),
...: roll=NoInput(0),
...: eom=True,
...: modifier="MF",
...: calendar="nyc",
...: payment_lag=2,
...: payment_lag_exchange=0,
...: notional=None, # <- Generic options start here
...: currency="usd",
...: amortization=NoInput(0),
...: convention="act360",
...: initial_exchange=True,
...: final_exchange=True,
...: float_spread=0.0, # <- FloatLeg only options start here
...: fixings=NoInput(0),
...: fixing_method="rfr_payment_delay",
...: method_param=NoInput(0),
...: spread_compound_method="none_simple",
...: alt_notional=2000000, # <- MtmLeg only options start here
...: alt_currency="eur",
...: fx_fixings=NoInput(0),
...: )
...:
In [8]: fxr = FXRates({"eurusd": 1.05}, settlement = dt(2022, 1, 3))
In [9]: fxf = FXForwards(fxr, {
...: "usdusd": Curve({dt(2022, 1, 1): 1.0, dt(2023, 1, 1): 0.965}),
...: "eureur": Curve({dt(2022, 1, 1): 1.0, dt(2023, 1, 1): 0.985}),
...: "eurusd": Curve({dt(2022, 1, 1): 1.0, dt(2023, 1, 1): 0.987}),
...: })
...:
In [10]: float_leg_exch.cashflows(curve, curve, fxf)
Out[10]:
Type Period Ccy Acc Start Acc End Payment Convention DCF Notional DF Rate Spread Cashflow NPV FX Rate NPV Ccy Collateral
0 Cashflow Exchange USD NaT NaT 2022-01-03 None NaN -2100000.00 1.00 1.05 NaN 2100000.00 2099884.36 1.00 2099884.36 None
1 FloatPeriod Regular USD 2022-01-03 2022-04-04 2022-04-06 act360 0.25 2100000.00 1.00 0.99 0.00 -5268.57 -5254.80 1.00 -5254.80 None
2 Cashflow Mtm USD NaT NaT 2022-04-04 None NaN -11835.32 1.00 1.06 NaN 11835.32 11805.05 1.00 11805.05 None
3 FloatPeriod Regular USD 2022-04-04 2022-07-05 2022-07-07 act360 0.26 2111835.32 0.99 0.99 0.00 -5356.56 -5329.05 1.00 -5329.05 None
4 Cashflow Exchange USD NaT NaT 2022-07-05 None NaN 2111835.32 0.99 1.06 NaN -2111835.32 -2101104.97 1.00 -2101104.97 None