IndexFixedRateBond#

class rateslib.instruments.IndexFixedRateBond(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, notional=NoInput.blank, currency=NoInput.blank, amortization=NoInput.blank, convention=NoInput.blank, fixed_rate=NoInput.blank, index_base=NoInput.blank, index_fixings=NoInput.blank, index_method=NoInput.blank, index_lag=NoInput.blank, ex_div=NoInput.blank, settle=NoInput.blank, calc_mode=NoInput.blank, curves=NoInput.blank, spec=NoInput.blank)#

Bases: FixedRateBond

Create an indexed fixed rate bond security.

Parameters:
  • args (tuple) – Required positional args for FixedRateBond.

  • index_base (float or None, optional) – The base index applied to all periods.

  • index_fixings (float, or Series, optional) – If a float scalar, will be applied as the index fixing for the first period. If a list of n fixings will be used as the index fixings for the first n periods. If a datetime indexed Series will use the fixings that are available in that object, and derive the rest from the curve.

  • index_method (str) – Whether the indexing uses a daily measure for settlement or the most recently monthly data taken from the first day of month.

  • index_lag (int, optional) – The number of months by which the index value is lagged. Used to ensure consistency between curves and forecast values. Defined by default.

  • kwargs (dict) – Required keyword args for FixedRateBond.

Examples

See FixedRateBond for similar.

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

accrued(settlement)

Calculate the accrued amount per nominal par value of 100.

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

Return the analytic delta of the security via summing all periods.

cashflows([curves, solver, fx, base, settlement])

Return the properties of the security used in calculating cashflows.

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

convexity(ytm, settlement)

Return the second derivative of price w.r.t.

delta(*args, **kwargs)

Calculate the delta of the Instrument.

duration(ytm, settlement[, metric])

Return the (negated) derivative of price w.r.t.

ex_div(settlement)

Return a boolean whether the security is ex-div at the given settlement.

fwd_from_repo(price, settlement, ...[, ...])

Return a forward price implied by a given repo rate.

gamma(*args, **kwargs)

Calculate the gamma of the Instrument.

index_ratio(settlement, curve)

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

Return the NPV of the security by summing cashflow valuations.

oaspread([curves, solver, fx, base, price, ...])

The option adjusted spread added to the discounting Curve to value the security at price.

price(ytm, settlement[, dirty])

Calculate the price of the security per nominal value of 100, given yield-to-maturity.

rate([curves, solver, fx, base, metric, ...])

Return various pricing metrics of the security calculated from Curve s.

repo_from_fwd(price, settlement, ...[, ...])

Return an implied repo rate from a forward price.

ytm(price, settlement[, dirty])

Calculate the yield-to-maturity of the security given its price.

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

accrued(settlement)#

Calculate the accrued amount per nominal par value of 100.

Parameters:

settlement (datetime) – The settlement date which to measure accrued interest against.

Notes

Fractionally apportions the coupon payment based on calendar days.

\[\text{Accrued} = \text{Coupon} \times \frac{\text{Settle - Last Coupon}}{\text{Next Coupon - Last Coupon}}\]
analytic_delta(curve=NoInput.blank, disc_curve=NoInput.blank, fx=NoInput.blank, base=NoInput.blank)#

Return the analytic delta of the security via summing all periods.

For arguments see analytic_delta().

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

Return the properties of the security used in calculating cashflows.

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

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

    • Forecasting Curve for leg1.

    • Discounting Curve for leg1.

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

  • settlement (datetime, optional) – The settlement date of the security. If None adds the regular settle time to the initial node date of the given discount curves.

Return type:

DataFrame

cashflows_table(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank)#
convexity(ytm, settlement)#

Return the second derivative of price w.r.t. ytm.

Parameters:
  • ytm (float) – The yield-to-maturity for the bond.

  • settlement (datetime) – The settlement date of the bond.

Return type:

float

Examples

In [9]: gilt = FixedRateBond(
   ...:     effective=dt(1998, 12, 7),
   ...:     termination=dt(2015, 12, 7),
   ...:     frequency="S",
   ...:     calendar="ldn",
   ...:     currency="gbp",
   ...:     convention="ActActICMA",
   ...:     ex_div=7,
   ...:     fixed_rate=8.0
   ...: )
   ...: 

In [10]: gilt.convexity(4.445, dt(1999, 5, 27))
Out[10]: 2.03673015861093

This number is interpreted as hundredths of a cent. For a 1bp increase in yield the duration will decrease by 2 hundredths of a cent.

In [11]: gilt.duration(4.445, dt(1999, 5, 27))
Out[11]: 14.65975398077815

In [12]: gilt.duration(4.455, dt(1999, 5, 27))
Out[12]: 14.63940251353963
delta(*args, **kwargs)#

Calculate the delta of the Instrument.

For arguments see Sensitivities.delta().

duration(ytm, settlement, metric='risk')#

Return the (negated) derivative of price w.r.t. ytm.

Parameters:
  • ytm (float) – The yield-to-maturity for the bond.

  • settlement (datetime) – The settlement date of the bond.

  • metric (str) – The specific duration calculation to return. See notes.

Return type:

float

Notes

The available metrics are:

  • “risk”: the derivative of price w.r.t. ytm, scaled to -1bp.

    \[risk = - \frac{\partial P }{\partial y}\]
  • “modified”: the modified duration which is risk divided by price.

    \[mduration = \frac{risk}{P} = - \frac{1}{P} \frac{\partial P }{\partial y}\]
  • “duration”: the duration which is modified duration reverse modified.

    \[duration = mduration \times (1 + y / f)\]

Examples

In [13]: gilt = FixedRateBond(
   ....:     effective=dt(1998, 12, 7),
   ....:     termination=dt(2015, 12, 7),
   ....:     frequency="S",
   ....:     calendar="ldn",
   ....:     currency="gbp",
   ....:     convention="ActActICMA",
   ....:     ex_div=7,
   ....:     fixed_rate=8.0
   ....: )
   ....: 

In [14]: gilt.duration(4.445, dt(1999, 5, 27), "risk")
Out[14]: 14.65975398077815

In [15]: gilt.duration(4.445, dt(1999, 5, 27), "modified")
Out[15]: 10.39181988471933

In [16]: gilt.duration(4.445, dt(1999, 5, 27), "duration")
Out[16]: 10.622778081657216

This result is interpreted as cents. If the yield is increased by 1bp the price will fall by 14.65 cents.

In [17]: gilt.price(4.445, dt(1999, 5, 27))
Out[17]: 141.31188978180361

In [18]: gilt.price(4.455, dt(1999, 5, 27))
Out[18]: 141.16539402571507
ex_div(settlement)#

Return a boolean whether the security is ex-div at the given settlement.

Parameters:

settlement (datetime) – The settlement date to test.

Return type:

bool

Notes

By default uses the UK DMO convention of returning False if settlement is on or before the ex-div date.

Some calc_mode options return True if settlement is on the ex-div date.

Ex-div dates are determined as measured by the number of ex_div business days prior to the unadjusted coupon end date.

With an ex_div of 1, a settlement that occurs on the coupon payment date will be classified as ex-dividend and not receive that coupon.

With an ex_div of 0, a settlement that occurs on the coupon payment date will not be classified as ex-dividend and will receive that coupon (in the default calculation mode).

fwd_from_repo(price, settlement, forward_settlement, repo_rate, convention=NoInput.blank, dirty=False, method='proceeds')#

Return a forward price implied by a given repo rate.

Parameters:
  • price (float, Dual, or Dual2) – The initial price of the security at settlement.

  • settlement (datetime) – The settlement date of the bond

  • forward_settlement (datetime) – The forward date for which to calculate the forward price.

  • repo_rate (float, Dual or Dual2) – The rate which is used to calculate values.

  • convention (str, optional) – The day count convention applied to the rate. If not given uses default values.

  • dirty (bool, optional) – Whether the input and output price are specified including accrued interest.

  • method (str in {"proceeds", "compounded"}, optional) – The method for determining the forward price.

Return type:

float, Dual or Dual2

Notes

Any intermediate (non ex-dividend) cashflows between settlement and forward_settlement will also be assumed to accrue at repo_rate.

gamma(*args, **kwargs)#

Calculate the gamma of the Instrument.

For arguments see Sensitivities.gamma().

index_ratio(settlement, curve)#
npv(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank, local=False)#

Return the NPV of the security by summing cashflow valuations.

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

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

    • Forecasting Curve for leg1.

    • Discounting Curve for leg1.

  • 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), 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

Notes

The settlement date of the bond is inferred from the objects settle days parameter and the initial date of the supplied curves. The NPV returned is for immediate settlement.

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.

oaspread(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank, price=NoInput.blank, dirty=False)#

The option adjusted spread added to the discounting Curve to value the security at price.

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

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

    • Forecasting Curve for leg1.

    • Discounting Curve for leg1.

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

  • price (float, Dual, Dual2) – The price of the bond to match.

  • dirty (bool) – Whether the price is given clean or dirty.

Return type:

float, Dual, Dual2

price(ytm, settlement, dirty=False)#

Calculate the price of the security per nominal value of 100, given yield-to-maturity.

Parameters:
  • ytm (float) – The yield-to-maturity against which to determine the price.

  • settlement (datetime) – The settlement date on which to determine the price.

  • dirty (bool, optional) – If True will include the rateslib.instruments.FixedRateBond.accrued() in the price.

Return type:

float, Dual, Dual2

Examples

This example is taken from the UK debt management office website. The result should be 141.070132 and the bond is ex-div.

In [19]: gilt = FixedRateBond(
   ....:     effective=dt(1998, 12, 7),
   ....:     termination=dt(2015, 12, 7),
   ....:     frequency="S",
   ....:     calendar="ldn",
   ....:     currency="gbp",
   ....:     convention="ActActICMA",
   ....:     ex_div=7,
   ....:     fixed_rate=8.0
   ....: )
   ....: 

In [20]: gilt.ex_div(dt(1999, 5, 27))
Out[20]: True

In [21]: gilt.price(
   ....:     ytm=4.445,
   ....:     settlement=dt(1999, 5, 27),
   ....:     dirty=True
   ....: )
   ....: 
Out[21]: 141.07013154004537

This example is taken from the Swedish national debt office website. The result of accrued should, apparently, be 0.210417 and the clean price should be 99.334778.

In [22]: bond = FixedRateBond(
   ....:     effective=dt(2017, 5, 12),
   ....:     termination=dt(2028, 5, 12),
   ....:     frequency="A",
   ....:     calendar="stk",
   ....:     currency="sek",
   ....:     convention="ActActICMA",
   ....:     ex_div=5,
   ....:     fixed_rate=0.75
   ....: )
   ....: 

In [23]: bond.ex_div(dt(2017, 8, 23))
Out[23]: False

In [24]: bond.accrued(dt(2017, 8, 23))
Out[24]: 0.21164383561643835

In [25]: bond.price(
   ....:     ytm=0.815,
   ....:     settlement=dt(2017, 8, 23),
   ....:     dirty=False
   ....: )
   ....: 
Out[25]: 99.3348737576038
rate(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank, metric='clean_price', forward_settlement=NoInput.blank)#

Return various pricing metrics of the security calculated from Curve s.

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

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

    • Forecasting Curve for leg1.

    • Discounting Curve for leg1.

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

  • metric (str, optional) – Metric returned by the method. Available options are {“clean_price”, “dirty_price”, “ytm”, “index_clean_price”, “index_dirty_price”}

  • forward_settlement (datetime, optional) – The forward settlement date. If not given uses the discount Curve and the settle attribute of the bond.

Return type:

float, Dual, Dual2

repo_from_fwd(price, settlement, forward_settlement, forward_price, convention=NoInput.blank, dirty=False)#

Return an implied repo rate from a forward price.

Parameters:
  • price (float, Dual, or Dual2) – The initial price of the security at settlement.

  • settlement (datetime) – The settlement date of the bond

  • forward_settlement (datetime) – The forward date for which to calculate the forward price.

  • forward_price (float, Dual or Dual2) – The forward price which iplies the repo rate

  • convention (str, optional) – The day count convention applied to the rate. If not given uses default values.

  • dirty (bool, optional) – Whether the input and output price are specified including accrued interest.

Return type:

float, Dual or Dual2

Notes

Any intermediate (non ex-dividend) cashflows between settlement and forward_settlement will also be assumed to accrue at repo_rate.

ytm(price, settlement, dirty=False)#

Calculate the yield-to-maturity of the security given its price.

Parameters:
  • price (float) – The price, per 100 nominal, against which to determine the yield.

  • settlement (datetime) – The settlement date on which to determine the price.

  • dirty (bool, optional) – If True will assume the accrued() is included in the price.

Return type:

float, Dual, Dual2

Notes

If price is given as Dual or Dual2 input the result of the yield will be output as the same type with the variables passed through accordingly.

Examples

In [26]: gilt = FixedRateBond(
   ....:     effective=dt(1998, 12, 7),
   ....:     termination=dt(2015, 12, 7),
   ....:     frequency="S",
   ....:     calendar="ldn",
   ....:     currency="gbp",
   ....:     convention="ActActICMA",
   ....:     ex_div=7,
   ....:     fixed_rate=8.0
   ....: )
   ....: 

In [27]: gilt.ytm(
   ....:     price=141.0701315,
   ....:     settlement=dt(1999,5,27),
   ....:     dirty=True
   ....: )
   ....: 
Out[27]: 4.445000002731656

In [28]: gilt.ytm(Dual(141.0701315, ["price", "a", "b"], [1, -0.5, 2]), dt(1999, 5, 27), True)
Out[28]: <Dual: 4.445000, (price, a, b), [-0.1, 0.0, -0.1]>

In [29]: gilt.ytm(Dual2(141.0701315, ["price", "a", "b"], [1, -0.5, 2], []), dt(1999, 5, 27), True)
Out[29]: <Dual2: 4.445000, (price, a, b), [-0.1, 0.0, -0.1], [[...]]>