Metrics#

class rateslib.instruments.Metrics#

Bases: object

Base class for Instruments adding optional pricing parameters, such as fixed rates, float spreads etc. Also provides key pricing methods.

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.

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

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

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 [36]: curve = Curve({dt(2021,1,1): 1.00, dt(2025,1,1): 0.83}, id="SONIA")

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

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

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

In [41]: irs.analytic_delta(curve, curve, fxr, "gbp")
Out[41]: 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 [42]: irs.cashflows([curve], fx=fxr)
Out[42]: 
               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.250000  1.000000e+09  0.943382       None  5.000000     NaN -1.250000e+07 -1.179228e+07     1.25 -1.474035e+07
     1  FixedPeriod  Regular  GBP 2022-04-01 2022-07-01 2022-07-03     Act360  0.252778  1.000000e+09  0.932497       None  5.000000     NaN -1.263889e+07 -1.178572e+07     1.25 -1.473215e+07
leg2 0  FloatPeriod  Regular  GBP 2022-01-01 2022-04-01 2022-04-03     Act360  0.250000 -1.000000e+09  0.943382       None  4.617734     0.0  1.154434e+07  1.089072e+07     1.25  1.361340e+07
     1  FloatPeriod  Regular  GBP 2022-04-01 2022-07-01 2022-07-03     Act360  0.252778 -1.000000e+09  0.932497       None  4.618029     0.0  1.167335e+07  1.088536e+07     1.25  1.360670e+07
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

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 [43]: irs.npv(curve)
Out[43]: -1801917.2427671738

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

In [45]: irs.npv([curve], fx=fxr, base="gbp")
Out[45]: -1801917.2427671738
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.