Get Started#

Installation#

Rateslib can be installed directly from PyPI using pip into your Python environment.

pip install rateslib

Versions of rateslib greater than and starting at 1.2.0 use Rust extensions for performance. For most users this will not affect the installation of rateslib, however for some computer architectures (e.g. Linux) Python wheels are not pre-built, and this means pip install rateslib will use the source distribution directly. In this case you must first install Rust so that the rust extensions can be compiled locally.

Additionally, for versions less than 1.2.0, it can be installed via the community conda-forge channel available from Anaconda.org

conda install --channel=conda-forge rateslib

Minimum Dependencies

Package Name

Latest Tested

Recommended Version

Earliest Tested

Python

3.11

3.11

3.9

NumPy

1.26.4

1.26.1

1.21.5

Pandas

2.2.1

2.1.3

1.4.1

Matplotlib

3.8.3

3.8.1

3.5.1

Introduction to Rateslib#

For what purpose would I use rateslib?#

  • If you want to integrate linear fixed income analysis into your workflow with Python.

  • If you desire a pain free setup process, a user-oriented API, and extensive documentation.

  • If you are new to fixed income and interested to learn about basic and advanced concepts with tools to explore the nuances of these markets, as a companion to various authored books.

Which fixed income instruments does rateslib include?#

Single Ccy Derivatives

Multi-Ccy Derivatives

Securities

Volatility

Combinations

IRS

FXExchange

FixedRateBond

FXCall

Spread

SBS

FXSwap

FloatRateNote

FXPut

Fly

FRA

XCS

Bill

FXRiskReversal

Portfolio

STIRFuture

BondFuture

ZCS

IndexFixedRateBond

ZCIS

IIRS

Does rateslib handle foreign exchange (FX)?#

Yes. Foreign exchange is a pre-requisite of properly handling multi-currency fixed income derivatives, so the FXRates and FXForwards classes exist to allow full flexibility and expressing quantities in consistent currencies.

Can Curves be constructed and plotted in rateslib?#

Of course. Building curves is a necessity for pricing fixed income instruments. Rateslib has three primitive curve structures; Curve (which is discount factor based), LineCurve (which is purely value based), and IndexCurve (which is based on a Curve but also calculates index values which is useful for inflation, for example). All Curve types offer various interpolation methods, such as log-linear or log-cubic spline and can even splice certain interpolation types together.

Does rateslib solve curves relative to market prices?#

Yes, when a Solver is configured along with all the intended Instruments and their relevant prices. Multiple algorithms (gradient descent, Gauss-Newton, Levenberg-Marquardt) and stopping criteria can be used within the optimization routine to simultaneously solve multiple Curve parameters.

The Solver can even construct dependency chains, like sequentially building curves with dependencies to other desks on an investment bank trading floor, and internally manage all of the risk sensitivity calculations.

Does rateslib use automatic differentiation (AD)?#

Yes. The dual module provides rateslib with its own integrated automatic differentiation toolset, primarily the dual datatypes Dual and Dual2, which operate in forward mode (as opposed to backwards, or adjoint, mode). This allows native calculations to store first (or second) derivative information as those calculations are made on-the-fly.

Imports and Defaults#

Rateslib classes and methods are publicly exposed meaning anything can be imported and used from the top level.

from rateslib import Curve, IRS, FXRates  # or * to blanket import everything

It is also possible to import the library as object and call objects from that,

import rateslib as rl
curve = rl.Curve(...)

The defaults object from rateslib sets parameters and settings that are used when otherwise not set by the user. This object can only be imported, and changed, from the top level.

from rateslib import defaults
defaults.base_currency = "eur"
import rateslib as rl
rl.defaults.base_currency = "eur"

How to Use Rateslib#

The best way to learn rateslib is to follow the tutorials and examples in the User Guide. This systematically introduces the main objects and concepts.