BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bbldc_calendardaycountutil

Detailed Description

Outline

Purpose

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

Classes

See also
bbldc_daycountconvention, 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);
Definition bdlt_date.h:294

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));
Definition bdlt_calendar.h:569
void addWeekendDay(DayOfWeek::Enum weekendDay)
void setValidRange(const Date &firstDate, const Date &lastDate)
Definition bdlt_calendar.h:1588
@ e_SUN
Definition bdlt_dayofweek.h:125
@ e_SAT
Definition bdlt_dayofweek.h:131

Now, compute the day count between d1 and d2 according to the BUS-252 day-count convention:

d1,
d2,
calendar,
assert(52 == daysDiff);
static int daysDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate, const bdlt::Calendar &calendar, DayCountConvention::Enum convention)
@ e_CALENDAR_BUS_252
Definition bbldc_daycountconvention.h:144

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,
// Need fuzzy comparison since 'yearsDiff' is a 'double'.
assert(0.2063 < yearsDiff && 0.2064 > yearsDiff);
static double yearsDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate, const bdlt::Calendar &calendar, DayCountConvention::Enum convention)