IRS#

class rateslib.instruments.IRS(effective=NoInput.blank, termination=NoInput.blank, frequency=NoInput.blank, *, stub=NoInput.blank, front_stub=NoInput.blank, back_stub=NoInput.blank, roll=NoInput.blank, eom=NoInput.blank, modifier=NoInput.blank, calendar=NoInput.blank, payment_lag=NoInput.blank, payment_lag_exchange=NoInput.blank, ex_div=NoInput.blank, convention=NoInput.blank, leg2_effective=NoInput.inherit, leg2_termination=NoInput.inherit, leg2_frequency=NoInput.inherit, leg2_stub=NoInput.inherit, leg2_front_stub=NoInput.inherit, leg2_back_stub=NoInput.inherit, leg2_roll=NoInput.inherit, leg2_eom=NoInput.inherit, leg2_modifier=NoInput.inherit, leg2_calendar=NoInput.inherit, leg2_payment_lag=NoInput.inherit, leg2_payment_lag_exchange=NoInput.inherit, leg2_ex_div=NoInput.inherit, leg2_convention=NoInput.inherit, currency=NoInput.blank, notional=NoInput.blank, amortization=NoInput.blank, leg2_notional=NoInput.negate, leg2_amortization=NoInput.negate, pair=NoInput.blank, fx_fixings=NoInput.blank, leg2_fx_fixings=NoInput.inherit, fixed_rate=NoInput.blank, leg2_float_spread=NoInput.blank, leg2_spread_compound_method=NoInput.blank, leg2_rate_fixings=NoInput.blank, leg2_fixing_method=NoInput.blank, leg2_method_param=NoInput.blank, leg2_fixing_frequency=NoInput.blank, leg2_fixing_series=NoInput.blank, curves=NoInput.blank, spec=NoInput.blank)#

Bases: _BaseInstrument

An interest rate swap (IRS) composing a FixedLeg and a FloatLeg.

Examples

In [1]: irs = IRS(
   ...:     effective=dt(2000, 1, 1),
   ...:     termination="2y",
   ...:     spec="usd_irs",
   ...:     fixed_rate=2.0,
   ...: )
   ...: 

In [2]: irs.cashflows()
Out[2]: 
               Type  Ccy    Payment   Notional   Period Convention       DCF  Acc Start    Acc End    DF      Cashflow   NPV  FX Rate Base Ccy NPV Ccy Collateral  Rate  Spread
leg1 0  FixedPeriod  USD 2001-01-04  1000000.0  Regular     Act360  1.013889 2000-01-03 2001-01-02  None -20277.777778  None      1.0      USD    None       None   2.0     NaN
     1  FixedPeriod  USD 2002-01-04  1000000.0  Regular     Act360  1.013889 2001-01-02 2002-01-02  None -20277.777778  None      1.0      USD    None       None   2.0     NaN
leg2 0  FloatPeriod  USD 2001-01-04 -1000000.0  Regular     Act360  1.013889 2000-01-03 2001-01-02  None           NaN  None      1.0      USD    None       None   NaN     0.0
     1  FloatPeriod  USD 2002-01-04 -1000000.0  Regular     Act360  1.013889 2001-01-02 2002-01-02  None           NaN  None      1.0      USD    None       None   NaN     0.0

Pricing

An IRS requires a disc curve on both legs (which should be the same Curve) and a leg2 rate curve to forecast rates on the FloatLeg. The following input formats are allowed:

curves = curve | [curve]           #  a single curve is repeated for all required curves
curves = [rate_curve, disc_curve]  #  two curves are applied in the given order
curves = [None, disc_curve, rate_curve, disc_curve]     # four curves applied to each leg
curves = {"leg2_rate_curve": rate_curve, "disc_curve": disc_curve}  # dict form is explicit
Parameters:
  • .

    Note

    The following define generalised scheduling parameters.

  • effective (datetime, required) – The unadjusted effective date. If given as adjusted, unadjusted alternatives may be inferred.

  • termination (datetime, str, required) – The unadjusted termination date. If given as adjusted, unadjusted alternatives may be inferred. If given as string tenor will be calculated from effective.

  • frequency (Frequency, str, required) – The frequency of the schedule. If given as string will derive a Frequency aligning with: monthly (“M”), quarterly (“Q”), semi-annually (“S”), annually(“A”) or zero-coupon (“Z”), or a set number of calendar or business days (“_D”, “_B”), weeks (“_W”), months (“_M”) or years (“_Y”). Where required, the RollDay is derived as per roll and business day calendar as per calendar.

  • stub (StubInference, str in {“ShortFront”, “LongFront”, “ShortBack”, “LongBack”}, optional) – The stub type used if stub inference is required. If given as string will derive a StubInference.

  • front_stub (datetime, optional) – The unadjusted date for the start stub period. If given as adjusted, unadjusted alternatives may be inferred.

  • back_stub (datetime, optional) – The unadjusted date for the back stub period. If given as adjusted, unadjusted alternatives may be inferred. See notes for combining stub, front_stub and back_stub and any automatic stub inference.

  • roll (RollDay, int in [1, 31], str in {“eom”, “imm”, “som”}, optional) – The roll day of the schedule. If not given or not available in frequency will be inferred for monthly frequency variants.

  • eom (bool, optional) – Use an end of month preference rather than regular rolls for roll inference. Set by default. Not required if roll is defined.

  • modifier (Adjuster, str in {“NONE”, “F”, “MF”, “P”, “MP”}, optional) – The Adjuster used for adjusting unadjusted schedule dates into adjusted dates. If given as string must define simple date rolling rules.

  • calendar (calendar, str, optional) – The business day calendar object to use. If string will call get_calendar().

  • payment_lag (Adjuster, int, optional) – The Adjuster to use to map adjusted schedule dates into a payment date. If given as integer will define the number of business days to lag payments by.

  • payment_lag_exchange (Adjuster, int, optional) – The Adjuster to use to map adjusted schedule dates into additional payment date. If given as integer will define the number of business days to lag payments by.

  • ex_div (Adjuster, int, optional) – The Adjuster to use to map adjusted schedule dates into additional dates, which may be used, for example by fixings schedules. If given as integer will define the number of business days to lag dates by.

  • convention (str, optional (set by ‘defaults’)) – The day count convention applied to calculations of period accrual dates. See dcf().

  • leg2_effective (datetime, optional (inherited from leg1))

  • leg2_termination (datetime, str, optional (inherited from leg1))

  • leg2_frequency (Frequency, str, optional (inherited from leg1))

  • leg2_stub (StubInference, str, optional (inherited from leg1))

  • leg2_front_stub (datetime, optional (inherited from leg1))

  • leg2_back_stub (datetime, optional (inherited from leg1))

  • leg2_roll (RollDay, int, str, optional (inherited from leg1))

  • leg2_eom (bool, optional (inherited from leg1))

  • leg2_modifier (Adjuster, str, optional (inherited from leg1))

  • leg2_calendar (calendar, str, optional (inherited from leg1))

  • leg2_payment_lag (Adjuster, int, optional (inherited from leg1))

  • leg2_payment_lag_exchange (Adjuster, int, optional (inherited from leg1))

  • leg2_ex_div (Adjuster, int, optional (inherited from leg1))

  • leg2_convention (str, optional (inherited from leg1)) –

    Note

    The following define generalised settlement parameters.

  • currency (str, optional (set by ‘defaults’)) – The local settlement currency of the Instrument (3-digit code).

  • notional (float, Dual, Dual2, Variable, optional (set by ‘defaults’)) – The initial leg notional, defined in units of reference currency.

  • amortization (float, Dual, Dual2, Variable, str, Amortization, optional (set as zero)) – Set a non-constant notional per Period. If a scalar value, adjusts the notional of each successive period by that same value. Should have sign equal to that of notional if the notional is to reduce towards zero.

  • leg2_notional (float, Dual, Dual2, Variable, optional (negatively inherited from leg1))

  • leg2_amortization (float, Dual, Dual2, Variable, str, Amortization, optional (negatively inherited from leg1)) –

    Note

    The following are rate parameters.

  • fixed_rate (float or None) – The fixed rate applied to the FixedLeg. If None will be set to mid-market when curves are provided.

  • leg2_fixing_method (FloatFixingMethod, str, optional (set by ‘defaults’)) – The FloatFixingMethod describing the determination of the floating rate for each period.

  • leg2_method_param (int, optional (set by ‘defaults’)) – A specific parameter that is used by the specific fixing_method.

  • leg2_fixing_frequency (Frequency, str, optional (set by ‘frequency’ or ‘1B’)) – The Frequency as a component of the FloatRateIndex. If not given is assumed to match the frequency of the schedule for an IBOR type fixing_method or ‘1B’ if RFR type.

  • leg2_fixing_series (FloatRateSeries, str, optional (implied by other parameters)) – The FloatRateSeries as a component of the FloatRateIndex. If not given inherits attributes given such as the calendar, convention, method_param etc.

  • leg2_float_spread (float, Dual, Dual2, Variable, optional (set as 0.0)) – The amount (in bps) added to the rate in each period rate determination.

  • leg2_spread_compound_method (SpreadCompoundMethod, str, optional (set by ‘defaults’)) – The SpreadCompoundMethod used in the calculation of the period rate when combining a float_spread. Used only with RFR type fixing_method.

  • leg2_rate_fixings (float, Dual, Dual2, Variable, Series, str, optional) –

    See Fixings. The value of the rate fixing. If a scalar, is used directly. If a string identifier, links to the central fixings object and data loader.

    Note

    The following define non-deliverability parameters. If the swap is directly deliverable do not use these parameters. Review the notes section non-deliverability.

  • pair (FXIndex, str, optional) – The currency pair for FXFixing that determines Period settlement. The reference currency is implied from pair. Must include currency.

  • fx_fixings (float, Dual, Dual2, Variable, Series, str, 2-tuple or list, optional) – The value of the FXFixing for each Period according to non-deliverability.

  • leg2_fx_fixings (float, Dual, Dual2, Variable, Series, str, 2-tuple or list, optional) –

    The value of the FXFixing for each Period on Leg2 according to non-deliverability.

    Note

    The following are meta parameters.

  • curves (_BaseCurve, str, dict, _Curves, Sequence, optional) – Pricing objects passed directly to the Instrument’s methods’ curves argument. See Pricing.

  • spec (str, optional) – A collective group of parameters. See default argument specifications.

Notes

Non-Deliverable IRS (NDIRS)

An NDIRS can be constructed by using the pair argument. The currency defines the settlement currency, whilst the reference currency is derived from pair and the notional is expressed reference currency units.

The fx_fixings argument is typically used to provide an FX fixing series from which to extract non-deliverable FXFixing data. The leg2_fx_fixings inherits from the former and is likely to always be omitted, unless the fixings are provided as a list (against best practice) and the schedules do not align.

For pricing, whilst a traditional IRS can be priced with just one Curve, e.g. “sofr” for a conventional USD IRS, an ND-IRS will always require 2 different curves: a leg2 rate curve for forecasting rates in the non-deliverable reference currency, and a disc curve for discounting cashflows in the settlement currency.

The following is an example of a THB ND-IRS settled in USD with notional of 10mm THB.

In [3]: fixings.add("WMR_10AM_TYO_USDTHB", Series(index=[dt(2000, 6, 30), dt(2001, 1, 2)], data=[35.25, 37.0]))

In [4]: irs = IRS(
   ...:     effective=dt(2000, 1, 1),
   ...:     termination="2y",
   ...:     frequency="S",
   ...:     currency="usd",                              #  <- USD set as the settlement currency
   ...:     pair=FXIndex("usdthb", "fed", 1, "fed", -1), #  <- THB inferred as the reference currency
   ...:     fx_fixings="WMR_10AM_TYO",
   ...:     fixed_rate=2.0,
   ...: )
   ...: 

In [5]: irs.cashflows()
Out[5]: 
               Type  Ccy    Payment   Notional   Period Convention       DCF  Acc Start    Acc End    DF    Cashflow   NPV  FX Rate Base Ccy NPV Ccy Collateral  Rate  Spread  FX Fixing FX Fix Date Reference Ccy
leg1 0  FixedPeriod  USD 2000-07-03  1000000.0  Regular     Act360  0.505556 2000-01-01 2000-07-01  None -286.840032  None      1.0      USD    None       None   2.0     NaN      35.25  2000-06-30           THB
     1  FixedPeriod  USD 2001-01-03  1000000.0  Regular     Act360  0.511111 2000-07-01 2001-01-01  None -276.276276  None      1.0      USD    None       None   2.0     NaN      37.00  2001-01-02           THB
     2  FixedPeriod  USD 2001-07-03  1000000.0  Regular     Act360  0.502778 2001-01-01 2001-07-01  None         NaN  None      1.0      USD    None       None   2.0     NaN        NaN  2001-07-02           THB
     3  FixedPeriod  USD 2002-01-03  1000000.0  Regular     Act360  0.511111 2001-07-01 2002-01-01  None         NaN  None      1.0      USD    None       None   2.0     NaN        NaN  2002-01-02           THB
leg2 0  FloatPeriod  USD 2000-07-03 -1000000.0  Regular     Act360  0.505556 2000-01-01 2000-07-01  None         NaN  None      1.0      USD    None       None   NaN     0.0      35.25  2000-06-30           THB
     1  FloatPeriod  USD 2001-01-03 -1000000.0  Regular     Act360  0.511111 2000-07-01 2001-01-01  None         NaN  None      1.0      USD    None       None   NaN     0.0      37.00  2001-01-02           THB
     2  FloatPeriod  USD 2001-07-03 -1000000.0  Regular     Act360  0.502778 2001-01-01 2001-07-01  None         NaN  None      1.0      USD    None       None   NaN     0.0        NaN  2001-07-02           THB
     3  FloatPeriod  USD 2002-01-03 -1000000.0  Regular     Act360  0.511111 2001-07-01 2002-01-01  None         NaN  None      1.0      USD    None       None   NaN     0.0        NaN  2002-01-02           THB

Further information is available in the documentation for a FixedLeg.

Attributes Summary

fixed_rate

The fixed rate parameter of the composited FixedLeg.

kwargs

The _KWArgs container for the Instrument.

leg1

The FixedLeg of the Instrument.

leg2

The FloatLeg of the Instrument.

leg2_float_spread

The float spread parameter of the composited FloatLeg.

legs

A list of the Legs of the Instrument.

rate_scalar

A scaling quantity associated with the Solver risk calculations.

settlement_params

The default _SettlementParams of the Instrument.

Methods Summary

analytic_delta(*[, curves, solver, fx, vol, ...])

Calculate the analytic rate delta of a Leg of the Instrument.

cashflows(*[, curves, solver, fx, vol, ...])

Return aggregated cashflow data for the Instrument.

cashflows_table(*[, curves, solver, fx, ...])

Aggregate the values derived from a cashflows(), grouped by date, settlement currency and collateral.

delta(*[, curves, solver, fx, vol, base, ...])

Calculate delta risk of an Instrument against the calibrating instruments in a Solver.

exo_delta(*[, curves, solver, fx, vol, ...])

Calculate delta risk of an Instrument against some exogenous user created Variables, via a Solver.

gamma(*[, curves, solver, fx, vol, base, ...])

Calculate cross-gamma risk of an Instrument against the calibrating instruments of a Solver.

local_analytic_rate_fixings(*[, curves, ...])

Calculate the sensitivity to rate fixings of the Instrument, expressed in local settlement currency per basis point.

local_fixings(identifiers[, scalars, ...])

Calculate the sensitivity to fixings of the Instrument, expressed in local settlement currency.

npv(*[, curves, solver, fx, vol, base, ...])

Calculate the NPV of the Instrument converted to any other base accounting currency.

rate(*[, curves, solver, fx, vol, base, ...])

Calculate some pricing rate metric for the Instrument.

reset_fixings([state])

Resets any fixings values of the Instrument derived using the given data state.

spread(*[, curves, solver, fx, vol, base, ...])

Calculate some pricing spread metric for the Instrument.

Attributes Documentation

fixed_rate#

The fixed rate parameter of the composited FixedLeg.

kwargs#

The _KWArgs container for the Instrument.

leg1#

The FixedLeg of the Instrument.

leg2#

The FloatLeg of the Instrument.

leg2_float_spread#

The float spread parameter of the composited FloatLeg.

legs#

A list of the Legs of the Instrument.

rate_scalar#

A scaling quantity associated with the Solver risk calculations.

settlement_params#

The default _SettlementParams of the Instrument.

This is used to define a base currency when one is not specified.

Methods Documentation

analytic_delta(*, curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, vol=NoInput.blank, base=NoInput.blank, local=False, settlement=NoInput.blank, forward=NoInput.blank, leg=1)#

Calculate the analytic rate delta of a Leg of the Instrument.

Examples

In [6]: curve = Curve({dt(2000, 1, 1): 1.0, dt(2010, 1, 1): 0.75})

In [7]: irs = IRS(dt(2000, 1, 1), "3Y", spec="usd_irs", fixed_rate=1.0, curves=[curve])

In [8]: irs.analytic_delta()
Out[8]: 287.14750127899316

In [9]: irs.analytic_delta(local=True)
Out[9]: {'usd': 287.14750127899316}
Parameters:
  • curves (_Curves, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • solver (Solver, optional) – A Solver object containing Curve, Smile, Surface, or Cube mappings for pricing.

  • fx (FXForwards, optional) – The FXForwards object used for forecasting FX rates, if necessary.

  • vol (_Vol, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • base (str, optional (set to settlement currency)) – The currency to convert the local settlement NPV to.

  • local (bool, optional (set as False)) – An override flag to return a dict of NPV values indexed by string currency.

  • settlement (datetime, optional) – The assumed settlement date of the PV determination. Used only to evaluate ex-dividend status.

  • forward (datetime, optional) – The future date to project the PV to using the disc_curve.

  • leg (int, optional (set as 1)) – The Leg over which to calculate the analytic rate delta.

Return type:

float, Dual, Dual2, Variable or dict of such indexed by string currency.

cashflows(*, curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, vol=NoInput.blank, base=NoInput.blank, settlement=NoInput.blank, forward=NoInput.blank)#

Return aggregated cashflow data for the Instrument.

Warning

This method is a convenience method to provide a visual representation of all associated calculation data. Calling this method to extract certain values should be avoided. It is more efficient to source relevant parameters or calculations from object attributes or other methods directly.

Examples

In [1]: irs = IRS(dt(2000, 1, 1), "3Y", spec="usd_irs", fixed_rate=1.0)

In [2]: irs.cashflows()
Out[2]: 
               Type  Ccy    Payment   Notional   Period Convention       DCF  Acc Start    Acc End    DF      Cashflow   NPV  FX Rate Base Ccy NPV Ccy Collateral  Rate  Spread
leg1 0  FixedPeriod  USD 2001-01-04  1000000.0  Regular     Act360  1.013889 2000-01-03 2001-01-02  None -10138.888889  None      1.0      USD    None       None   1.0     NaN
     1  FixedPeriod  USD 2002-01-04  1000000.0  Regular     Act360  1.013889 2001-01-02 2002-01-02  None -10138.888889  None      1.0      USD    None       None   1.0     NaN
     2  FixedPeriod  USD 2003-01-06  1000000.0  Regular     Act360  1.013889 2002-01-02 2003-01-02  None -10138.888889  None      1.0      USD    None       None   1.0     NaN
leg2 0  FloatPeriod  USD 2001-01-04 -1000000.0  Regular     Act360  1.013889 2000-01-03 2001-01-02  None           NaN  None      1.0      USD    None       None   NaN     0.0
     1  FloatPeriod  USD 2002-01-04 -1000000.0  Regular     Act360  1.013889 2001-01-02 2002-01-02  None           NaN  None      1.0      USD    None       None   NaN     0.0
     2  FloatPeriod  USD 2003-01-06 -1000000.0  Regular     Act360  1.013889 2002-01-02 2003-01-02  None           NaN  None      1.0      USD    None       None   NaN     0.0

Providing relevant pricing objects will ensure all data that can be calculated is returned.

In [3]: curve = Curve({dt(2000, 1, 1): 1.0, dt(2010, 1, 1): 0.75})

In [4]: irs.cashflows(curves=[curve])
Out[4]: 
               Type  Ccy    Payment   Notional   Period Convention       DCF  Acc Start    Acc End        DF      Cashflow           NPV  FX Rate Base Ccy       NPV Ccy Collateral      Rate  Spread
leg1 0  FixedPeriod  USD 2001-01-04  1000000.0  Regular     Act360  1.013889 2000-01-03 2001-01-02  0.971359 -10138.888889  -9848.496702      1.0      USD  -9848.496702       None  1.000000     NaN
     1  FixedPeriod  USD 2002-01-04  1000000.0  Regular     Act360  1.013889 2001-01-02 2002-01-02  0.943835 -10138.888889  -9569.435745      1.0      USD  -9569.435745       None  1.000000     NaN
     2  FixedPeriod  USD 2003-01-06  1000000.0  Regular     Act360  1.013889 2002-01-02 2003-01-02  0.916946 -10138.888889  -9296.817681      1.0      USD  -9296.817681       None  1.000000     NaN
leg2 0  FloatPeriod  USD 2001-01-04 -1000000.0  Regular     Act360  1.013889 2000-01-03 2001-01-02  0.971359  29161.694029  28326.461668      1.0      USD  28326.461668       None  2.876222     0.0
     1  FloatPeriod  USD 2002-01-04 -1000000.0  Regular     Act360  1.013889 2001-01-02 2002-01-02  0.943835  29161.694029  27523.820438      1.0      USD  27523.820438       None  2.876222     0.0
     2  FloatPeriod  USD 2003-01-06 -1000000.0  Regular     Act360  1.013889 2002-01-02 2003-01-02  0.916946  29161.694029  26739.710399      1.0      USD  26739.710399       None  2.876222     0.0
Parameters:
  • curves (_Curves, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • solver (Solver, optional) – A Solver object containing Curve, Smile, Surface, or Cube mappings for pricing.

  • fx (FXForwards, optional) – The FXForwards object used for forecasting FX rates, if necessary.

  • vol (_Vol, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • base (str, optional (set to settlement currency)) – The currency to convert the local settlement NPV to.

  • settlement (datetime, optional) – The assumed settlement date of the PV determination. Used only to evaluate ex-dividend status.

  • forward (datetime, optional) – The future date to project the PV to using the disc_curve.

Return type:

DataFrame

cashflows_table(*, curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, vol=NoInput.blank, base=NoInput.blank, settlement=NoInput.blank, forward=NoInput.blank)#

Aggregate the values derived from a cashflows(), grouped by date, settlement currency and collateral.

Examples

In [5]: irs = IRS(dt(2000, 1, 1), "3Y", spec="usd_irs", fixed_rate=1.0)

In [6]: curve = Curve({dt(2000, 1, 1): 1.0, dt(2010, 1, 1): 0.75})

In [7]: irs.cashflows_table(curves=[curve])
Out[7]: 
local_ccy               USD
collateral_ccy          NaN
payment                    
2001-01-04      19022.80514
2002-01-04      19022.80514
2003-01-06      19022.80514
Parameters:
  • curves (_Curves, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • solver (Solver, optional) – A Solver object containing Curve, Smile, Surface, or Cube mappings for pricing.

  • fx (FXForwards, optional) – The FXForwards object used for forecasting FX rates, if necessary.

  • vol (_Vol, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • base (str, optional (set to settlement currency)) – The currency to convert the local settlement NPV to.

  • local (bool, optional (set as False)) – An override flag to return a dict of NPV values indexed by string currency.

  • settlement (datetime, optional) – The assumed settlement date of the PV determination. Used only to evaluate ex-dividend status.

  • forward (datetime, optional) – The future date to project the PV to using the disc_curve.

Return type:

DataFrame

delta(*, curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, vol=NoInput.blank, base=NoInput.blank, settlement=NoInput.blank, forward=NoInput.blank)#

Calculate delta risk of an Instrument against the calibrating instruments in a Solver.

Examples

In [8]: curve = Curve({dt(2000, 1, 1): 1.0, dt(2002, 1, 1): 0.85, dt(2010, 1, 1): 0.75})

In [9]: solver = Solver(
   ...:     curves=[curve],
   ...:     instruments=[
   ...:         IRS(dt(2000, 1, 1), "2Y", spec="usd_irs", curves=[curve]),
   ...:         IRS(dt(2000, 1, 1), "5Y", spec="usd_irs", curves=[curve]),
   ...:     ],
   ...:     s=[2.0, 2.25],
   ...:     instrument_labels=["2Y", "5Y"],
   ...:     id="US_RATES"
   ...: )
   ...: 
SUCCESS: `func_tol` reached after 6 iterations (levenberg_marquardt), `f_val`: 8.499591036903249e-16, `time`: 0.0032s

In [10]: irs = IRS(dt(2000, 1, 1), "3Y", spec="usd_irs", curves=[curve])

In [11]: irs.delta(solver=solver)
Out[11]: 
local_ccy                          usd
display_ccy                        usd
type        solver   label            
instruments US_RATES 2Y     129.580448
                     5Y     162.173287
Parameters:
  • curves (_Curves, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • solver (Solver, required) – A Solver object containing Curve, Smile, Surface, or Cube mappings for pricing.

  • fx (FXForwards, optional) – The FXForwards object used for forecasting FX rates, if necessary.

  • vol (_Vol, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • base (str, optional (set to settlement currency)) – The currency to convert the local settlement NPV to.

  • settlement (datetime, optional) – The assumed settlement date of the PV determination. Used only to evaluate ex-dividend status.

  • forward (datetime, optional) – The future date to project the PV to using the disc_curve.

Return type:

DataFrame

Notes

Delta measures the sensitivity of the PV to a change in any of the calibrating instruments of the given Solver. Values are returned according to the rate_scalar quantity at an Instrument level and according to the metric used to derive the rate() method of each Instrument.

exo_delta(*, curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, vol=NoInput.blank, base=NoInput.blank, settlement=NoInput.blank, forward=NoInput.blank, vars, vars_scalar=NoInput.blank, vars_labels=NoInput.blank)#

Calculate delta risk of an Instrument against some exogenous user created Variables, via a Solver.

See What are exogenous variables? in the cookbook.

Examples

This example calculates the risk of the fixed rate increasing by 1bp and the notional increasing by 1mm. Mathematically this should be equivalent to the npv and the analytic delta (although the calculation is based on AD and is completely independent of the solver).

In [12]: curve = Curve({dt(2000, 1, 1): 1.0, dt(2002, 1, 1): 0.85, dt(2010, 1, 1): 0.75})

In [13]: solver = Solver(
   ....:     curves=[curve],
   ....:     instruments=[
   ....:         IRS(dt(2000, 1, 1), "2Y", spec="usd_irs", curves=[curve]),
   ....:         IRS(dt(2000, 1, 1), "5Y", spec="usd_irs", curves=[curve]),
   ....:     ],
   ....:     s=[2.0, 2.25],
   ....:     instrument_labels=["2Y", "5Y"],
   ....:     id="US_RATES"
   ....: )
   ....: 
SUCCESS: `func_tol` reached after 6 iterations (levenberg_marquardt), `f_val`: 8.499591036903249e-16, `time`: 0.0031s

In [14]: irs = IRS(dt(2000, 1, 1), "3Y", spec="usd_irs", fixed_rate=Variable(3.0, ["R"]), notional=Variable(1e6, ["N"]), curves=[curve])

In [15]: irs.exo_delta(solver=solver, vars=["R", "N"], vars_scalar=[1e-2, 1e6])
Out[15]: 
local_ccy                          usd
display_ccy                        usd
type      solver   label              
exogenous US_RATES R       -291.752073
                   N     -25123.690181

In [16]: irs.analytic_delta()
Out[16]: <Dual: 291.752073, (N, ae9100, ae9101, ...), [0.0, 49.2, 239.9, ...]>

In [17]: irs.npv()
Out[17]: <Dual: -25123.690181, (N, R, ae9100, ...), [-0.0, -29175.2, 982218.9, ...]>
Parameters:
  • curves (_Curves, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • solver (Solver, required) – A Solver object containing Curve, Smile, Surface, or Cube mappings for pricing.

  • fx (FXForwards, optional) – The FXForwards object used for forecasting FX rates, if necessary.

  • vol (_Vol, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • base (str, optional (set to settlement currency)) – The currency to convert the local settlement NPV to.

  • settlement (datetime, optional) – The assumed settlement date of the PV determination. Used only to evaluate ex-dividend status.

  • forward (datetime, optional) – The future date to project the PV to using the disc_curve.

  • vars (list[str], required) – The variable tags which to determine sensitivities for.

  • vars_scalar (list[float], optional) – Scaling factors for each variable, for example converting rates to basis point etc. Defaults to ones.

  • vars_labels (list[str], optional) – Alternative names to relabel variables in DataFrames.

Return type:

DataFrame

gamma(*, curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, vol=NoInput.blank, base=NoInput.blank, settlement=NoInput.blank, forward=NoInput.blank)#

Calculate cross-gamma risk of an Instrument against the calibrating instruments of a Solver.

Examples

In [18]: curve = Curve({dt(2000, 1, 1): 1.0, dt(2002, 1, 1): 0.85, dt(2010, 1, 1): 0.75})

In [19]: solver = Solver(
   ....:     curves=[curve],
   ....:     instruments=[
   ....:         IRS(dt(2000, 1, 1), "2Y", spec="usd_irs", curves=[curve]),
   ....:         IRS(dt(2000, 1, 1), "5Y", spec="usd_irs", curves=[curve]),
   ....:     ],
   ....:     s=[2.0, 2.25],
   ....:     instrument_labels=["2Y", "5Y"],
   ....:     id="US_RATES"
   ....: )
   ....: 
SUCCESS: `func_tol` reached after 6 iterations (levenberg_marquardt), `f_val`: 8.499591036903249e-16, `time`: 0.0030s

In [20]: irs = IRS(dt(2000, 1, 1), "3Y", spec="usd_irs", curves=[curve])

In [21]: irs.gamma(solver=solver)
Out[21]: 
type                                             instruments          
solver                                              US_RATES          
label                                                     2Y        5Y
local_ccy display_ccy type        solver   label                      
usd       usd         instruments US_RATES 2Y      -0.029442 -0.038104
                                           5Y      -0.038104 -0.010190
Parameters:
  • curves (_Curves, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • solver (Solver, required) – A Solver object containing Curve, Smile, Surface, or Cube mappings for pricing.

  • fx (FXForwards, optional) – The FXForwards object used for forecasting FX rates, if necessary.

  • vol (_Vol, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • base (str, optional (set to settlement currency)) – The currency to convert the local settlement NPV to.

  • settlement (datetime, optional) – The assumed settlement date of the PV determination. Used only to evaluate ex-dividend status.

  • forward (datetime, optional) – The future date to project the PV to using the disc_curve.

Return type:

DataFrame

Notes

Gamma measures the second order cross-sensitivity of the PV to a change in any of the calibrating instruments of the given Solver. Values are returned according to the rate_scalar quantity at an Instrument level and according to the metric used to derive the rate() method of each Instrument.

local_analytic_rate_fixings(*, curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, vol=NoInput.blank, settlement=NoInput.blank, forward=NoInput.blank)#

Calculate the sensitivity to rate fixings of the Instrument, expressed in local settlement currency per basis point.

Examples

In [1]: curve1 = Curve({dt(2000, 1, 1): 1.0, dt(2010, 1, 1): 0.75}, id="Eur1mCurve")

In [2]: curve3 = Curve({dt(2000, 1, 1): 1.0, dt(2010, 1, 1): 0.70}, id="Eur3mCurve")

In [3]: irs = IRS(dt(2000, 1, 1), "20m", spec="eur_irs3", curves=[{"1m": curve1, "3m": curve3}, curve1])

In [4]: irs.local_analytic_rate_fixings()
Out[4]: 
identifier  Eur1mCurve Eur3mCurve
local_ccy          eur        eur
display_ccy        eur        eur
frequency           1M         3M
obs_dates                        
1999-12-30     8.81934   7.215824
2000-02-28         NaN  25.251470
2000-05-30         NaN  25.069179
2000-08-30         NaN  24.619619
2000-11-29         NaN  24.177105
2001-02-27         NaN  24.535960
2001-05-30         NaN  24.884455
Parameters:
  • curves (_Curves, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • solver (Solver, optional) – A Solver object containing Curve, Smile, Surface, or Cube mappings for pricing.

  • fx (FXForwards, optional) – The FXForwards object used for forecasting FX rates, if necessary.

  • vol (_Vol, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • settlement (datetime, optional) – The assumed settlement date of the PV determination. Used only to evaluate ex-dividend status.

  • forward (datetime, optional) – The future date to project the PV to using the disc_curve.

Return type:

DataFrame

Notes

This analytic method will index the sensitivities with series identifier according to the Curve id which has forecast the fixing.

local_fixings(identifiers, scalars=NoInput.blank, curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, vol=NoInput.blank, settlement=NoInput.blank, forward=NoInput.blank)#

Calculate the sensitivity to fixings of the Instrument, expressed in local settlement currency.

Parameters:
  • identifiers (Sequence of tuple[str, Series], required) – These are the series string identifiers and the data values that will be used in each Series to determine the sensitivity against.

  • scalars (Sequence of floats, optional (each set as 1.0)) – A sequence of scalars to multiply the sensitivities by for each on of the identifiers.

  • curves (_Curves, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • solver (Solver, optional) – A Solver object containing Curve, Smile, Surface, or Cube mappings for pricing.

  • fx (FXForwards, optional) – The FXForwards object used for forecasting FX rates, if necessary.

  • vol (_Vol, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • settlement (datetime, optional) – The assumed settlement date of the PV determination. Used only to evaluate ex-dividend status.

  • forward (datetime, optional) – The future date to project the PV to using the disc_curve.

Return type:

DataFrame

npv(*, curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, vol=NoInput.blank, base=NoInput.blank, local=False, settlement=NoInput.blank, forward=NoInput.blank)#

Calculate the NPV of the Instrument converted to any other base accounting currency.

Examples

In [1]: curve = Curve({dt(2000, 1, 1): 1.0, dt(2010, 1, 1): 0.75})

In [2]: irs = IRS(dt(2000, 1, 1), "3Y", spec="usd_irs", fixed_rate=1.0, curves=[curve])

In [3]: irs.npv()
Out[3]: 53875.24237805192

In [4]: irs.npv(local=True)
Out[4]: {'usd': 53875.24237805192}
Parameters:
  • curves (_Curves, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • solver (Solver, optional) – A Solver object containing Curve, Smile, Surface, or Cube mappings for pricing.

  • fx (FXForwards, optional) – The FXForwards object used for forecasting FX rates, if necessary.

  • vol (_Vol, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • base (str, optional (set to settlement currency)) – The currency to convert the local settlement NPV to.

  • local (bool, optional (set as False)) – An override flag to return a dict of NPV values indexed by string currency.

  • settlement (datetime, optional) – The assumed settlement date of the PV determination. Used only to evaluate ex-dividend status.

  • forward (datetime, optional) – The future date to project the PV to using the disc_curve.

Return type:

float, Dual, Dual2, Variable or dict of such indexed by string currency.

Notes

If base is not given then this function will return the value obtained from determining the PV in local settlement currency.

If base is provided this then an FXForwards object may be required to perform conversions. An FXRates object is also allowed for this conversion although best practice does not recommend it due to possible settlement date conflicts.

rate(*, curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, vol=NoInput.blank, base=NoInput.blank, settlement=NoInput.blank, forward=NoInput.blank, metric=NoInput.blank)#

Calculate some pricing rate metric for the Instrument.

Examples

The default metric for an IRS is its fixed ‘rate’.

In [1]: curve = Curve({dt(2000, 1, 1): 1.0, dt(2010, 1, 1): 0.75})

In [2]: irs = IRS(dt(2000, 1, 1), "3Y", spec="usd_irs", curves=[curve], fixed_rate=2.0)

In [3]: irs.rate()       # <- `fixed_rate` on fixed leg to equate value with float leg
Out[3]: 2.87622187684324
Parameters:
  • curves (_Curves, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • solver (Solver, optional) – A Solver object containing Curve, Smile, Surface, or Cube mappings for pricing.

  • fx (FXForwards, optional) – The FXForwards object used for forecasting FX rates, if necessary.

  • vol (_Vol, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • base (str, optional (set to settlement currency)) – The currency to convert the local settlement NPV to.

  • local (bool, optional (set as False)) – An override flag to return a dict of NPV values indexed by string currency.

  • settlement (datetime, optional) – The assumed settlement date of the PV determination. Used only to evaluate ex-dividend status.

  • forward (datetime, optional) – The future date to project the PV to using the disc_curve.

  • metric (str, optional) – The specific calculation to perform and the value to return. See Pricing on each Instrument for details of allowed inputs.

Return type:

float, Dual, Dual2, Variable

reset_fixings(state=NoInput.blank)#

Resets any fixings values of the Instrument derived using the given data state.

Parameters:

state (int, optional) – The state id of the data series that set the fixing. Only fixings determined by this data will be reset. If not given resets all fixings.

Return type:

None

spread(*, curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, vol=NoInput.blank, base=NoInput.blank, settlement=NoInput.blank, forward=NoInput.blank)#

Calculate some pricing spread metric for the Instrument.

This calculation may be an alias for rate() with a specific metric and is designated at an Instrument level.

Examples

The ‘spread’ on an IRS is the float leg spread to equate value with the fixed leg.

In [1]: curve = Curve({dt(2000, 1, 1): 1.0, dt(2010, 1, 1): 0.75})

In [2]: irs = IRS(dt(2000, 1, 1), "3Y", spec="usd_irs", curves=[curve], fixed_rate=2.0)

In [3]: irs.spread()       # <- `spread` on float leg to equate value with fixed leg
Out[3]: -87.62218768432399
Parameters:
  • curves (_Curves, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • solver (Solver, optional) – A Solver object containing Curve, Smile, Surface, or Cube mappings for pricing.

  • fx (FXForwards, optional) – The FXForwards object used for forecasting FX rates, if necessary.

  • vol (_Vol, optional) – Pricing objects. See Pricing on each Instrument for details of allowed inputs.

  • base (str, optional (set to settlement currency)) – The currency to convert the local settlement NPV to.

  • local (bool, optional (set as False)) – An override flag to return a dict of NPV values indexed by string currency.

  • settlement (datetime, optional) – The assumed settlement date of the PV determination. Used only to evaluate ex-dividend status.

  • forward (datetime, optional) – The future date to project the PV to using the disc_curve.

Return type:

float, Dual, Dual2, Variable