QuantLib icon indicating copy to clipboard operation
QuantLib copied to clipboard

ThirdWednesdayInclusive reported as 'unknown rule' in Schedule firstDate/nextToLastDate validation and catbond stubDate switch

Open leafyoung opened this issue 1 month ago • 1 comments

Summary

DateGeneration::ThirdWednesdayInclusive (added in 2021) is missing from two switch statements, so a valid rule is reported as "unknown rule (4)":

  1. The Schedule constructor validation switches for firstDate and nextToLastDate (ql/time/schedule.cpp, the QL_FAIL("unknown rule (...") arms): a schedule with a firstDate and this rule dies even though the rule is valid.
import QuantLib as ql
ql.Schedule(ql.Date(15,1,2025), ql.Date(15,4,2026), ql.Period('3M'), ql.TARGET(),
            ql.Following, ql.Following, ql.DateGeneration.ThirdWednesdayInclusive,
            False, ql.Date(15,4,2025), ql.Date())
# RuntimeError: unknown rule (4)

Rules that were handled produce the correct behavior (either generate or reject with a rule-specific message).

  1. The stubDate switch in ql/experimental/catbonds/catbond.cpp (default: QL_FAIL("unknown ... rule")): it handles Backward/Forward and rejects Zero/ThirdWednesday/Twentieth with their own messages, but CDS, CDS2015, OldCDS, and ThirdWednesdayInclusive fall to the default arm and are reported as unknown rules.

Mechanism

The 2021 commit that introduced ThirdWednesdayInclusive added the enumerator to the generation switch but not to the validation switches. catbond.cpp predates the new enumerators entirely.

Impact

Functional gap for a public enum value, four years live: valid input rejected with a misleading message. Same species as the historical enum-totality issues (e.g. PR #1974).

Suggested fix

Add ThirdWednesdayInclusive to the firstDate/nextToLastDate validation switches in schedule.cpp (with whatever the intended handling is: either the rule-specific generation path or an explicit incompatibility message), and add CDS/CDS2015/OldCDS/ThirdWednesdayInclusive handling to the catbond.cpp stubDate switch.

Environment

QuantLib-Python 1.44; verified in source at master e429e9f1 (ql/time/schedule.cpp, ql/experimental/catbonds/catbond.cpp).

Found by a formal-verification audit of historical QuantLib PRs; AI-assisted (ZCode/GLM-5.3-flash).

leafyoung avatar Oct 31 '26 00:10 leafyoung

Hi, I'd like to take this one. I have a fix ready and will open a PR shortly.

saanvimundra avatar Oct 31 '26 11:10 saanvimundra