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

Detailed Description

Outline

Purpose

Provide stateless functions for calendar-based BUS-252.

Classes

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);
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

Next, compute the day count between d1 and d2:

const int daysDiff = bbldc::CalendarBus252::daysDiff(d1, d2, calendar);
assert(52 == daysDiff);
static int daysDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate, const bdlt::Calendar &calendar)
Definition bbldc_calendarbus252.h:156

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);
static double yearsDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate, const bdlt::Calendar &calendar)
Definition bbldc_calendarbus252.h:173