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 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>]