Instruments#

Instruments in rateslib are generally categorised into the following groups:

  • Securities, which are single currency based, like Bonds and Bills.

  • Single Currency Derivatives, like Interest Rate Swaps (IRS), FRAs.

  • Multi-currency Derivatives, like FXSwaps and Cross-Currency Swaps (XCSs)

Each Instrument is its own Python Class, and it is sequentially constructed from other classes.

  • First Periods are defined in the rateslib.periods module.

  • Secondly Legs are defined in the rateslib.legs module and these combine and control a list of organised Periods.

  • Finally Instruments are defined in the rateslib.instruments module and these combine and control one or two Legs.

Composition of objects to form instruments

It is recommended to review the documentation in the above order, since the composited objects are more explicit in their documentation of each parameter.

Users are expected to rarely use Periods or Legs directly but they are exposed in the public API in order to construct custom objects.

The below example demonstrates this composition when creating an IRS.

In [1]: irs = IRS(dt(2022, 1, 1), "1Y", "S")

# The IRS contains 2 Leg attributes.
In [2]: irs.leg1
Out[2]: <rateslib.legs.FixedLeg at 0x7f0a9ed19590>

In [3]: irs.leg2
Out[3]: <rateslib.legs.FloatLeg at 0x7f0a9edc7450>

# Each leg contains a list of Periods.
In [4]: irs.leg1.periods
Out[4]: 
[<FixedPeriod: 2022-01-01->2022-07-01,1000000.0,ACT360>,
 <FixedPeriod: 2022-07-01->2023-01-01,1000000.0,ACT360>]

In [5]: irs.leg2.periods
Out[5]: 
[<FloatPeriod: 2022-01-01->2022-07-01,-1000000.0,ACT360>,
 <FloatPeriod: 2022-07-01->2023-01-01,-1000000.0,ACT360>]