rateslib
Python PyPi Conda Licence Status Coverage Code Style

Rateslib is a state-of-the-art fixed income library designed for Python. Its purpose is to provide advanced, flexible and efficient fixed income analysis with a high level, well documented API.

Licence#

Rateslib is released under an Amended Creative Commons Attribution, Non-Commercial, No-Derivatives 4.0 International Licence. For more details see here.

Academic and at-home educational use: FREE to use and modify.
Commercial use: Not licensed for any use (funds, banks, etc,). Purchase User Licences

Highlights#

Other interface bindings#

Extension websites provide the documentation for using rateslib in other ways than directly with Python.

Rateslib-Excel
rateslib-excel provides Excel bindings for the Python library, to users with a commercial licence extension.
Rateslib-JS
rateslib-js allows integration with JavaScript/TypeScript via PyOdide, which is a Python interpreter for web browsers. The demo page gives a browser build where the code is shown in source, and integrates with Vue.js. Also see this LinkedIn article example.
Rateslib-Rust
rateslib-rs is the lower level codebase written in Rust, with PyO3 bindings, providing performant solutions for some of the Python classes and methods.

Curve construction is simple but has huge flexibility#

Multiple interpolation modes are offered by default and the generalised process for curve solving means very specific pricing artefacts can be accurately modelled with the correct formulations. The framework is accessible and requires minimal configuration.

usd_curve = Curve(
    nodes={...},
    convention="act360",
    calendar="nyc",
    interpolation="log_linear",
    id="sofr",
)
solver = Solver(
    curves=[usd_curve],
    instruments=[...],
    weights=[...],
    s=[...],
)

API is designed for users with full documentation#

Although any fixed income library uses complex mathematical processes, the API has been carefully designed to provide a workflow that is very intuitive. In the case of using it for small scale learning items often few parameters and arguments are required. For larger series of curves and more complicated object oriented associations the API signature does not materially change. Best practice is demonstrated in documentation examples.

xcs = XCS(
    effective=dt(2022, 2, 14), termination="15M",
    notional=100e6, float_spread=-10.25,
    spec="eurusd_xcs", curves=[...],
)  # Create a EUR/USD Cross-Ccy Swap

xcs.rate(solver=solver)
<Dual: -14.294203, [...], [...]>

xcs.npv(solver=solver, base="eur")
<Dual: -50,073.295467, [...], [...]>

Wide range of fixed income Instruments available#

The most recent version of rateslib contains the main Instruments that dominate linear fixed income products. The large array of input parameters for these gives scope to fully capture the nuances of these products across sectors and geographic regions, capturing aspects like trading calendars, day count conventions, payment delays, etc. New specifications and calendars are continually being added as users enquire.

A good example is a US Treasury Bond, replicated here with rateslib and the equivalent ticket in Bloomberg for reference point.

In [1]: ust = FixedRateBond(
   ...:     effective=dt(2023, 8, 15), termination=dt(2033, 8, 15),
   ...:     fixed_rate=3.875, spec="us_gb"
   ...: )  # Create a US-Treasury bond
   ...: 

In [2]: ust.price(ytm=4.0, settlement=dt(2025, 2, 14))
Out[2]: 99.10641380057267

In [3]: ust.duration(ytm=4.0, settlement=dt(2025, 2, 14), metric="risk")
Out[3]: np.float64(7.11053190579773)
US Treasury example using the FixedRateBond class

Minimal dependencies to other Python libraries#

The dependencies are to NumPy, Pandas, and Matplotlib. Rateslib does not have any dependencies to any automatic differentiation libraries, such as PyAudi or JAX, preferring initially to use its own forward mode module.

The test coverage is very high.

Get Started#

Move on to the next page to Get Started