Instruments#

Instruments in rateslib are generally categorised into the following groups:

Each Instrument is its own Python Class, and, commonly, are 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]: <rl.FixedLeg at 0x12178f290>

In [3]: irs.leg2
Out[3]: <rl.FloatLeg at 0x1217b43d0>

# Each leg contains a list of Periods.
In [4]: irs.leg1.periods
Out[4]: [<rl.FixedPeriod at 0x12178ed50>, <rl.FixedPeriod at 0x12178eb10>]

In [5]: irs.leg2.periods
Out[5]: [<rl.FloatPeriod at 0x1211c8c80>, <rl.FloatPeriod at 0x1211ca030>]