CreditProtectionLeg#

class rateslib.legs.CreditProtectionLeg(*args, recovery_rate=NoInput.blank, **kwargs)#

Bases: BaseLeg

Create a credit protection leg composed of CreditProtectionPeriod s.

Parameters:
  • args (tuple) – Required positional args to BaseLeg.

  • kwargs (dict) – Required keyword arguments to BaseLeg.

Notes

The NPV of a credit protection leg is the sum of the period NPVs.

\[P = \sum_{i=1}^n P_i\]

The analytic delta is the sum of the period analytic deltas.

\[A = -\frac{\partial P}{\partial S} = \sum_{i=1}^n -\frac{\partial P_i}{\partial S}\]

Examples

In [1]: disc_curve = Curve({dt(2022, 1, 1): 1.0, dt(2023, 1, 1): 0.98})

In [2]: hazard_curve = Curve({dt(2022, 1, 1): 1.0, dt(2023, 1, 1): 0.995})

In [3]: protection_leg = CreditProtectionLeg(
   ...:     dt(2022, 1, 1), "9M", "Z",
   ...:     notional=1000000,
   ...: )
   ...: 

In [4]: protection_leg.cashflows(hazard_curve, disc_curve)
Out[4]: 
                     Type   Period  Ccy  Acc Start    Acc End    Payment Convention  DCF   Notional   DF Collateral  Recovery  Survival   Cashflow      NPV  FX Rate  NPV Ccy
0  CreditProtectionPeriod  Regular  USD 2022-01-01 2022-10-01 2022-10-03     ACT360 0.76 1000000.00 0.98       None      0.40      1.00 -600000.00 -2228.38     1.00 -2228.38

In [5]: protection_leg.npv(hazard_curve, disc_curve)
Out[5]: -2228.3848975139967

Methods Summary

analytic_delta(*args, **kwargs)

Return the analytic delta of the CreditProtectionLeg via summing all periods.

analytic_rec_risk(*args, **kwargs)

Return the analytic recovery risk of the CreditProtectionLeg via summing all periods.

cashflows(*args, **kwargs)

Return the properties of the CreditProtectionLeg used in calculating cashflows.

npv(*args, **kwargs)

Return the NPV of the CreditProtectionLeg via summing all periods.

Methods Documentation

analytic_delta(*args, **kwargs)#

Return the analytic delta of the CreditProtectionLeg via summing all periods.

For arguments see BasePeriod.analytic_delta().

analytic_rec_risk(*args, **kwargs)#

Return the analytic recovery risk of the CreditProtectionLeg via summing all periods.

For arguments see BasePeriod.analytic_delta().

cashflows(*args, **kwargs)#

Return the properties of the CreditProtectionLeg used in calculating cashflows.

For arguments see BasePeriod.cashflows().

npv(*args, **kwargs)#

Return the NPV of the CreditProtectionLeg via summing all periods.

For arguments see BasePeriod.npv().