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

Detailed Description

Outline

Purpose

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

Classes

See also
bbldc_daycountconvention, bbldc_periodicmaactualactual

Description

This component provides a struct, bbldc::PeriodDayCountUtil, 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::PeriodDayCountUtil take a trailing DayCountConvention::Enum argument indicating which particular period-based 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::PeriodDayCountUtil 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 schedule of period dates, sched, corresponding to a quarterly payment (periodYearDiff == 0.25):

sched.push_back(bdlt::Date(2003, 10, 1));
sched.push_back(bdlt::Date(2004, 1, 1));
Definition bslstl_vector.h:1025
void push_back(const VALUE_TYPE &value)
Definition bslstl_vector.h:3760

Now, compute the day count between d1 and d2 according to the ICMA Actual/Actual day-count convention:

d1,
d2,
assert(73 == daysDiff);
@ e_PERIOD_ICMA_ACTUAL_ACTUAL
Definition bbldc_daycountconvention.h:143
static int daysDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate, DayCountConvention::Enum convention)

Finally, compute the year fraction between the two dates according to the ICMA Actual/Actual day-count convention:

const double yearsDiff = bbldc::PeriodDayCountUtil::yearsDiff(
d1,
d2,
sched,
0.25,
// Need fuzzy comparison since 'yearsDiff' is a 'double'.
assert(yearsDiff > 0.1983 && yearsDiff < 0.1985);
static double yearsDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate, const bsl::vector< bdlt::Date > &periodDate, double periodYearDiff, DayCountConvention::Enum convention)
Definition bbldc_perioddaycountutil.h:215