Quick Links:

bal | bbl | bdl | bsl

Namespaces

Component bbldc_calendardaycountutil
[Package bbldc]

Support for day-count calculations of enum-specified conventions. More...

Namespaces

namespace  bbldc

Detailed Description

Outline
Purpose:
Support for day-count calculations of enum-specified conventions.
Classes:
bbldc::CalendarDayCountUtil enum-specified day-count calculations
See also:
Component bbldc_daycountconvention, Component bbldc_calendarbus252
Description:
This component provides a struct, bbldc::CalendarDayCountUtil, that defines a suite of date-related functions used to compute the day count and the year fraction between two dates as prescribed by an enumerated day-count convention. Specifically, the daysDiff and yearsDiff methods defined in bbldc::CalendarDayCountUtil take a trailing DayCountConvention::Enum argument indicating which particular day-count convention to apply.
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::CalendarDayCountUtil 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);
Now, compute the day count between d1 and d2 according to the BUS-252 day-count convention:
  const int daysDiff = bbldc::CalendarDayCountUtil::daysDiff(
                              d1,
                              d2,
                              calendar,
                              bbldc::DayCountConvention::e_CALENDAR_BUS_252);
  assert(52 == daysDiff);
Finally, compute the year fraction between the two dates according to the BUS-252 day-count convention:
  const double yearsDiff = bbldc::CalendarDayCountUtil::yearsDiff(
                              d1,
                              d2,
                              calendar,
                              bbldc::DayCountConvention::e_CALENDAR_BUS_252);
  // Need fuzzy comparison since 'yearsDiff' is a 'double'.
  assert(0.2063 < yearsDiff && 0.2064 > yearsDiff);