_BaseLeg#

class rateslib.legs._BaseLeg(*args, **kwargs)#

Bases: _WithFixings, _WithNPV, _WithCashflows, _WithAnalyticDelta, _WithAnalyticRateFixings

Abstract base class used in the construction of Legs.

Attributes Summary

periods

settlement_params

The _SettlementParams of the first Period of the Leg.

Methods Summary

analytic_delta(*[, rate_curve, index_curve, ...])

Calculate the analytic rate delta of a Period expressed in a base currency.

cashflows(*[, rate_curve, disc_curve, ...])

Return aggregated cashflow data for the Leg.

local_analytic_delta([rate_curve, ...])

Calculate the analytic rate delta of a Period expressed in its local settlement currency.

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

Return a DataFrame of financial sensitivity to published interest rate fixings, expressed in local settlement currency of the Period.

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

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

local_npv(*[, rate_curve, index_curve, ...])

Calculate the NPV of the Leg expressed in local settlement currency.

npv(*[, rate_curve, index_curve, ...])

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

reset_fixings([state])

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

spread(*, target_npv[, rate_curve, ...])

Calculate a spread metric which when applied to the Leg allows it to attain the target value.

Attributes Documentation

periods#
settlement_params#

The _SettlementParams of the first Period of the Leg.

Methods Documentation

analytic_delta(*, rate_curve=NoInput.blank, index_curve=NoInput.blank, disc_curve=NoInput.blank, fx=NoInput.blank, fx_vol=NoInput.blank, base=NoInput.blank, local=False, settlement=NoInput.blank, forward=NoInput.blank)#

Calculate the analytic rate delta of a Period expressed in a base currency.

Parameters:
  • rate_curve (_BaseCurve or dict of such indexed by string tenor, optional) – Used to forecast floating period rates, if necessary.

  • index_curve (_BaseCurve, optional) – Used to forecast index values for indexation, if necessary.

  • disc_curve (_BaseCurve, optional) – Used to discount cashflows.

  • fx (FXForwards, optional) – The FXForwards object used for forecasting the fx_fixing for deliverable cashflows, if necessary. Or, an FXRates object purely for immediate currency conversion.

  • fx_vol (FXDeltaVolSmile, FXSabrSmile, FXDeltaVolSurface, FXSabrSurface, optional) – The FX volatility Smile or Surface object used for determining Black calendar day implied volatility values.

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

  • local (bool, optional) – 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

cashflows(*, rate_curve=NoInput.blank, disc_curve=NoInput.blank, index_curve=NoInput.blank, fx=NoInput.blank, fx_vol=NoInput.blank, base=NoInput.blank, settlement=NoInput.blank, forward=NoInput.blank)#

Return aggregated cashflow data for the Leg.

Warning

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

Parameters:
  • rate_curve (_BaseCurve or dict of such indexed by string tenor, optional) – Used to forecast floating period rates, if necessary.

  • index_curve (_BaseCurve, optional) – Used to forecast index values for indexation, if necessary.

  • disc_curve (_BaseCurve, optional) – Used to discount cashflows.

  • fx (FXForwards, optional) – The FXForwards object used for forecasting the fx_fixing for deliverable cashflows, if necessary. Or, an FXRates object purely for immediate currency conversion.

  • fx_vol (FXDeltaVolSmile, FXSabrSmile, FXDeltaVolSurface, FXSabrSurface, optional) – The FX volatility Smile or Surface object used for determining Black calendar day implied volatility values.

  • base (str, optional) – The currency to convert relevant values into.

  • 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

local_analytic_delta(rate_curve=NoInput.blank, index_curve=NoInput.blank, disc_curve=NoInput.blank, fx=NoInput.blank, fx_vol=NoInput.blank, settlement=NoInput.blank, forward=NoInput.blank)#

Calculate the analytic rate delta of a Period expressed in its local settlement currency.

Parameters:
  • rate_curve (_BaseCurve or dict of such indexed by string tenor, optional) – Used to forecast floating period rates, if necessary.

  • index_curve (_BaseCurve, optional) – Used to forecast index values for indexation, if necessary.

  • disc_curve (_BaseCurve, optional) – Used to discount cashflows.

  • fx (FXForwards, optional) – The FXForwards object used for forecasting the fx_fixing for deliverable cashflows, if necessary. Or, an FXRates object purely for immediate currency conversion.

  • fx_vol (FXDeltaVolSmile, FXSabrSmile, FXDeltaVolSurface, FXSabrSurface, optional) – The FX volatility Smile or Surface object used for determining Black calendar day implied volatility values.

  • 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

local_analytic_rate_fixings(*, rate_curve=NoInput.blank, index_curve=NoInput.blank, disc_curve=NoInput.blank, fx=NoInput.blank, fx_vol=NoInput.blank, settlement=NoInput.blank, forward=NoInput.blank)#

Return a DataFrame of financial sensitivity to published interest rate fixings, expressed in local settlement currency of the Period.

If the Period has no sensitivity to rates fixings this DataFrame is empty.

Parameters:
  • rate_curve (_BaseCurve or dict of such indexed by string tenor, optional) – Used to forecast floating period rates, if necessary.

  • index_curve (_BaseCurve, optional) – Used to forecast index values for indexation, if necessary.

  • disc_curve (_BaseCurve, optional) – Used to discount cashflows.

  • fx (FXForwards, optional) – The FXForwards object used for forecasting the fx_fixing for deliverable cashflows, if necessary. Or, an FXRates object purely for immediate currency conversion.

  • fx_vol (FXDeltaVolSmile, FXSabrSmile, FXDeltaVolSurface, FXSabrSurface, optional) – The FX volatility Smile or Surface object used for determining Black calendar day implied volatility values.

  • 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

local_fixings(identifiers, scalars=NoInput.blank, rate_curve=NoInput.blank, index_curve=NoInput.blank, disc_curve=NoInput.blank, fx=NoInput.blank, fx_vol=NoInput.blank, settlement=NoInput.blank, forward=NoInput.blank)#

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

Parameters:
  • indentifiers (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.

  • rate_curve (_BaseCurve or dict of such indexed by string tenor, optional) – Used to forecast floating period rates, if necessary.

  • index_curve (_BaseCurve, optional) – Used to forecast index values for indexation, if necessary.

  • disc_curve (_BaseCurve, optional) – Used to discount cashflows.

  • fx (FXForwards, optional) – The FXForwards object used for forecasting the fx_fixing for deliverable cashflows, if necessary. Or, an class:~rateslib.fx.FXRates object purely for immediate currency conversion.

  • fx_vol (FXDeltaVolSmile, FXSabrSmile, FXDeltaVolSurface, FXSabrSurface, optional) – The FX volatility Smile or Surface object used for determining Black calendar day implied volatility values.

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

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

Return type:

DataFrame

local_npv(*, rate_curve=NoInput.blank, index_curve=NoInput.blank, disc_curve=NoInput.blank, fx=NoInput.blank, fx_vol=NoInput.blank, settlement=NoInput.blank, forward=NoInput.blank)#

Calculate the NPV of the Leg expressed in local settlement currency.

Parameters:
  • rate_curve (_BaseCurve or dict of such indexed by string tenor, optional) – Used to forecast floating period rates, if necessary.

  • index_curve (_BaseCurve, optional) – Used to forecast index values for indexation, if necessary.

  • disc_curve (_BaseCurve, optional) – Used to discount cashflows.

  • fx (FXForwards, optional) – The FXForwards object used for forecasting the fx_fixing for deliverable cashflows, if necessary. Or, an FXRates object purely for immediate currency conversion.

  • fx_vol (FXDeltaVolSmile, FXSabrSmile, FXDeltaVolSurface, FXSabrSurface, optional) – The FX volatility Smile or Surface object used for determining Black calendar day implied volatility values.

  • 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

npv(*, rate_curve=NoInput.blank, index_curve=NoInput.blank, disc_curve=NoInput.blank, fx=NoInput.blank, fx_vol=NoInput.blank, base=NoInput.blank, local=False, settlement=NoInput.blank, forward=NoInput.blank)#

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

Hint

If the cashflows are unspecified or incalculable due to missing information this method will raise an exception. For a function that returns a Result indicating success or failure use try_local_npv().

Parameters:
  • rate_curve (_BaseCurve or dict of such indexed by string tenor, optional) – Used to forecast floating period rates, if necessary.

  • index_curve (_BaseCurve, optional) – Used to forecast index values for indexation, if necessary.

  • disc_curve (_BaseCurve, optional) – Used to discount cashflows.

  • fx (FXForwards, optional) – The FXForwards object used for forecasting the fx_fixing for deliverable cashflows, if necessary. Or, an FXRates object purely for immediate currency conversion.

  • fx_vol (FXDeltaVolSmile, FXSabrSmile, FXDeltaVolSurface, FXSabrSurface, optional) – The FX volatility Smile or Surface object used for determining Black calendar day implied volatility values.

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

  • local (bool, optional) – 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 provided then this function will return the value obtained from try_local_npv().

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.

reset_fixings(state=NoInput.blank)#

Resets any fixings values of the Leg 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(*, target_npv, rate_curve=NoInput.blank, index_curve=NoInput.blank, disc_curve=NoInput.blank, fx=NoInput.blank, fx_vol=NoInput.blank, settlement=NoInput.blank, forward=NoInput.blank)#

Calculate a spread metric which when applied to the Leg allows it to attain the target value.

Parameters:
  • target_npv (DualTypes, required) – The target value of the Leg measured using all of the other given arguments. Must be expressed in local settlement currency units.

  • rate_curve (_BaseCurve or dict of such indexed by string tenor, optional) – Used to forecast floating period rates, if necessary.

  • index_curve (_BaseCurve, optional) – Used to forecast index values for indexation, if necessary.

  • disc_curve (_BaseCurve, optional) – Used to discount cashflows.

  • fx (FXForwards, optional) – The FXForwards object used for forecasting the fx_fixing for deliverable cashflows, if necessary. Or, an FXRates object purely for immediate currency conversion.

  • fx_vol (FXDeltaVolSmile, FXSabrSmile, FXDeltaVolSurface, FXSabrSurface, optional) – The FX volatility Smile or Surface object used for determining Black calendar day implied volatility values.

  • 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