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, Inflation Swaps (ZCISs).
Multi-Currency Derivatives, like FXSwaps and Cross-Currency Swaps (XCSs).
FX Volatility Derivatives, like FXCalls, FXPuts and FXStraddles.
Utilities and Instrument Combinations, which allows things like Spread trades, Butterflies, Portfolios and a Value for a Curve.
Each Instrument is its own Python Class, and, commonly, are sequentially constructed from other classes.
First Periods are defined in the
rateslib.periodsmodule.Secondly Legs are defined in the
rateslib.legsmodule and these combine and control a list of organised Periods.Finally Instruments are defined in the
rateslib.instrumentsmodule and these combine and control one or two Legs.
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 0x11e681130>
In [3]: irs.leg2
Out[3]: <rl.FloatLeg at 0x11e1f97e0>
# Each leg contains a list of Periods.
In [4]: irs.leg1.periods
Out[4]: [<rl.FixedPeriod at 0x11e631310>, <rl.FixedPeriod at 0x11e633050>]
In [5]: irs.leg2.periods
Out[5]: [<rl.FloatPeriod at 0x11e627e70>, <rl.FloatPeriod at 0x11e627bd0>]