.. _pricing-doc: .. ipython:: python :suppress: from rateslib.curves import * from rateslib.instruments import * import matplotlib.pyplot as plt from datetime import datetime as dt import numpy as np *********** Get Started *********** Installation ------------ *Rateslib* can **only** be installed on a machine under the terms of its :ref:`licence ` .. raw:: html

If you would like to install rateslib on a corporate machine without a licence extension, for a trial period of time, please register your interest by sending an email to info@rStockholm Kungsgatanateslib.com , who will grant such a request.

*Rateslib* can be installed directly from `PyPI `_ using ``pip`` into your Python environment. .. code-block:: 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 by the *pip* installer. *Rateslib* is also available via the community ``conda-forge`` channel for `Anaconda `_, but only for platforms Osx-64, Windows-64 and Linux-64. Other platform installs will default to the much earlier pre-rust 1.1.0 version. .. code-block:: conda install --channel=conda-forge rateslib **Minimum Dependencies** .. list-table:: :widths: 25 25 25 25 :header-rows: 1 * - Package Name - Latest Tested - Recommended Version - Earliest Tested * - Python - 3.13 - 3.12 - 3.10 (Oct '21) * - NumPy - 2.2.2 - 2.2.2 - 1.21.5 (Dec '21) * - Pandas - 2.2.3 - 2.2.3 - 1.4.1 (Feb '22) * - Matplotlib - 3.10.0 - 3.9.3 - 3.5.1 (Dec '21) Introduction to Rateslib ------------------------- For what purpose would I use *rateslib*? ============================================= - If you want to integrate linear fixed income, FX and FX volatility 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 currencies 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? =========================================================== .. list-table:: :widths: 20 20 20 20 20 :header-rows: 1 * - Single Ccy Derivatives - Multi-Ccy Derivatives - Securities - FX Volatility - Combinations * - :class:`~rateslib.instruments.IRS` - :class:`~rateslib.instruments.FXExchange` - :class:`~rateslib.instruments.FixedRateBond` - :class:`~rateslib.instruments.FXCall` - :class:`~rateslib.instruments.Spread` * - :class:`~rateslib.instruments.SBS` - :class:`~rateslib.instruments.FXSwap` - :class:`~rateslib.instruments.FloatRateNote` - :class:`~rateslib.instruments.FXPut` - :class:`~rateslib.instruments.Fly` * - :class:`~rateslib.instruments.FRA` - :class:`~rateslib.instruments.XCS` - :class:`~rateslib.instruments.Bill` - :class:`~rateslib.instruments.FXRiskReversal` - :class:`~rateslib.instruments.Portfolio` * - :class:`~rateslib.instruments.STIRFuture` - :class:`~rateslib.instruments.NDF` - :class:`~rateslib.instruments.BondFuture` - :class:`~rateslib.instruments.FXStraddle` - * - :class:`~rateslib.instruments.ZCS` - - :class:`~rateslib.instruments.IndexFixedRateBond` - :class:`~rateslib.instruments.FXStrangle` - * - :class:`~rateslib.instruments.ZCIS` - - - :class:`~rateslib.instruments.FXBrokerFly` - * - :class:`~rateslib.instruments.IIRS` - - - - * - :class:`~rateslib.instruments.CDS` - - - - .. raw:: html
:ref:`Straight to tutorial...` .. raw:: html
Does *rateslib* handle ``foreign exchange (FX)``? =========================================================== **Yes**. Foreign exchange is a pre-requisite of properly handling multi-currency fixed income derivatives, so the :class:`~rateslib.fx.FXRates` and :class:`~rateslib.fx.FXForwards` classes exist to allow full flexibility and expressing quantities in consistent currencies. Additionally *rateslib* also includes certain *FX Option* products and the ability to construct an :class:`~rateslib.fx_volatility.FXDeltaVolSmile` or :class:`~rateslib.fx_volatility.FXDeltaVolSurface` and :class:`~rateslib.fx_volatility.FXSabrSmile` or :class:`~rateslib.fx_volatility.FXSabrSurface` for pricing. .. raw:: html
:ref:`Straight to tutorial...` .. raw:: html
Can ``Curves`` be constructed and plotted in *rateslib*? =========================================================== **Of course**. Building curves is a necessity for pricing fixed income instruments. *Rateslib* has two primitive curve structures; :class:`~rateslib.curves.Curve`, which is **discount factor, or survival probability based** and which can also calculate index values for use with inflation products, for example, and :class:`~rateslib.curves.LineCurve` (which is **purely value based**). All *Curve* types offer various interpolation methods, such as log-linear or log-cubic spline and can even splice certain interpolation types together. .. raw:: html
:ref:`Straight to tutorial...` .. raw:: html
Does *rateslib* ``solve`` curves relative to market prices? =========================================================== **Yes**, when a :class:`~rateslib.solver.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. .. raw:: html
:ref:`Straight to tutorial...` .. raw:: html
Does *rateslib* use ``automatic differentiation (AD)``? =========================================================== **Yes** fully integrated into all calculations. The *dual* module provides *rateslib* with its own automatic differentiation toolset, primarily the dual datatypes :class:`~rateslib.dual.Dual` and :class:`~rateslib.dual.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. .. raw:: html
:ref:`Straight to tutorial...` .. raw:: html
Imports and Defaults -------------------- *Rateslib* classes and methods are publicly exposed meaning anything can be imported and used from the top level. .. code-block:: 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, .. code-block:: 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. .. code-block:: from rateslib import defaults defaults.base_currency = "eur" .. code-block:: 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 :ref:`User Guide`. This systematically introduces the main objects and concepts.