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 \\ S =& \text{Fixed credit spread} \\ Q(m) =& \text{Survival probability at maturity,} \; m \\\end{split}\]

Defaults#

Classes#

Cal(holidays, week_mask)

A business day calendar with a singular list of holidays.

Defaults()

The defaults object used by initialising objects.

Fixings()

Class to lazy load fixing data from CSV files.

NamedCal(name)

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

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

Enumerable type to handle setting default values.

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.

Calendars#

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[, 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.

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_log(x[, base])

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

dual_exp(x)

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

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

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

dual_norm_pdf(x)

Return the standard normal probability density function.

dual_norm_cdf(x)

Return the cumulative standard normal distribution for given value.

dual_inv_norm_cdf(x)

Return the inverse cumulative standard normal distribution for given value.

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

Return derivatives of a dual number.

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

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

set_order(val, order)

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

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.

Variable(real[, vars, dual])

A user defined, exogenous variable that automatically converts to a Dual or Dual2 type dependent upon the overall AD calculation order.

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.

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).

CreditPremiumPeriod(*args[, fixed_rate, ...])

Create a credit premium period defined by a credit spread.

CreditProtectionPeriod(*args[, ...])

Create a credit protection period defined by a recovery rate.

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.CreditPremiumPeriod, rateslib.periods.CreditProtectionPeriod, 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#

CustomLeg(periods)

Create a leg contained of user specified Periods.

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.

FixedLeg(*args[, fixed_rate])

Create a fixed leg composed of FixedPeriod s.

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

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

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

Create a floating leg composed of FloatPeriod s.

FixedLegMtm(*args[, fixed_rate])

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

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

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

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.

CreditPremiumLeg(*args[, fixed_rate, ...])

Create a credit premium leg composed of CreditPremiumPeriod s.

CreditProtectionLeg(*args[, recovery_rate, ...])

Create a credit protection leg composed of CreditProtectionPeriod s.

Class Inheritance Diagram#

Inheritance diagram of rateslib.legs.CustomLeg, rateslib.legs.BaseLeg, rateslib.legs.BaseLegMtm, rateslib.legs.FixedLeg, rateslib.legs.IndexFixedLeg, rateslib.legs.FloatLeg, rateslib.legs.FixedLegMtm, rateslib.legs.FloatLegMtm, rateslib.legs.ZeroFixedLeg, rateslib.legs.ZeroFloatLeg, rateslib.legs.ZeroIndexLeg, rateslib.legs.CreditPremiumLeg, rateslib.legs.CreditProtectionLeg

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.

CDS(*args[, fixed_rate, premium_accrued, ...])

Create a credit default swap composing a CreditPremiumLeg and a CreditProtectionLeg.

FRA(*args[, fixed_rate, method_param, fixings])

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.rates_derivatives.BaseDerivative, rateslib.instruments.inst_core.BaseMixin, rateslib.instruments.bonds.securities.Bill, rateslib.instruments.bonds.securities.BondMixin, rateslib.instruments.bonds.conventions.BondCalcMode, rateslib.instruments.bonds.conventions.BillCalcMode, rateslib.instruments.bonds.futures.BondFuture, rateslib.instruments.rates_derivatives.CDS, rateslib.instruments.rates_derivatives.FRA, rateslib.instruments.fx_volatility.FXBrokerFly, rateslib.instruments.fx_volatility.FXCall, rateslib.instruments.rates_multi_ccy.FXExchange, rateslib.instruments.fx_volatility.FXOption, rateslib.instruments.fx_volatility.FXOptionStrat, rateslib.instruments.fx_volatility.FXPut, rateslib.instruments.fx_volatility.FXRiskReversal, rateslib.instruments.fx_volatility.FXStraddle, rateslib.instruments.fx_volatility.FXStrangle, rateslib.instruments.rates_multi_ccy.FXSwap, rateslib.instruments.bonds.securities.FixedRateBond, rateslib.instruments.bonds.securities.FloatRateNote, rateslib.instruments.generics.Fly, rateslib.instruments.rates_derivatives.IIRS, rateslib.instruments.rates_derivatives.IRS, rateslib.instruments.bonds.securities.IndexFixedRateBond, rateslib.instruments.generics.Portfolio, rateslib.instruments.rates_derivatives.SBS, rateslib.instruments.rates_derivatives.STIRFuture, rateslib.instruments.inst_core.Sensitivities, rateslib.instruments.generics.Spread, rateslib.instruments.generics.Value, rateslib.instruments.generics.VolValue, rateslib.instruments.rates_multi_ccy.XCS, rateslib.instruments.rates_derivatives.ZCIS, rateslib.instruments.rates_derivatives.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#

Please see here for the cookbook index.