Quick Links:

bal | bbl | bdl | bsl

Namespaces

Component bbldc_calendarbus252
[Package bbldc]

Provide stateless functions for calendar-based BUS-252. More...

Namespaces

namespace  bbldc

Detailed Description

Outline
Purpose:
Provide stateless functions for calendar-based BUS-252.
Classes:
bbldc::CalendarBus252 BUS-252 convention stateless functions
Description:
This component provides a struct, bbldc::CalendarBus252, that serves as a namespace for defining a suite of date-related functions used to compute the day count and the year fraction between two dates as per the BUS-252 day-count convention. In this day-count convention, the day count between two ordered dates, beginDate and endDate where beginDate < endDate, is exactly the number of business days occurring in the time period [beginDate .. endDate). Reversing the order of the dates negates the result. When the two dates have the same value, the day count is 0. The year fraction is the day count divided by 252.
Usage:
This section illustrates intended use of this component.
Example 1: Computing Day Count and Year Fraction:
The following snippets of code illustrate how to use bbldc::CalendarBus252 methods. First, create two bdlt::Date variables, d1 and d2:
  const bdlt::Date d1(2003, 10, 19);
  const bdlt::Date d2(2003, 12, 31);
Then, create a calendar with a valid range spanning 2003 and typical weekend days:
  bdlt::Calendar calendar;
  calendar.setValidRange(bdlt::Date(2003, 1, 1), bdlt::Date(2003, 12, 31));
  calendar.addWeekendDay(bdlt::DayOfWeek::e_SUN);
  calendar.addWeekendDay(bdlt::DayOfWeek::e_SAT);
Next, compute the day count between d1 and d2:
  const int daysDiff = bbldc::CalendarBus252::daysDiff(d1, d2, calendar);
  assert(52 == daysDiff);
Finally, compute the year fraction between the two dates:
  const double yearsDiff = bbldc::CalendarBus252::yearsDiff(d1,
                                                            d2,
                                                            calendar);
  // Need fuzzy comparison since 'yearsDiff' is a 'double'.
  assert(yearsDiff > 0.2063 && yearsDiff < 0.2064);