Rolling: when a date doesn't exist
Worked examples
Read the claim, then run it and check the machine agrees. One at a time — nothing here is taken on trust.
import QuantLib as ql
target = ql.TARGET()
d = ql.Date(31, 5, 2026) # a Sunday
for name, conv in (("Following", ql.Following),
("ModifiedFollowing", ql.ModifiedFollowing),
("Preceding", ql.Preceding)):
print(f"{name:18} -> {target.adjust(d, conv).ISO()}")
Following crosses into June; MF sees that the next business day (1 June) would change the month and rolls back to Friday 29 May instead; Preceding goes there directly. Same contract dates, same calendar — up to three different payment days, and up to three different accrual amounts. The contract names one of these; your code implements it exactly.
import QuantLib as ql
target = ql.TARGET()
sat = ql.Date(31, 1, 2026) # month-end Saturday
sun = ql.Date(30, 8, 2026) # a Sunday with August room to spare
print("31 Jan: F ->", target.adjust(sat, ql.Following).ISO(),
" MF ->", target.adjust(sat, ql.ModifiedFollowing).ISO())
print("30 Aug: F ->", target.adjust(sun, ql.Following).ISO(),
" MF ->", target.adjust(sun, ql.ModifiedFollowing).ISO())
At the January month-end, F escapes to 2 February and MF refuses, rolling back to Friday the 30th — a three-day payment difference on the same date. But on 30 August, both answer Monday the 31st: the next business day stays inside August, so the 'modified' clause never fires. MF is not "always earlier" — it's F with a month-boundary tripwire.
import QuantLib as ql
target = ql.TARGET()
feb27 = ql.Date(27, 2, 2026)
print("last business day of its month?", target.isEndOfMonth(feb27))
print("+1M, EOM=True: ", target.advance(feb27, ql.Period(1, ql.Months), ql.ModifiedFollowing, True).ISO())
print("+1M, EOM=False:", target.advance(feb27, ql.Period(1, ql.Months), ql.ModifiedFollowing, False).ISO())
With EOM, "one month after the last business day of February" means "the last business day of March" — the 31st. Without it, plain day-of-month arithmetic gives the 27th. Four days of accrual on every period of the schedule, controlled by one boolean that the trade confirmation does specify and rushed implementations do skip.
Check the concept
One question at a time. Unsure? Revisit the lecture, then answer.
The challenge
Pass the quiz to unlock the challenge — your code will still be waiting here.