BaseMixin#

class rateslib.instruments.BaseMixin#

Bases: object

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[, leg])

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.

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

Return the NPV of the derivative object by summing legs.

rate(*args, **kwargs)

Return the rate or typical price for a derivative instrument.

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

abstract analytic_delta(*args, leg=1, **kwargs)#

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

Parameters:
  • args – Required positional arguments supplied to BaseLeg.analytic_delta.

  • leg (int in [1, 2]) – The leg identifier of which to take the analytic delta.

  • kwargs – Required Keyword arguments supplied to BaseLeg.analytic_delta().

Return type:

float, Dual, Dual2

Examples

In [4]: curve = Curve({dt(2021,1,1): 1.00, dt(2025,1,1): 0.83}, id="SONIA")

In [5]: fxr = FXRates({"gbpusd": 1.25}, base="usd")
In [6]: irs = IRS(
   ...:     effective=dt(2022, 1, 1),
   ...:     termination="6M",
   ...:     frequency="Q",
   ...:     currency="gbp",
   ...:     notional=1e9,
   ...:     fixed_rate=5.0,
   ...: )
   ...: 

In [7]: irs.analytic_delta(curve, curve)
Out[7]: 47156.00216054951

In [8]: irs.analytic_delta(curve, curve, fxr)
Out[8]: <Dual: 58945.002701, (fx_gbpusd), [47156.0]>

In [9]: irs.analytic_delta(curve, curve, fxr, "gbp")
Out[9]: 47156.00216054951
abstract cashflows(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank)#

Return the properties of all legs used in calculating cashflows.

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

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

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

  • fx (float, FXRates, FXForwards, optional) – The immediate settlement FX rate that will be used to convert values into another currency. A given float is used directly. If giving a FXRates or FXForwards object, converts from local currency into base.

  • base (str, optional) – The base currency to convert cashflows into (3-digit code). Only used if fx is an FXRates or FXForwards object. If not given defaults to fx.base.

Return type:

DataFrame

Notes

If only one curve is given this is used as all four curves.

If two curves are given the forecasting curve is used as the forecasting curve on both legs and the discounting curve is used as the discounting curve for both legs.

If three curves are given the single discounting curve is used as the discounting curve for both legs.

Examples

In [10]: irs.cashflows([curve], fx=fxr)
Out[10]: 
               Type   Period  Ccy  Acc Start    Acc End    Payment Convention  DCF       Notional   DF Collateral  Rate  Spread     Cashflow          NPV  FX Rate      NPV Ccy
leg1 0  FixedPeriod  Regular  GBP 2022-01-01 2022-04-01 2022-04-03     ACT360 0.25  1000000000.00 0.94       None  5.00     NaN -12500000.00 -11792277.34     1.25 -14740346.67
     1  FixedPeriod  Regular  GBP 2022-04-01 2022-07-01 2022-07-03     ACT360 0.25  1000000000.00 0.93       None  5.00     NaN -12638888.89 -11785723.74     1.25 -14732154.68
leg2 0  FloatPeriod  Regular  GBP 2022-01-01 2022-04-01 2022-04-03     ACT360 0.25 -1000000000.00 0.94       None  4.62    0.00  11544335.50  10890720.47     1.25  13613400.59
     1  FloatPeriod  Regular  GBP 2022-04-01 2022-07-01 2022-07-03     ACT360 0.25 -1000000000.00 0.93       None  4.62    0.00  11673351.69  10885363.37     1.25  13606704.21
abstract 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.

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

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

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

  • fx (float, FXRates, FXForwards, optional) – The immediate settlement FX rate that will be used to convert values into another currency. A given float is used directly. If giving a FXRates or FXForwards object, converts from local currency into base.

  • base (str, optional) – The base currency to convert cashflows into (3-digit code). Only used if fx is an FXRates or FXForwards object. If not given defaults to fx.base.

  • local (bool, optional) – If True will return a dict identifying NPV by local currencies on each leg. Useful for multi-currency derivatives and for ensuring risk sensitivities are allocated to local currencies without conversion.

Return type:

float, Dual or Dual2, or dict of such.

Notes

If only one curve is given this is used as all four curves.

If two curves are given the forecasting curve is used as the forecasting curve on both legs and the discounting curve is used as the discounting curve for both legs.

If three curves are given the single discounting curve is used as the discounting curve for both legs.

Examples

In [11]: irs.npv(curve)
Out[11]: -1801917.2427669652

In [12]: irs.npv([curve], fx=fxr)
Out[12]: <Dual: -2252396.553459, (fx_gbpusd), [-1801917.2]>

In [13]: irs.npv([curve], fx=fxr, base="gbp")
Out[13]: -1801917.2427669652
abstract rate(*args, **kwargs)#

Return the rate or typical price for a derivative instrument.

Return type:

Dual

Notes

This method must be implemented for instruments to function effectively in Solver iterations.