CustomLeg#
- class rateslib.legs.CustomLeg(periods)#
Bases:
BaseLeg
Create a leg contained of user specified
Periods
.Useful for crafting amortising swaps with custom notional and date schedules.
- Parameters:
periods (iterable of
Period
types) – A sequence ofPeriods
to attach to the leg.
- periods#
- Type:
list[Periods]
Examples
In [1]: fp1 = FixedPeriod(dt(2021,1,1), dt(2021,7,1), dt(2021,7,2), "Q", 1e6, "Act365F", fixed_rate=2.10) In [2]: fp2 = FixedPeriod(dt(2021,3,7), dt(2021,9,7), dt(2021,9,8), "Q", -5e6, "Act365F", fixed_rate=3.10) In [3]: custom_leg = CustomLeg(periods=[fp1, fp2]) In [4]: custom_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 FixedPeriod Regular ACT365F 2021-01-01 2021-07-01 2021-07-02 Act360 0.502778 1000000.0 0.977056 None 2.1 None -10558.333333 -10316.081105 1.0 -10316.081105 1 FixedPeriod Regular ACT365F 2021-03-07 2021-09-07 2021-09-08 Act360 0.511111 -5000000.0 0.968619 None 3.1 None 79222.222222 76736.151345 1.0 76736.151345
Methods Summary
analytic_delta
(*args, **kwargs)Return the analytic delta of the CustomLeg via summing all periods.
cashflows
(*args, **kwargs)Return the properties of the CustomLeg used in calculating cashflows.
npv
(*args, **kwargs)Return the NPV of the CustomLeg via summing all periods.
Methods Documentation
- analytic_delta(*args, **kwargs)#
Return the analytic delta of the CustomLeg via summing all periods.
For arguments see
BasePeriod.analytic_delta()
.
- cashflows(*args, **kwargs)#
Return the properties of the CustomLeg used in calculating cashflows.
For arguments see
BasePeriod.cashflows()
.
- npv(*args, **kwargs)#
Return the NPV of the CustomLeg via summing all periods.
For arguments see
BasePeriod.npv()
.