Counting Business Days with a Financial Calendar
Summary
The document distinguishes calendar-based business-day counts from bond day-count conventions such as Thirty/360. A day-count convention measures time for purposes such as coupon calculations; it does not, by itself, use a market calendar to exclude weekends and holidays. When the goal is instead to count working days between two dates, the relevant method is a business calendar’s business-day counting function.
The example uses QuantLib’s TARGET calendar to count business days between two specified dates and reports a result of 62. This demonstrates how the selected calendar incorporates its business-day rules, including applicable holidays. The result depends on the calendar and the method’s endpoint settings, so users should choose the market calendar that matches their instrument or workflow and check whether the start and end dates are included. The document is a concise usage example; it does not compare calendars or explain alternative date-counting conventions.
Key ideas
- Business-day counts and bond day-count conventions answer different questions.
- A financial calendar can count business days between two dates while accounting for its holiday rules.
- The example uses QuantLib’s TARGET calendar and reports a count of 62 business days.
- The chosen calendar and endpoint inclusion settings affect how a count should be interpreted.
Tags
Full text
# Number of days between two dates based on a given a calendar # Number of days between two dates based on a given a calendar I wanted to calculate the number of trading days between 2 given days. There is a discussion in https://stackoverflow.com/questions/62292979/using-quantlib-in-python-how-do-i-get-the-number-of-days-between-two-dates. However this considers the day-count convention from the Bond coupon's calculation perspective using something `Thirty360()`. However I wonder why we dont consider a calendar for such calculation? Is there any way to consider the holiday information as well in the day-count calculation? ## Answer by David Duarte (score 3, accepted) https://quant.stackexchange.com/a/58097 If you want the number of business days acording to a calendar, you can use the `businessDaysBetween` method from the calendar object, like this: ``` import QuantLib as ql d1 = ql.Date(15,3,2020) d2 = ql.Date(15,6,2020) cal = ql.TARGET() days = cal.businessDaysBetween(d1, d2) print(days) ``` 62
Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.