BasePeriod#

class rateslib.periods.BasePeriod(start, end, payment, frequency, notional=NoInput.blank, currency=NoInput.blank, convention=NoInput.blank, termination=NoInput.blank, stub=False, roll=NoInput.blank, calendar=NoInput.blank)#

Bases: object

Abstract base class with common parameters for all Period subclasses.

See also: User guide for Periods.

Parameters:
  • start (Datetime) – The adjusted start date of the calculation period.

  • end (Datetime) – The adjusted end date of the calculation period.

  • payment (Datetime) – The adjusted payment date of the period.

  • frequency (str) – The frequency of the corresponding leg. Also used with specific values for convention, or floating rate calculation.

  • notional (float, optional, set by Default) – The notional amount of the period (positive implies paying a cashflow).

  • currency (str, optional) – The currency of the cashflow (3-digit code), set by default.

  • convention (str, optional, set by Default) – The day count convention of the calculation period accrual. See dcf().

  • termination (Datetime, optional) – The termination date of the corresponding leg. Required only with specific values for convention.

  • stub (bool, optional) – Records whether the period is a stub or regular. Used by certain day count convention calculations.

  • roll (int, str, optional) – Used only by stub periods and for specific values of convention.

  • calendar (CustomBusinessDay, str, optional) – Used only by stub periods and for specific values of convention.

Attributes Summary

dcf

Calculated with appropriate convention over the period.

Methods Summary

analytic_delta([curve, disc_curve, fx, base])

Return the analytic delta of the period object.

cashflows([curve, disc_curve, fx, base])

Return the properties of the period used in calculating cashflows.

npv([curve, disc_curve, fx, base, local])

Return the NPV of the period object.

Attributes Documentation

dcf#

Calculated with appropriate convention over the period.

Type:

float

Methods Documentation

abstract analytic_delta(curve=NoInput.blank, disc_curve=NoInput.blank, fx=NoInput.blank, base=NoInput.blank)#

Return the analytic delta of the period object.

Parameters:
  • curve (Curve) – The forecasting curve object. Not used unless it is set equal to disc_curve, or if a rate in a FloatPeriod is required.

  • disc_curve (Curve, optional) – The discounting curve object used in calculations. Set equal to curve if not given.

  • 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), set by default. Only used if fx is an FXRates or FXForwards object.

Return type:

float, Dual, Dual2

Examples

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

In [2]: fxr = FXRates({"gbpusd": 1.25}, base="usd")
In [3]: period = FixedPeriod(
   ...:     start=dt(2022, 1, 1),
   ...:     end=dt(2022, 7, 1),
   ...:     payment=dt(2022, 7, 1),
   ...:     frequency="S",
   ...:     currency="gbp",
   ...:     fixed_rate=4.00,
   ...: )
   ...: 

In [4]: period.analytic_delta(curve, curve)
Out[4]: 46.8958283304191

In [5]: period.analytic_delta(curve, curve, fxr)
Out[5]: <Dual: 58.619785, (fx_gbpusd), [46.9]>

In [6]: period.analytic_delta(curve, curve, fxr, "gbp")
Out[6]: 46.8958283304191
abstract cashflows(curve=NoInput.blank, disc_curve=NoInput.blank, fx=NoInput.blank, base=NoInput.blank)#

Return the properties of the period used in calculating cashflows.

Parameters:
  • curve (Curve, optional) – The forecasting curve object. Not used unless it is set equal to disc_curve, or if a rate in a FloatPeriod is required.

  • disc_curve (Curve, optional) – The discounting curve object used in calculations. Set equal to curve if not given.

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

dict

Examples

In [1]: period.cashflows(curve, curve, fxr)
Out[1]: 
{'Type': 'FixedPeriod',
 'Period': 'Regular',
 'Ccy': 'GBP',
 'Acc Start': datetime.datetime(2022, 1, 1, 0, 0),
 'Acc End': datetime.datetime(2022, 7, 1, 0, 0),
 'Payment': datetime.datetime(2022, 7, 1, 0, 0),
 'Convention': 'ACT360',
 'DCF': 0.5027777777777778,
 'Notional': 1000000.0,
 'DF': 0.9327347071243579,
 'Collateral': None,
 'Rate': 4.0,
 'Spread': None,
 'Cashflow': -20111.11111111111,
 'NPV': -18758.33133216764,
 'FX Rate': 1.25,
 'NPV Ccy': -23447.91416520955}
abstract npv(curve=NoInput.blank, disc_curve=NoInput.blank, fx=NoInput.blank, base=NoInput.blank, local=False)#

Return the NPV of the period object.

Calculates the cashflow for the period and multiplies it by the DF associated with the payment date.

Parameters:
  • curve (Curve, optional) – The forecasting curve object. Not used unless it is set equal to disc_curve, or if a rate in a FloatPeriod is required.

  • disc_curve (Curve, optional) – The discounting curve object used in calculations. Set equal to curve if not given.

  • 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), set by default. Only used if fx is an FXRates or FXForwards object.

  • local (bool, optional) – If True will ignore the base request and return a dict identifying local currency NPV.

Return type:

float, Dual, Dual2, or dict of such

Examples

In [1]: period.npv(curve, curve)
Out[1]: -18758.33133216764

In [2]: period.npv(curve, curve, fxr)
Out[2]: <Dual: -23447.914165, (fx_gbpusd), [-18758.3]>

In [3]: period.npv(curve, curve, fxr, "gbp")
Out[3]: -18758.33133216764

In [4]: period.npv(curve, curve, fxr, local=True)
Out[4]: {'gbp': -18758.33133216764}