Schedule#
The rateslib.scheduling
module generates common financial instrument schedules.
Scheduling is a surprisingly complex
issue, especially when one wants to infer some necessary parameters from the given
information.
The Schedule
object has an original set of available input types,
used since the initial version of rateslib and a core set of available input types which
more closely align with the Rust re-implementation after version 2.0. These can be intermixed,
but for demonstration purposes this page uses core inputs.
The original inputs allow for a more UI friendly input for the most common schedules.
In [1]: s = Schedule(
...: dt(2000, 1, 15),
...: dt(2001, 1, 1),
...: "Q",
...: stub="ShortFront",
...: modifier="MF",
...: payment_lag=2,
...: calendar="tgt",
...: )
...:
In [2]: print(s)
freq: 3M (roll: 1), accrual adjuster: MF, payment adjuster: 2B,
Period Unadj Acc Start Unadj Acc End Acc Start Acc End Payment
0 Stub 2000-01-15 2000-04-01 2000-01-17 2000-04-03 2000-04-05
1 Regular 2000-04-01 2000-07-01 2000-04-03 2000-07-03 2000-07-05
2 Regular 2000-07-01 2000-10-01 2000-07-03 2000-10-02 2000-10-04
3 Regular 2000-10-01 2001-01-01 2000-10-02 2001-01-02 2001-01-04
The core inputs utilise the Rust objects directly and may provide more flexibility.
In [3]: s = Schedule(
...: dt(2000, 1, 15),
...: dt(2001, 1, 1),
...: Frequency.Months(3, RollDay.Day(1)),
...: stub=StubInference.ShortFront,
...: modifier=Adjuster.ModifiedFollowing(),
...: payment_lag=Adjuster.BusDaysLagSettle(2),
...: calendar=NamedCal("tgt"),
...: )
...:
In [4]: print(s)
freq: 3M (roll: 1), accrual adjuster: MF, payment adjuster: 2B,
Period Unadj Acc Start Unadj Acc End Acc Start Acc End Payment
0 Stub 2000-01-15 2000-04-01 2000-01-17 2000-04-03 2000-04-05
1 Regular 2000-04-01 2000-07-01 2000-04-03 2000-07-03 2000-07-05
2 Regular 2000-07-01 2000-10-01 2000-07-03 2000-10-02 2000-10-04
3 Regular 2000-10-01 2001-01-01 2000-10-02 2001-01-02 2001-01-04
Summary#
Classes#
|
Generate a schedule of dates according to a regular pattern and calendar inference. |
Enumerable type for a scheduling frequency. |
|
Enumerable type for roll days. |
|
Enumerable type for date adjustment rules. |
|
Enumerable type for |
Scheduling Examples#
The following scheduling patterns are possible to construct in rateslib.
A regular schedule, which does not contain any stub periods.
Irregular schedules, which consist of the following:
A single stub period, be it a short or long stub.
Two stub periods, combining any short and long varieties.
A front stub and a regular schedule.
A regular schedule and a back stub.
A front stub and a regular schedule and a back stub.
The below tabs give an example of each construction type. To minimise the complexity of these examples all dates are given in their unadjusted form, which is how they should be given to avoid any inference.
The unadjusted effective
and termination
dates perfectly divide the frequency
.
In this instance any stub
inference parameter is unused.
In [5]: s = Schedule(
...: dt(2000, 1, 1),
...: dt(2001, 1, 1),
...: Frequency.Months(3, RollDay.Day(1)),
...: stub=StubInference.ShortFront,
...: )
...:
In [6]: print(s)
freq: 3M (roll: 1), accrual adjuster: MF, payment adjuster: 2B,
Period Unadj Acc Start Unadj Acc End Acc Start Acc End Payment
0 Regular 2000-01-01 2000-04-01 2000-01-01 2000-04-01 2000-04-03
1 Regular 2000-04-01 2000-07-01 2000-04-01 2000-07-01 2000-07-03
2 Regular 2000-07-01 2000-10-01 2000-07-01 2000-10-01 2000-10-03
3 Regular 2000-10-01 2001-01-01 2000-10-01 2001-01-01 2001-01-03
The stub
inference parameter is explicitly set to None here.
In [7]: s = Schedule(
...: dt(2000, 1, 1),
...: dt(2000, 2, 15),
...: Frequency.Months(3, RollDay.Day(1)),
...: stub=None,
...: )
...:
In [8]: print(s)
freq: 3M (roll: 1), accrual adjuster: MF, payment adjuster: 2B,
Period Unadj Acc Start Unadj Acc End Acc Start Acc End Payment
0 Stub 2000-01-01 2000-02-15 2000-01-01 2000-02-15 2000-02-17
The stub
inference parameter is explicitly set to None here.
In [9]: s = Schedule(
...: dt(2000, 1, 1),
...: dt(2000, 5, 15),
...: Frequency.Months(3, RollDay.Day(1)),
...: stub=None,
...: )
...:
In [10]: print(s)
freq: 3M (roll: 1), accrual adjuster: MF, payment adjuster: 2B,
Period Unadj Acc Start Unadj Acc End Acc Start Acc End Payment
0 Stub 2000-01-01 2000-05-15 2000-01-01 2000-05-15 2000-05-17
Both the front_stub
and back_stub
dates must be equivalent. stub
inference is set
to None.
In [11]: s = Schedule(
....: dt(2000, 1, 1),
....: dt(2000, 5, 15),
....: Frequency.Months(3, None),
....: front_stub=dt(2000, 1, 20),
....: back_stub=dt(2000, 1, 20),
....: stub=None,
....: )
....:
In [12]: print(s)
freq: 3M (roll: 20), accrual adjuster: MF, payment adjuster: 2B,
Period Unadj Acc Start Unadj Acc End Acc Start Acc End Payment
0 Stub 2000-01-01 2000-01-20 2000-01-01 2000-01-20 2000-01-22
1 Stub 2000-01-20 2000-05-15 2000-01-20 2000-05-15 2000-05-17
Set a front_stub
and ensure the subsequent termination
aligns with a regular schedule.
Or permit stub
inference.
In [13]: s = Schedule(
....: dt(2000, 1, 1),
....: dt(2000, 11, 15),
....: Frequency.Months(3, None),
....: stub=StubInference.ShortFront,
....: )
....:
In [14]: print(s)
freq: 3M (roll: 15), accrual adjuster: MF, payment adjuster: 2B,
Period Unadj Acc Start Unadj Acc End Acc Start Acc End Payment
0 Stub 2000-01-01 2000-02-15 2000-01-01 2000-02-15 2000-02-17
1 Regular 2000-02-15 2000-05-15 2000-02-15 2000-05-15 2000-05-17
2 Regular 2000-05-15 2000-08-15 2000-05-15 2000-08-15 2000-08-17
3 Regular 2000-08-15 2000-11-15 2000-08-15 2000-11-15 2000-11-17
Set a back_stub
and ensure the preliminary effective
aligns with a regular schedule.
Or permit stub
inference.
In [15]: s = Schedule(
....: dt(2000, 1, 1),
....: dt(2000, 11, 15),
....: Frequency.Months(3, None),
....: stub=StubInference.LongBack,
....: )
....:
In [16]: print(s)
freq: 3M (roll: 1), accrual adjuster: MF, payment adjuster: 2B,
Period Unadj Acc Start Unadj Acc End Acc Start Acc End Payment
0 Regular 2000-01-01 2000-04-01 2000-01-01 2000-04-01 2000-04-03
1 Regular 2000-04-01 2000-07-01 2000-04-01 2000-07-01 2000-07-03
2 Stub 2000-07-01 2000-11-15 2000-07-01 2000-11-15 2000-11-17
Stub inference can only be applied to one side. Either supply both front_stub
and
back_stub
or supply one and permit stub
inference on the remaining side.
In [17]: s = Schedule(
....: dt(2000, 1, 1),
....: dt(2000, 11, 15),
....: Frequency.Months(3, None),
....: front_stub=dt(2000, 1, 21),
....: stub=StubInference.ShortBack,
....: )
....:
In [18]: print(s)
freq: 3M (roll: 21), accrual adjuster: MF, payment adjuster: 2B,
Period Unadj Acc Start Unadj Acc End Acc Start Acc End Payment
0 Stub 2000-01-01 2000-01-21 2000-01-01 2000-01-21 2000-01-23
1 Regular 2000-01-21 2000-04-21 2000-01-21 2000-04-21 2000-04-23
2 Regular 2000-04-21 2000-07-21 2000-04-21 2000-07-21 2000-07-23
3 Regular 2000-07-21 2000-10-21 2000-07-21 2000-10-21 2000-10-23
4 Stub 2000-10-21 2000-11-15 2000-10-21 2000-11-15 2000-11-17
Construction elements#
A Schedule
in rateslib is characterised by three major attributes:
its uschedule which is a list of unadjusted dates defining its unambiguous skeletal structure.
its aschedule which applies the
modifier
as an accrualAdjuster
to adjust the unadjusted dates into adjusted accrual dates for defining its accrual periods.its pschedule which applies the
payment_lag
as a secondaryAdjuster
to adjust each accrual date to determine a physical payment, or cashflow settlement, date.Adjuster
All of the input arguments to a Schedule
fit into the logic for
yielding these three components.