SBS#

class rateslib.instruments.SBS(*args, float_spread=NoInput.blank, spread_compound_method=NoInput.blank, fixings=NoInput.blank, fixing_method=NoInput.blank, method_param=NoInput.blank, leg2_float_spread=NoInput.blank, leg2_spread_compound_method=NoInput.blank, leg2_fixings=NoInput.blank, leg2_fixing_method=NoInput.blank, leg2_method_param=NoInput.blank, **kwargs)#

Bases: BaseDerivative

Create a single currency basis swap composing two FloatLeg s.

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

  • float_spread (float, optional) – The spread applied to the FloatLeg. 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, or Series 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.

  • 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.

  • leg2_float_spread (float or None) – The floating spread applied in a simple way (after daily compounding) to the second FloatLeg. If None will be set to zero. float_spread : float, optional The spread applied to the FloatLeg. Can be set to None and designated later, perhaps after a mid-market spread for all periods has been calculated.

  • leg2_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”}.

  • leg2_fixings (float, list, or Series 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.

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

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

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

Examples

Construct curves to price the example.

In [1]: eur3m = Curve(
   ...:     nodes={
   ...:         dt(2022, 1, 1): 1.0,
   ...:         dt(2023, 1, 1): 0.965,
   ...:         dt(2024, 1, 1): 0.94
   ...:     },
   ...:     id="eur3m",
   ...: )
   ...: 

In [2]: eur6m = Curve(
   ...:     nodes={
   ...:         dt(2022, 1, 1): 1.0,
   ...:         dt(2023, 1, 1): 0.962,
   ...:         dt(2024, 1, 1): 0.936
   ...:     },
   ...:     id="eur6m",
   ...: )
   ...: 

Create the SBS, and demonstrate the rate(), npv(), analytic_delta(), and spread().

In [3]: sbs = SBS(
   ...:     effective=dt(2022, 1, 1),
   ...:     termination="18M",
   ...:     frequency="Q",
   ...:     leg2_frequency="S",
   ...:     calendar="tgt",
   ...:     currency="eur",
   ...:     fixing_method="ibor",
   ...:     method_param=2,
   ...:     convention="Act360",
   ...:     leg2_float_spread=-22.9,
   ...:     notional=100e6,
   ...:     curves=["eur3m", "eur3m", "eur6m", "eur3m"],
   ...: )
   ...: 

In [4]: sbs.rate(curves=[eur3m, eur3m, eur6m, eur3m])
Out[4]: 2.0110843167657118

In [5]: sbs.npv(curves=[eur3m, eur3m, eur6m, eur3m])
Out[5]: 29592.78143321164

In [6]: sbs.analytic_delta(curve=eur6m, disc_curve=eur3m, leg=2)
Out[6]: -14655.336027072415

In [7]: sbs.spread(curves=[eur3m, eur3m, eur6m, eur3m], leg=2)
Out[7]: -24.919249601547563

A DataFrame of cashflows().

In [8]: sbs.cashflows(curves=[eur3m, eur3m, eur6m, eur3m])
Out[8]: 
               Type   Period  Ccy  Acc Start    Acc End    Payment Convention       DCF     Notional        DF Collateral      Rate  Spread      Cashflow           NPV  FX Rate       NPV Ccy
leg1 0  FloatPeriod  Regular  EUR 2022-01-03 2022-04-01 2022-04-05     Act360  0.244444  100000000.0  0.990867       None  3.529393     0.0 -8.627406e+05 -8.548609e+05      1.0 -8.548609e+05
     1  FloatPeriod  Regular  EUR 2022-04-01 2022-07-01 2022-07-05     Act360  0.252778  100000000.0  0.982104       None  3.529566     0.0 -8.921958e+05 -8.762294e+05      1.0 -8.762294e+05
     2  FloatPeriod  Regular  EUR 2022-07-01 2022-10-03 2022-10-05     Act360  0.261111  100000000.0  0.973325       None  3.529738     0.0 -9.216539e+05 -8.970684e+05      1.0 -8.970684e+05
     3  FloatPeriod  Regular  EUR 2022-10-03 2023-01-02 2023-01-04     Act360  0.252778  100000000.0  0.964792       None  3.509448     0.0 -8.871104e+05 -8.558768e+05      1.0 -8.558768e+05
     4  FloatPeriod  Regular  EUR 2023-01-02 2023-04-03 2023-04-05     Act360  0.252778  100000000.0  0.958499       None  2.597262     0.0 -6.565301e+05 -6.292833e+05      1.0 -6.292833e+05
     5  FloatPeriod  Regular  EUR 2023-04-03 2023-07-03 2023-07-05     Act360  0.252778  100000000.0  0.952247       None  2.597356     0.0 -6.565538e+05 -6.252012e+05      1.0 -6.252012e+05
leg2 0  FloatPeriod  Regular  EUR 2022-01-03 2022-07-01 2022-07-05     Act360  0.497222 -100000000.0  0.982104       None  3.628542   -22.9  1.804192e+06  1.771905e+06      1.0  1.771905e+06
     1  FloatPeriod  Regular  EUR 2022-07-01 2023-01-02 2023-01-04     Act360  0.513889 -100000000.0  0.964792       None  3.623608   -22.9  1.862132e+06  1.796569e+06      1.0  1.796569e+06
     2  FloatPeriod  Regular  EUR 2023-01-02 2023-07-03 2023-07-05     Act360  0.505556 -100000000.0  0.952247       None  2.491909   -22.9  1.259798e+06  1.199639e+06      1.0  1.199639e+06

For accurate sensitivity calculations; delta() and gamma(), construct a curve model.

In [9]: irs_kws = dict(
   ...:     effective=dt(2022, 1, 1),
   ...:     frequency="A",
   ...:     leg2_frequency="Q",
   ...:     convention="30E360",
   ...:     leg2_convention="Act360",
   ...:     leg2_fixing_method="ibor",
   ...:     leg2_method_param=2,
   ...:     calendar="tgt",
   ...:     currency="eur",
   ...:     curves=["eur3m", "eur3m"],
   ...: )
   ...: 

In [10]: sbs_kws = dict(
   ....:     effective=dt(2022, 1, 1),
   ....:     frequency="Q",
   ....:     leg2_frequency="S",
   ....:     convention="Act360",
   ....:     fixing_method="ibor",
   ....:     method_param=2,
   ....:     leg2_convention="Act360",
   ....:     calendar="tgt",
   ....:     currency="eur",
   ....:     curves=["eur3m", "eur3m", "eur6m", "eur3m"]
   ....: )
   ....: 

In [11]: instruments = [
   ....:     IRS(termination="1Y", **irs_kws),
   ....:     IRS(termination="2Y", **irs_kws),
   ....:     SBS(termination="1Y", **sbs_kws),
   ....:     SBS(termination="2Y", **sbs_kws),
   ....: ]
   ....: 

In [12]: solver = Solver(
   ....:     curves=[eur3m, eur6m],
   ....:     instruments=instruments,
   ....:     s=[1.55, 1.6, 5.5, 6.5],
   ....:     instrument_labels=["1Y", "2Y", "1Y 3s6s", "2Y 3s6s"],
   ....:     id="eur",
   ....: )
   ....: 
SUCCESS: `func_tol` reached after 4 iterations (levenberg_marquardt), `f_val`: 1.510220670780831e-13, `time`: 0.0281s

In [13]: sbs.delta(solver=solver)
Out[13]: 
local_ccy                           eur
display_ccy                         eur
type        solver label               
instruments eur    1Y         16.697385
                   2Y          9.310094
                   1Y 3s6s  4999.601921
                   2Y 3s6s  9960.313305

In [14]: sbs.gamma(solver=solver)
Out[14]: 
type                                             instruments                              
solver                                                   eur                              
label                                                     1Y        2Y   1Y 3s6s   2Y 3s6s
local_ccy display_ccy type        solver label                                            
eur       eur         instruments eur    1Y        -0.002189 -0.002239 -0.189954 -0.743437
                                         2Y        -0.002239  0.001696 -0.245952 -0.121302
                                         1Y 3s6s   -0.189954 -0.245952 -0.000700  0.001391
                                         2Y 3s6s   -0.743437 -0.121302  0.001391 -0.002763

Attributes Summary

fixed_rate

If set will also set the fixed_rate of the contained leg1.

float_spread

If set will also set the float_spread of contained leg1.

index_base

If set will also set the index_base of the contained leg1.

leg2_fixed_rate

If set will also set the fixed_rate of the contained leg2.

leg2_float_spread

If set will also set the float_spread of contained leg2.

leg2_index_base

If set will also set the index_base of the contained leg1.

Methods Summary

analytic_delta(*args, **kwargs)

Return the analytic delta of a leg of the derivative object.

cashflows([curves, solver, fx, base])

Return the properties of all legs used in calculating cashflows.

cashflows_table([curves, solver, fx, base])

Aggregate the values derived from a cashflows() method on an Instrument.

delta(*args, **kwargs)

Calculate the delta of the Instrument.

exo_delta(*args, **kwargs)

Calculate the delta of the Instrument, measured against user defined Variable s.

fixings_table([curves, solver, fx, base, ...])

Return a DataFrame of fixing exposures on the FloatLeg.

gamma(*args, **kwargs)

Calculate the gamma of the Instrument.

npv([curves, solver, fx, base, local])

Return the NPV of the derivative object by summing legs.

rate([curves, solver, fx, base, leg])

Return the mid-market float spread on the specified leg of the SBS.

spread(*args, **kwargs)

Return the mid-market float spread on the specified leg of the SBS.

Attributes Documentation

fixed_rate#

If set will also set the fixed_rate of the contained leg1.

Note

fixed_rate, float_spread, leg2_fixed_rate and leg2_float_spread are attributes only applicable to certain Instruments. AttributeErrors are raised if calling or setting these is invalid.

Type:

float or None

float_spread#

If set will also set the float_spread of contained leg1.

Type:

float or None

index_base#

If set will also set the index_base of the contained leg1.

Note

index_base and leg2_index_base are attributes only applicable to certain Instruments. AttributeErrors are raised if calling or setting these is invalid.

Type:

float or None

leg2_fixed_rate#

If set will also set the fixed_rate of the contained leg2.

Type:

float or None

leg2_float_spread#

If set will also set the float_spread of contained leg2.

Type:

float or None

leg2_index_base#

If set will also set the index_base of the contained leg1.

Note

index_base and leg2_index_base are attributes only applicable to certain Instruments. AttributeErrors are raised if calling or setting these is invalid.

Type:

float or None

Methods Documentation

analytic_delta(*args, **kwargs)#

Return the analytic delta of a leg of the derivative object.

See BaseDerivative.analytic_delta().

cashflows(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank)#

Return the properties of all legs used in calculating cashflows.

See BaseDerivative.cashflows().

cashflows_table(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank, **kwargs)#

Aggregate the values derived from a cashflows() method on an Instrument.

Parameters:
  • curves (CurveType, str or list of such, optional) – Argument input to the underlying cashflows method of the Instrument.

  • solver (Solver, optional) – Argument input to the underlying cashflows method of the Instrument.

  • fx (float, FXRates, FXForwards, optional) – Argument input to the underlying cashflows method of the Instrument.

  • base (str, optional) – Argument input to the underlying cashflows method of the Instrument.

  • kwargs (dict) – Additional arguments input the underlying cashflows method of the Instrument.

Return type:

DataFrame

delta(*args, **kwargs)#

Calculate the delta of the Instrument.

For arguments see Sensitivities.delta().

exo_delta(*args, **kwargs)#

Calculate the delta of the Instrument, measured against user defined Variable s.

For arguments see Sensitivities.exo_delta().

fixings_table(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank, approximate=False, right=NoInput.blank)#

Return a DataFrame of fixing exposures on the FloatLeg.

Parameters:
  • curves (Curve, str or list of such) –

    A single Curve or id or a list of such. A list defines the following curves in the order:

    • Forecasting Curve for floating leg.

    • Discounting Curve for both legs.

  • solver (Solver, optional) –

    The numerical Solver that constructs Curve from calibrating instruments.

    Note

    The arguments fx and base are unused by single currency derivatives rates calculations.

  • approximate (bool, optional) – Perform a calculation that is broadly 10x faster but potentially loses precision upto 0.1%.

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

Return type:

DataFrame

gamma(*args, **kwargs)#

Calculate the gamma of the Instrument.

For arguments see Sensitivities.gamma().

npv(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank, local=False)#

Return the NPV of the derivative object by summing legs.

See BaseDerivative.npv().

rate(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank, leg=1)#

Return the mid-market float spread on the specified leg of the SBS.

Parameters:
  • curves (Curve, str or list of such) –

    A list defines the following curves in the order:

    • Forecasting Curve for floating leg1.

    • Discounting Curve for both legs.

    • Forecasting Curve for floating leg2.

  • solver (Solver, optional) – The numerical Solver that constructs Curve from calibrating instruments.

  • leg (int in [1, 2]) – Specify which leg the spread calculation is applied to.

Return type:

float, Dual or Dual2

spread(*args, **kwargs)#

Return the mid-market float spread on the specified leg of the SBS.

Alias for rate().