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

Detailed Description

Outline

Purpose

Provide a parameterized day-count convention implementation.

Classes

Description

This component provides a parameterized (template) implementation, bbldc::BasicBasicDayCountAdapter, of the bbldc::BasicDayCount protocol. The template argument can be any type supporting the following two class methods.

int daysDiff(const bdlt::Date& beginDate, const bdlt::Date& endDate);
double yearsDiff(const bdlt::Date& beginDate, const bdlt::Date& endDate);
Definition bdlt_date.h:294

The template class bbldc::BasicBasicDayCountAdapter provides convenient support for run-time polymorphic choice of day-count conventions (via conventional use of a base-class pointer or reference) without having to implement each derived type explicitly. In this sense, bbldc::BasicBasicDayCountAdapter adapts the various concrete "basic" day-count convention classes (e.g., bbldc::BasicIsma30360) to a run-time binding mechanism.

Usage

This section illustrates intended use of this component.

Example 1: Adapting bbldc::BasicIsma30360

This example shows the procedure for using bbldc::BasicBasicDayCountAdapter to adapt the bbldc::BasicIsma30360 day-count convention to the bbldc::BasicDayCount protocol, and then the use of the day-count methods. First, we define an instance of the adapted day-count convention and obtain a reference to the bbldc::BasicDayCount:

const bbldc::BasicDayCount& dcc = myDcc;
Definition bbldc_basicbasicdaycountadapter.h:129
Definition bbldc_basicdaycount.h:163

Then, create two bdlt::Date variables, d1 and d2, with which to use the day-count convention methods:

const bdlt::Date d1(2003, 10, 18);
const bdlt::Date d2(2003, 12, 31);

Now, use the base-class reference to compute the day count between the two dates:

const int daysDiff = dcc.daysDiff(d1, d2);
assert(72 == daysDiff);
virtual int daysDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate) const =0

Finally, use the base-class reference to compute the year fraction between the two dates:

const double yearsDiff = dcc.yearsDiff(d1, d2);
// Need fuzzy comparison since 'yearsDiff' is a 'double'.
assert(0.1999 < yearsDiff && 0.2001 > yearsDiff);
virtual double yearsDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate) const =0