FloatLeg#

class rateslib.legs.FloatLeg(*args, float_spread=NoInput.blank, fixings=NoInput.blank, fixing_method=NoInput.blank, method_param=NoInput.blank, spread_compound_method=NoInput.blank, **kwargs)#

Bases: _FloatLegMixin, BaseLeg

Create a floating leg composed of FloatPeriod s.

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

  • float_spread (float, optional) – The spread applied to determine cashflows in bps (i.e. 100 = 1%). Can be set to None and designated later, perhaps after a mid-market spread for all periods has been calculated.

  • spread_compound_method (str, optional) – The method to use for adding a floating spread to compounded rates. Available options are {“none_simple”, “isda_compounding”, “isda_flat_compounding”}.

  • fixings (float, list, Series, 2-tuple, optional) – If a float scalar, will be applied as the determined fixing for the first period. If a list of n fixings will be used as the fixings for the first n periods. If any sublist of length m is given, is used as the first m RFR fixings for that FloatPeriod. If a datetime indexed Series will use the fixings that are available in that object, and derive the rest from the curve. If a 2-tuple of value and Series, the first scalar value is applied to the first period and latter periods handled as with Series.

  • fixing_method (str, optional) – The method by which floating rates are determined, set by default. See notes.

  • method_param (int, optional) – A parameter that is used for the various fixing_method s. See notes.

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

Notes

The NPV of a FloatLeg is the sum of the period NPVs.

\[P = \underbrace{- \sum_{i=1}^n {N_i r_i(r_j, z) d_i v_i(m_i)}}_{\text{regular flows}} \underbrace{+ N_1 v(m_0) - \sum_{i=1}^{n-1}v(m_i)(N_{i}-N_{i+1}) - N_n v(m_n)}_{\text{exchange flows}}\]

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

\[A = -\frac{\partial P}{\partial z} = \sum_{i=1}^n {\frac{\partial r_i}{\partial z} N_i d_i v_i(m_i)}\]

Warning

When floating rates are determined from historical fixings the forecast Curve calendar will be used to determine fixing dates. If this calendar does not align with the Leg calendar then spurious results or errors may be generated.

Including the curve calendar within a Leg multi-holiday calendar is acceptable, i.e. a Leg calendar of “nyc,ldn,tgt” and a curve calendar of “ldn” is valid. A Leg calendar of just “nyc,tgt” may give errors.

Examples

Set the first fixing on an historic IBOR leg.

In [1]: float_leg = FloatLeg(
   ...:     schedule=Schedule(dt(2021, 12, 1), "9M", "Q"),
   ...:     fixing_method="ibor",
   ...:     fixings=2.00,
   ...: )
   ...: 

In [2]: float_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  FloatPeriod  Regular  USD 2021-12-01 2022-03-01 2022-03-03     Act360  0.250000  1000000.0  0.996629       None  2.000000     0.0 -5000.000000 -4983.146753      1.0 -4983.146753
1  FloatPeriod  Regular  USD 2022-03-01 2022-06-01 2022-06-03     Act360  0.255556  1000000.0  0.991567       None  1.997678     0.0 -5105.176472 -5062.125667      1.0 -5062.125667
2  FloatPeriod  Regular  USD 2022-06-01 2022-09-01 2022-09-03     Act360  0.255556  1000000.0  0.986531       None  1.997678     0.0 -5105.176472 -5036.413886      1.0 -5036.413886

Set multiple fixings on an historic IBOR leg.

In [3]: float_leg = FloatLeg(
   ...:     schedule=Schedule(dt(2021, 9, 1), "12M", "Q"),
   ...:     fixing_method="ibor",
   ...:     fixings=[1.00, 2.00],
   ...: )
   ...: 

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  Regular  USD 2021-09-01 2021-12-01 2021-12-03     Act360  0.252778  1000000.0  0.000000       None  1.000000     0.0 -2527.777778     0.000000      1.0     0.000000
1  FloatPeriod  Regular  USD 2021-12-01 2022-03-01 2022-03-03     Act360  0.250000  1000000.0  0.996629       None  2.000000     0.0 -5000.000000 -4983.146753      1.0 -4983.146753
2  FloatPeriod  Regular  USD 2022-03-01 2022-06-01 2022-06-03     Act360  0.255556  1000000.0  0.991567       None  1.997678     0.0 -5105.176472 -5062.125667      1.0 -5062.125667
3  FloatPeriod  Regular  USD 2022-06-01 2022-09-01 2022-09-03     Act360  0.255556  1000000.0  0.986531       None  1.997678     0.0 -5105.176472 -5036.413886      1.0 -5036.413886

It is not best practice to supply fixings as a list of values. It is better to supply a Series indexed by IBOR publication date (in this case lagged by zero days).

In [5]: float_leg = FloatLeg(
   ...:     schedule=Schedule(dt(2021, 9, 1), "12M", "Q"),
   ...:     fixing_method="ibor",
   ...:     method_param=0,
   ...:     fixings=Series([1.00, 2.00], index=[dt(2021, 9, 1), dt(2021, 12, 1)])
   ...: )
   ...: 

In [6]: float_leg.cashflows(curve)
Out[6]: 
          Type   Period  Ccy  Acc Start    Acc End    Payment Convention       DCF   Notional        DF Collateral      Rate  Spread     Cashflow          NPV  FX Rate      NPV Ccy
0  FloatPeriod  Regular  USD 2021-09-01 2021-12-01 2021-12-03     Act360  0.252778  1000000.0  0.000000       None  1.000000     0.0 -2527.777778     0.000000      1.0     0.000000
1  FloatPeriod  Regular  USD 2021-12-01 2022-03-01 2022-03-03     Act360  0.250000  1000000.0  0.996629       None  2.000000     0.0 -5000.000000 -4983.146753      1.0 -4983.146753
2  FloatPeriod  Regular  USD 2022-03-01 2022-06-01 2022-06-03     Act360  0.255556  1000000.0  0.991567       None  1.997678     0.0 -5105.176472 -5062.125667      1.0 -5062.125667
3  FloatPeriod  Regular  USD 2022-06-01 2022-09-01 2022-09-03     Act360  0.255556  1000000.0  0.986531       None  1.997678     0.0 -5105.176472 -5036.413886      1.0 -5036.413886

Set the initial RFR fixings in the first period of an RFR leg (notice the sublist and the implied -10% year end turn spread).

In [7]: swestr_curve = Curve({dt(2023, 1, 2): 1.0, dt(2023, 7, 2): 0.99}, calendar="stk")

In [8]: float_leg = FloatLeg(
   ...:     schedule=Schedule(dt(2022, 12, 28), "2M", "M", calendar="stk"),
   ...:     fixings=[[1.19, 1.19, -8.81]],
   ...:     currency="SEK",
   ...: )
   ...: 

In [9]: float_leg.cashflows(swestr_curve)
Out[9]: 
          Type   Period  Ccy  Acc Start    Acc End    Payment Convention       DCF   Notional        DF Collateral      Rate  Spread     Cashflow          NPV  FX Rate      NPV Ccy
0  FloatPeriod  Regular  SEK 2022-12-28 2023-01-30 2023-02-01     Act360  0.091667  1000000.0  0.998336       None  0.967434     0.0  -886.814795  -885.338768      1.0  -885.338768
1  FloatPeriod  Regular  SEK 2023-01-30 2023-02-28 2023-03-02     Act360  0.080556  1000000.0  0.996729       None  2.000572     0.0 -1611.571994 -1606.301000      1.0 -1606.301000

In [10]: float_leg.fixings_table(swestr_curve)[dt(2022,12,28):dt(2023,1,4)]
Out[10]: 
                    15722                              
                 notional      risk       dcf     rates
obs_dates                                              
2022-12-28       0.000000  0.000000  0.002778  1.190000
2022-12-29       0.000000  0.000000  0.002778  1.190000
2022-12-30       0.000000  0.000000  0.008333 -8.810000
2023-01-02 -999220.923922 -0.277546  0.002778  1.999017
2023-01-03 -999276.408920 -0.277546  0.002778  1.999017
2023-01-04 -999331.897000 -0.277546  0.002778  1.999017

Again, this is poor practice. It is best practice to supply a Series of RFR rates by reference value date.

In [11]: float_leg = FloatLeg(
   ....:     schedule=Schedule(dt(2022, 12, 28), "2M", "M", calendar="stk"),
   ....:     fixings=Series([1.19, 1.19, -8.81], index=[dt(2022, 12, 28), dt(2022, 12, 29), dt(2022, 12, 30)]),
   ....:     currency="SEK",
   ....: )
   ....: 

In [12]: float_leg.cashflows(swestr_curve)
Out[12]: 
          Type   Period  Ccy  Acc Start    Acc End    Payment Convention       DCF   Notional        DF Collateral      Rate  Spread     Cashflow          NPV  FX Rate      NPV Ccy
0  FloatPeriod  Regular  SEK 2022-12-28 2023-01-30 2023-02-01     Act360  0.091667  1000000.0  0.998336       None  0.967434     0.0  -886.814795  -885.338768      1.0  -885.338768
1  FloatPeriod  Regular  SEK 2023-01-30 2023-02-28 2023-03-02     Act360  0.080556  1000000.0  0.996729       None  2.000572     0.0 -1611.571994 -1606.301000      1.0 -1606.301000

In [13]: float_leg.fixings_table(swestr_curve)[dt(2022,12,28):dt(2023,1,4)]
Out[13]: 
                    15722                              
                 notional      risk       dcf     rates
obs_dates                                              
2022-12-28       0.000000  0.000000  0.002778  1.190000
2022-12-29       0.000000  0.000000  0.002778  1.190000
2022-12-30       0.000000  0.000000  0.008333 -8.810000
2023-01-02 -999220.923922 -0.277546  0.002778  1.999017
2023-01-03 -999276.408920 -0.277546  0.002778  1.999017
2023-01-04 -999331.897000 -0.277546  0.002778  1.999017

Methods Summary

analytic_delta(*args, **kwargs)

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

cashflows(*args, **kwargs)

Return the properties of the FloatLeg used in calculating cashflows.

fixings_table(curve[, disc_curve, fx, base, ...])

Return a DataFrame of fixing exposures on a FloatLeg.

npv(*args, **kwargs)

Return the NPV of the FloatLeg via summing all periods.

Methods Documentation

analytic_delta(*args, **kwargs)#

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

For arguments see BasePeriod.analytic_delta().

cashflows(*args, **kwargs)#

Return the properties of the FloatLeg used in calculating cashflows.

For arguments see BasePeriod.cashflows().

fixings_table(curve, disc_curve=NoInput.blank, fx=NoInput.blank, base=NoInput.blank, approximate=False, right=NoInput.blank)#

Return a DataFrame of fixing exposures on a FloatLeg.

Parameters:
  • curve (Curve, optional) – The forecasting curve object.

  • disc_curve (Curve, optional) – The discounting curve object used in calculations. Set equal to curve if not given and curve is discount factor based.

  • fx (float, FXRates, FXForwards, optional) – Only used in the case of FloatLegMtm to derive FX fixings.

  • base (str, optional) – Not used by fixings_table.

  • approximate (bool) – Whether to use a faster (3x) but marginally less accurate (0.1% error) calculation.

  • right (datetime, optional) – Only calculate fixing exposures upto and including this date.

Return type:

DataFrame

npv(*args, **kwargs)#

Return the NPV of the FloatLeg via summing all periods.

For arguments see BasePeriod.npv().