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 of Periods 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.50  1000000.00 0.98       None  2.10   None -10558.33 -10316.08     1.00 -10316.08
1  FixedPeriod  Regular  ACT365F 2021-03-07 2021-09-07 2021-09-08     ACT360 0.51 -5000000.00 0.97       None  3.10   None  79222.22  76736.15     1.00  76736.15

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().