API Reference#

Indices and tables#

Notation#

\[\begin{split}d \quad \text{or} \quad d_i =& \text{DCF of period} \; (i) \\ m \quad \text{or} \quad m_i =& \text{Maturity date of period} \; (i) \\ v(m) =& \text{DF of period payment date,} \; m \\ N \quad \text{or} \quad N_i =& \text{Notional of period} \; (i) \\ R =& \text{Fixed rate of period or leg} \\ z =& \text{Floating period spread} \\ r(r_i, z) =& \text{Floating rate of period as a function of fixings,} \; (r_i) \\ C =& \text{Cashflow} \\ P =& \text{Net present value} \\ I(m) =& \text{Index ratio applicable at maturity,} \; m \\\end{split}\]

Defaults#

Classes#

Defaults()

The defaults object used by initialising objects.

Fixings()

Class to lazy load fixing data from CSV files.

NoInput(value[, names, module, qualname, ...])

Enumerable type to handle setting default values.

Calendars#

Classes#

Cal(holidays, week_mask)

A business day calendar with a singular list of holidays.

NamedCal(name)

A wrapper for a UnionCal struct specified by a string representation.

UnionCal(calendars[, settlement_calendars])

A business day calendar which is the potential union of multiple calendars, with the additional constraint of also ensuring settlement compliance with one or more other calendars.

Modifier(ad)

Enumerable type for modification rules.

RollDay

Enumerable type for roll day types.

Functions#

add_tenor(start, tenor, modifier[, ...])

Add a tenor to a given date under specific modification rules and holiday calendar.

create_calendar(rules[, week_mask])

Create a calendar with specific business and holiday days defined.

dcf(start, end, convention[, termination, ...])

Calculate the day count fraction of a period.

get_calendar(calendar[, kind, named])

Returns a calendar object either from an available set or a user defined input.

get_imm([month, year, code])

Return an IMM date for a specified month.

Classes#

Cal(holidays, week_mask)

A business day calendar with a singular list of holidays.

Modifier(ad)

Enumerable type for modification rules.

NamedCal(name)

A wrapper for a UnionCal struct specified by a string representation.

RollDay

Enumerable type for roll day types.

UnionCal(calendars[, settlement_calendars])

A business day calendar which is the potential union of multiple calendars, with the additional constraint of also ensuring settlement compliance with one or more other calendars.

Class Inheritance Diagram#

Inheritance diagram of rateslib.rs.Cal, rateslib.rs.Modifier, rateslib.rs.NamedCal, rateslib.rs.RollDay, rateslib.rs.UnionCal

Scheduling#

Classes#

Schedule(effective, termination, frequency)

Generate a schedule of dates according to a regular pattern and calendar inference.

Highlighted private functions#

_check_regular_swap(effective, termination, ...)

Tests whether the given the parameters define a regular leg schedule without stubs.

_infer_stub_date(effective, termination, ...)

Attempts to infer either a front or back stub in an unspecified schedule.

Piecewise Polynomial Splines#

Functions#

bsplev_single(x, i, k, t[, org_k])

Calculate the value of an indexed b-spline at x.

bspldnev_single(x, i, k, t, m[, org_k])

Calculate the m th order derivative (from the right) of an indexed b-spline at x.

evaluate(spline, x[, m])

Evaluate a single x-axis data point, or a derivative value, on a Spline.

Classes#

PPSplineF64(k, t[, c])

Piecewise polynomial spline composed of float values on the x and y axes.

PPSplineDual(k, t[, c])

Piecewise polynomial spline composed of float values on the x-axis and Dual values on the y-axis.

PPSplineDual2(k, t[, c])

Piecewise polynomial spline composed of float values on the x-axis and Dual2 values on the y-axis.

Dual (for AD)#

Functions#

dual_exp(x)

Calculate the exponential value of a regular int or float or a dual number.

dual_inv_norm_cdf(x)

Return the inverse cumulative standard normal distribution for given value.

dual_log(x[, base])

Calculate the logarithm of a regular int or float or a dual number.

dual_norm_cdf(x)

Return the cumulative standard normal distribution for given value.

dual_norm_pdf(x)

Return the standard normal probability density function.

dual_solve(A, b[, allow_lsq, types])

Solve a linear system of equations involving dual number data types.

gradient(dual[, vars, order, keep_manifold])

Return derivatives of a dual number.

set_order(val, order)

Changes the order of a Dual or Dual2 leaving floats and ints unchanged.

set_order_convert(val, order, tag[, vars_from])

Convert a float, Dual or Dual2 type to a specified alternate type.

Classes#

Dual(real, vars, dual)

Dual number data type to perform first derivative automatic differentiation.

Dual2(real, vars, dual, dual2)

Dual number data type to perform second derivative automatic differentiation.

Curves#

Functions#

average_rate(effective, termination, ...)

Return the geometric, 1 calendar day, average rate for the rate in a period.

index_left(list_input, list_length, value[, ...])

Return the interval index of a value from an ordered input list on the left side.

interpolate(x, x_1, y_1, x_2, y_2, interpolation)

Perform local interpolation between two data points.

Classes#

CompositeCurve(curves[, id])

A dynamic composition of a sequence of other curves.

Curve(nodes, *[, interpolation, t, c, ...])

Curve based on DF parametrisation at given node dates with interpolation.

IndexCurve(*args[, index_base, index_lag])

A subclass of Curve with an index_base value for index calculations.

LineCurve(*args, **kwargs)

Curve based on value parametrisation at given node dates with interpolation.

MultiCsaCurve(curves[, id, ...])

A dynamic composition of a sequence of other curves.

ProxyCurve(cashflow, collateral, fx_forwards)

A subclass of Curve which returns dynamic DFs based on other curves related via FXForwards parity.

Class Inheritance Diagram#

Inheritance diagram of rateslib.curves.curves.CompositeCurve, rateslib.curves.curves.Curve, rateslib.curves.curves.IndexCurve, rateslib.curves.curves.LineCurve, rateslib.curves.curves.MultiCsaCurve, rateslib.curves.curves.ProxyCurve

FX#

Functions#

forward_fx(date, curve_domestic, ...[, ...])

Return a forward FX rate based on interest rate parity.

Classes#

FXForwards(fx_rates, fx_curves[, base])

Class for storing and calculating FX forward rates.

FXRates(fx_rates[, settlement, base])

Object to store and calculate FX rates for a consistent settlement date.

FX Volatility#

Classes#

FXDeltaVolSmile(nodes, eval_date, expiry, ...)

Create an FX Volatility Smile at a given expiry indexed by delta percent.

FXDeltaVolSurface(delta_indexes, expiries, ...)

Create an FX Volatility Surface parametrised by cross-sectional Smiles at different expiries.

Class Inheritance Diagram#

Inheritance diagram of rateslib.fx_volatility.FXDeltaVolSmile, rateslib.fx_volatility.FXDeltaVolSurface

Periods#

Link to the Periods section in the user guide.

Classes#

BasePeriod(start, end, payment, frequency[, ...])

Abstract base class with common parameters for all Period subclasses.

Cashflow(notional, payment[, currency, ...])

Create a single cashflow amount on a payment date (effectively a CustomPeriod).

FXCallPeriod(*args, **kwargs)

Create an FXCallPeriod.

FXOptionPeriod(pair, expiry, delivery, payment)

Abstract base class for constructing volatility components of FXOptions.

FXPutPeriod(*args, **kwargs)

Create an FXPutPeriod.

FixedPeriod(*args[, fixed_rate])

Create a period defined with a fixed rate.

FloatPeriod(*args[, float_spread, fixings, ...])

Create a period defined with a floating rate index.

IndexCashflow(*args, index_base[, ...])

Create a cashflow defined with a real rate adjusted by an index.

IndexFixedPeriod(*args[, index_base, ...])

Create a period defined with a real rate adjusted by an index.

IndexMixin()

Abstract base class to include methods and properties related to indexed Periods.

Class Inheritance Diagram#

Inheritance diagram of rateslib.periods.BasePeriod, rateslib.periods.Cashflow, rateslib.periods.FXCallPeriod, rateslib.periods.FXOptionPeriod, rateslib.periods.FXPutPeriod, rateslib.periods.FixedPeriod, rateslib.periods.FloatPeriod, rateslib.periods.IndexCashflow, rateslib.periods.IndexFixedPeriod, rateslib.periods.IndexMixin

Legs#

Link to the Legs section in the user guide.

Classes#

BaseLeg(effective, termination, frequency, *)

Abstract base class with common parameters for all Leg subclasses.

BaseLegMtm(*args[, fx_fixings, ...])

Abstract base class with common parameters for all LegMtm subclasses.

CustomLeg(periods)

Create a leg contained of user specified Periods.

FixedLeg(*args[, fixed_rate])

Create a fixed leg composed of FixedPeriod s.

FixedLegMixin()

Add the functionality to add and retrieve fixed_rate on FixedPeriod s.

FixedLegMtm(*args[, fixed_rate])

Create a leg of FixedPeriod s and initial, mtm and final Cashflow s.

FloatLeg(*args[, float_spread, fixings, ...])

Create a floating leg composed of FloatPeriod s.

FloatLegMixin()

Add the functionality to add and retrieve float_spread on FloatPeriod s and a fixings_table().

FloatLegMtm(*args[, float_spread, fixings, ...])

Create a leg of FloatPeriod s and initial, mtm and final Cashflow s.

IndexFixedLeg(*args, index_base[, ...])

Create a leg of IndexFixedPeriod s and initial and final IndexCashflow s.

IndexLegMixin()

ZeroFixedLeg(*args[, fixed_rate])

Create a zero coupon fixed leg composed of a single FixedPeriod .

ZeroFloatLeg(*args[, float_spread, fixings, ...])

Create a zero coupon floating leg composed of FloatPeriod s.

ZeroIndexLeg(*args[, index_base, ...])

Create a zero coupon index leg composed of a single IndexFixedPeriod and a Cashflow.

Class Inheritance Diagram#

Inheritance diagram of rateslib.legs.BaseLeg, rateslib.legs.BaseLegMtm, rateslib.legs.CustomLeg, rateslib.legs.FixedLeg, rateslib.legs.FixedLegMixin, rateslib.legs.FixedLegMtm, rateslib.legs.FloatLeg, rateslib.legs.FloatLegMixin, rateslib.legs.FloatLegMtm, rateslib.legs.IndexFixedLeg, rateslib.legs.IndexLegMixin, rateslib.legs.ZeroFixedLeg, rateslib.legs.ZeroFloatLeg, rateslib.legs.ZeroIndexLeg

Instruments#

Classes#

BaseDerivative([effective, termination, ...])

Abstract base class with common parameters for many Derivative subclasses.

BaseMixin()

Bill([effective, termination, frequency, ...])

Create a discount security.

BondMixin()

BondCalcMode(settle_accrual_type, ...)

Define calculation conventions for FixedRateBond, IndexFixedRateBond and FloatRateNote types.

BillCalcMode(price_type, ytm_clone_kwargs)

Define calculation conventions for Bill type.

BondFuture(coupon, delivery, basket[, ...])

Create a bond future derivative.

FRA([effective, termination, frequency, ...])

Create a forward rate agreement composing single period FixedLeg and FloatLeg valued in a customised manner.

FXBrokerFly(*args[, strike, premium, ...])

Create an FX BrokerFly option strategy.

FXCall(*args, **kwargs)

Create an FX Call option.

FXExchange(settlement, pair[, fx_rate, ...])

Create a simple exchange of two currencies.

FXOption(pair, expiry[, notional, ...])

Create an FX Option.

FXOptionStrat(options, rate_weight, ...)

Create a custom option strategy composed of a list of FXOption.

FXPut(*args, **kwargs)

Create an FX Put option.

FXRiskReversal(*args[, strike, premium, metric])

Create an FX Risk Reversal option strategy.

FXStraddle(*args[, premium, metric])

Create an FX Straddle option strategy.

FXStrangle(*args[, strike, premium, metric])

Create an FX Strangle option strategy.

FXSwap(*args[, pair, fx_fixings, points, ...])

Create an FX swap simulated via a Fixed-Fixed XCS.

FixedRateBond([effective, termination, ...])

Create a fixed rate bond security.

FloatRateNote([effective, termination, ...])

Create a floating rate note (FRN) security.

Fly(instrument1, instrument2, instrument3)

A butterfly instrument which is, mechanically, the spread of two spread instruments.

IIRS(*args[, fixed_rate, index_base, ...])

Create an indexed interest rate swap (IIRS) composing an IndexFixedLeg and a FloatLeg.

IRS(*args[, fixed_rate, leg2_float_spread, ...])

Create an interest rate swap composing a FixedLeg and a FloatLeg.

IndexFixedRateBond([effective, termination, ...])

Create an indexed fixed rate bond security.

Portfolio(instruments)

Create a collection of Instruments to group metrics

SBS(*args[, float_spread, ...])

Create a single currency basis swap composing two FloatLeg s.

STIRFuture(*args[, price, contracts, ...])

Create a short term interest rate (STIR) future.

Sensitivities()

Base class to add risk sensitivity calculations to an object with an npv() method.

Spread(instrument1, instrument2)

A spread instrument defined as the difference in rate between two Instruments.

Value(effective[, convention, metric, curves])

A null Instrument which can be used within a Solver to directly parametrise a Curve node, via some calculated value.

VolValue(index_value[, metric, vol])

A null Instrument which can be used within a Solver to directly parametrise a Vol node, via some calculated metric.

XCS(*args[, fixed, payment_lag_exchange, ...])

Create a cross-currency swap (XCS) composing relevant fixed or floating Legs.

ZCIS(*args[, fixed_rate, leg2_index_base, ...])

Create a zero coupon index swap (ZCIS) composing an ZeroFixedLeg and a ZeroIndexLeg.

ZCS(*args[, fixed_rate, leg2_float_spread, ...])

Create a zero coupon swap (ZCS) composing a ZeroFixedLeg and a ZeroFloatLeg.

Class Inheritance Diagram#

Inheritance diagram of rateslib.instruments.BaseDerivative, rateslib.instruments.BaseMixin, rateslib.instruments.Bill, rateslib.instruments.BondMixin, rateslib.instruments.bonds.BondCalcMode, rateslib.instruments.bonds.BillCalcMode, rateslib.instruments.BondFuture, rateslib.instruments.FRA, rateslib.instruments.FXBrokerFly, rateslib.instruments.FXCall, rateslib.instruments.FXExchange, rateslib.instruments.FXOption, rateslib.instruments.FXOptionStrat, rateslib.instruments.FXPut, rateslib.instruments.FXRiskReversal, rateslib.instruments.FXStraddle, rateslib.instruments.FXStrangle, rateslib.instruments.FXSwap, rateslib.instruments.FixedRateBond, rateslib.instruments.FloatRateNote, rateslib.instruments.Fly, rateslib.instruments.IIRS, rateslib.instruments.IRS, rateslib.instruments.IndexFixedRateBond, rateslib.instruments.Portfolio, rateslib.instruments.SBS, rateslib.instruments.STIRFuture, rateslib.instruments.Sensitivities, rateslib.instruments.Spread, rateslib.instruments.Value, rateslib.instruments.VolValue, rateslib.instruments.XCS, rateslib.instruments.ZCIS, rateslib.instruments.ZCS

Solver#

Functions#

newton_1dim(f, g0[, max_iter, func_tol, ...])

Use the Newton-Raphson algorithm to determine the root of a function searching one variable.

newton_ndim(f, g0[, max_iter, func_tol, ...])

Use the Newton-Raphson algorithm to determine a function root searching many variables.

quadratic_eqn(a, b, c, x0[, raise_on_fail])

Solve the quadratic equation, \(ax^2 + bx +c = 0\), with error reporting.

Classes#

Gradients()

A catalogue of all the gradients used in optimisation routines and risk sensitivties.

Solver([curves, surfaces, instruments, s, ...])

A numerical solver to determine node values on multiple curves simultaneously.

Class Inheritance Diagram#

Inheritance diagram of rateslib.solver.Gradients, rateslib.solver.Solver

Cookbook#