Provide a parameterized day-count convention implementation.
More...
Namespaces |
namespace | bbldc |
Detailed Description
- Outline
-
-
- Purpose:
- Provide a parameterized day-count convention implementation.
-
- Classes:
-
-
- Description:
- This component provides a parameterized (template) implementation,
bbldc::PeriodDateRangeDayCountAdapter
, of the bbldc::DateRangeDayCount
protocol. The template argument can be any type supporting the following two class methods. The template class bbldc::PeriodDateRangeDayCountAdapter
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::PeriodDateRangeDayCountAdapter
adapts the various concrete period-based day-count convention classes (e.g., bbldc::PeriodIcmaActualActual
) to a run-time binding mechanism.
- The
bbldc::DateRangeDayCount
protocol requires two methods, firstDate
and lastDate
, that define a date range for which calculations are valid, to reflect the valid range of, say, a calendar required for the computations. For "period" day-count implementations, the valid date range is from the first to the last period date.
-
- Usage:
- This section illustrates intended use of this component.
-
- Example 1: Adapting bbldc::PeriodIcmaActualActual:
- This example shows the procedure for using
bbldc::PeriodDateRangeDayCountAdapter
to adapt the bbldc::PeriodIcmaActualActual
day-count convention to the bbldc::DateRangeDayCount
protocol, and then the use of the day-count methods. First, we create a schedule of period dates, sched
, corresponding to a quarterly payment (periodYearDiff == 0.25
): Then, we define an instance of the adapted day-count convention and obtain a reference to the bbldc::DateRangeDayCount
: Next, create two bdlt::Date
variables, d1
and d2
, with which to use the day-count convention methods: Now, use the base-class reference to compute the day count between the two dates: const int daysDiff = dcc.daysDiff(d1, d2);
assert(73 == daysDiff);
Finally, use the base-class reference to compute the year fraction between the two dates: const double yearsDiff = dcc.yearsDiff(d1, d2);
assert(yearsDiff > 0.1983 && yearsDiff < 0.1985);