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#

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.

Scheduling#

Functions#

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

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

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, definition])

Return an IMM date for a specified month.

next_imm(start[, definition])

Return the next IMM date after the given start date.

Classes#

Schedule(effective, termination, frequency, *)

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

Adjuster(args)

Enumerable type for date adjustment rules.

Frequency(args)

Enumerable type for a scheduling frequency.

StubInference(item)

Enumerable type for Schedule stub inference.

Convention(variant)

Specifier for day count conventions

Imm(item)

Enumerable type for International Money-Market (IMM) date definitions.

Cal(holidays, week_mask)

A business day calendar defined by weekends and a holiday list.

NamedCal(name)

A wrapped UnionCal constructed with a string parsing syntax.

RollDay(args)

Enumerable type for roll days.

UnionCal(calendars[, settlement_calendars])

A calendar defined by a business day intersection of multiple Cal objects.

Piecewise Polynomial Splines#

Functions#

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.

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

Calculate the value 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#

PPSplineDual(k, t[, c])

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

PPSplineDual2(k, t[, c])

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

PPSplineF64(k, t[, c])

Piecewise polynomial spline composed of float-64 values on the x-axis and float-64 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 with tagged variables.

set_order(val, order)

Changes the order of a Dual or Dual2 and a sets a Variable.

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

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

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

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

ift_1dim(s, s_tgt, h[, ini_h_args, ...])

Use the inverse function theorem to determine a function value of one variable.

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

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

Classes#

ADOrder(ad)

Defines the order of gradients available in a calculation with AD.

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-day, average simple rate for a given simple period rate.

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

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

index_value(index_lag, index_method[, ...])

Determine an index value from a reference date using combinations of known fixings and forecast from a Curve.

Classes#

CompositeCurve(curves[, id, _no_validation])

A dynamic composition of a sequence of other _BaseCurve.

Curve(*args, **kwargs)

A _BaseCurve with DF parametrisation at given node dates with interpolation.

LineCurve(*args, **kwargs)

A _BaseCurve with value parametrisation at given node dates with interpolation.

MultiCsaCurve(curves[, id])

A dynamic composition of a sequence of other _BaseCurve.

ProxyCurve(cashflow, collateral, fx_forwards)

A _BaseCurve which returns dynamic DFs from an FXForwards object and FX parity.

CreditImpliedCurve([risk_free, credit, ...])

Imply a _BaseCurve from credit components.

_CurveMeta(_calendar, _convention, ...)

A container of meta data associated with a _BaseCurve used to make calculations.

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

Enumerable type to define the difference between a discount factor (DF) based and values based _BaseCurve.

_CurveSpline(t, endpoints)

A container for data relating to interpolating _CurveNodes using a cubic PPSpline.

_CurveInterpolator(local, t, endpoints, ...)

A container for data relating to interpolating _CurveNodes.

_CurveNodes(_nodes)

An immutable container for the pricing parameters of a _BaseCurve.

_ProxyCurveInterpolator(_fx_forwards, _cash, ...)

A container for data relating to interpolating the DFs of a ProxyCurve.

RolledCurve(curve, roll_days[, id])

Create a new _BaseCurve type by translating the rate space of an input curve horizontally in time.

ShiftedCurve(curve, shift[, id])

Create a new _BaseCurve type by compositing an input with another flat curve of a set number of basis points.

TranslatedCurve(curve, start[, id])

Create a new _BaseCurve type by maintaining the rate space of an input curve but shifting the initial node date forwards in time.

_WithOperations()

Provides automatic implementation of the curve operations required on a _BaseCurve.

_BaseCurve()

An ABC defining the base methods of a Curve.

_WithMutability(nodes, *[, interpolation, ...])

This class is designed as a mixin for the methods for Curve Pricing Objects, i.e. the Curve and LineCurve.

Class Inheritance Diagram#

Inheritance diagram of rateslib.curves.Curve, rateslib.curves.LineCurve, rateslib.curves.CompositeCurve, rateslib.curves.MultiCsaCurve, rateslib.curves.ProxyCurve, rateslib.curves._BaseCurve, rateslib.curves._WithMutability, rateslib.curves.CreditImpliedCurve, rateslib.curves.TranslatedCurve, rateslib.curves.RolledCurve, rateslib.curves.ShiftedCurve

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#

FXSabrSmile(nodes, eval_date, expiry[, ...])

Create an FX Volatility Smile at a given expiry indexed by strike using SABR parameters.

FXSabrSurface(expiries, node_values, eval_date)

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

FXDeltaVolSurface(delta_indexes, expiries, ...)

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

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

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

_BaseSmile()

_FXDeltaVolSurfaceMeta(_eval_date, ...)

An immutable container of meta data associated with a FXDeltaVolSurface used to make calculations.

_FXSmileMeta(_eval_date, _expiry, ...)

_FXDeltaVolSpline(t)

A container for data relating to interpolating the nodes of a FXDeltaVolSmile using a cubic PPSpline.

_FXDeltaVolSmileNodes(nodes, meta)

A container for data relating to interpolating the nodes of a FXDeltaVolSmile.

_FXSabrSurfaceMeta(_eval_date, _pair, ...)

An immutable container of meta data associated with a FXSabrSurface used to make calculations.

_FXSabrSmileNodes(_alpha, _beta, _rho, _nu)

A container for data relating to the SABR parameters of a FXSabrSmile.

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.

FXOptionPeriod(pair, expiry, delivery, payment)

Abstract base class for constructing volatility components of FXOptions.

FXPutPeriod(*args, **kwargs)

Create an FXPutPeriod.

FXCallPeriod(*args, **kwargs)

Create an FXCallPeriod.

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

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

NonDeliverableCashflow(notional, currency, ...)

Create a cashflow amount associated with a non-deliverable FX forward.

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

Create a credit premium period defined by a credit spread.

CreditProtectionPeriod(*args, **kwargs)

Create a credit protection period defined by a recovery rate.

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.

FixedPeriod(*args[, fixed_rate])

Create a period defined with a fixed rate.

NonDeliverableFixedPeriod(*args, ...[, ...])

Create a FixedPeriod whose non-deliverable cashflow is converted to a settlement_currency.

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

Create a period defined with a floating rate index.

IndexMixin()

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

Class Inheritance Diagram#

Inheritance diagram of rateslib.periods.base.BasePeriod, rateslib.periods.fx_volatility.FXOptionPeriod, rateslib.periods.fx_volatility.FXPutPeriod, rateslib.periods.fx_volatility.FXCallPeriod, rateslib.periods.cashflow.Cashflow, rateslib.periods.cashflow.NonDeliverableCashflow, rateslib.periods.credit.CreditPremiumPeriod, rateslib.periods.credit.CreditProtectionPeriod, rateslib.periods.index.IndexCashflow, rateslib.periods.index.IndexFixedPeriod, rateslib.periods.rates.FixedPeriod, rateslib.periods.rates.NonDeliverableFixedPeriod, rateslib.periods.rates.FloatPeriod, rateslib.periods.index.IndexMixin

Legs#

Link to the Legs section in the user guide.

Classes#

CustomLeg(periods)

Create a leg contained of user specified Periods.

BaseLeg(schedule, *[, notional, currency, ...])

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.base.CustomLeg, rateslib.legs.base.BaseLeg, rateslib.legs.mtm.BaseLegMtm, rateslib.legs.rates.FixedLeg, rateslib.legs.index.IndexFixedLeg, rateslib.legs.rates.FloatLeg, rateslib.legs.mtm.FixedLegMtm, rateslib.legs.mtm.FloatLegMtm, rateslib.legs.zeros.ZeroFixedLeg, rateslib.legs.zeros.ZeroFloatLeg, rateslib.legs.index.ZeroIndexLeg, rateslib.legs.credit.CreditPremiumLeg, rateslib.legs.credit.CreditProtectionLeg

Instruments#

Classes#

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

Abstract base class with common parameters for many Derivative subclasses.

Metrics()

Base class for Instruments adding optional pricing parameters, such as fixed rates, float spreads etc.

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

Create a discount security.

BondMixin()

Inheritable class to provide basic functionality.

BondCalcMode(settle_accrual, ytm_accrual, ...)

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, or other FXOptionStrat objects.

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.

NDF(settlement, pair[, notional, fx_rate, ...])

Create a non-deliverable forward (NDF).

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[, expiry, 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.base.BaseDerivative, rateslib.instruments.base.Metrics, 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.credit.derivatives.CDS, rateslib.instruments.rates.single_currency.FRA, rateslib.instruments.fx_volatility.strategies.FXBrokerFly, rateslib.instruments.fx_volatility.vanilla.FXCall, rateslib.instruments.rates.multi_currency.FXExchange, rateslib.instruments.fx_volatility.vanilla.FXOption, rateslib.instruments.fx_volatility.strategies.FXOptionStrat, rateslib.instruments.fx_volatility.vanilla.FXPut, rateslib.instruments.fx_volatility.strategies.FXRiskReversal, rateslib.instruments.fx_volatility.strategies.FXStraddle, rateslib.instruments.fx_volatility.strategies.FXStrangle, rateslib.instruments.rates.multi_currency.FXSwap, rateslib.instruments.bonds.securities.FixedRateBond, rateslib.instruments.bonds.securities.FloatRateNote, rateslib.instruments.generics.Fly, rateslib.instruments.rates.inflation.IIRS, rateslib.instruments.rates.single_currency.IRS, rateslib.instruments.bonds.securities.IndexFixedRateBond, rateslib.instruments.rates.multi_currency.NDF, rateslib.instruments.generics.Portfolio, rateslib.instruments.rates.single_currency.SBS, rateslib.instruments.rates.single_currency.STIRFuture, rateslib.instruments.sensitivities.Sensitivities, rateslib.instruments.generics.Spread, rateslib.instruments.generics.Value, rateslib.instruments.generics.VolValue, rateslib.instruments.rates.multi_currency.XCS, rateslib.instruments.rates.inflation.ZCIS, rateslib.instruments.rates.single_currency.ZCS

Solver#

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 pricing objects simultaneously.

Class Inheritance Diagram#

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

Serialization#

Functions#

from_json(json)

Create an object from JSON string.

Cookbook#

Please see here for the cookbook index.