BDE 4.14.0 Production release
|
Provide a protocol for date-range limited day-count calculations.
This component provides a protocol, bbldc::DateRangeDayCount
, for implementing an arbitrary day-count convention. Concrete implementations of this protocol may implement, say, the BUS-252 day-count convention, or a custom day-count convention appropriate for some niche market.
Several of the components in bbldc
provide individual day-count convention support through interfaces that are functionally identical to the abstract interface provided by this component, except that they do not inherit from bbldc::DateRangeDayCount
. In conjunction with the adapter components (e.g., bbldc_basicdaterangedaycountadapter ), bbldc::DateRangeDayCount
is intended to allow run-time binding of these and other similar day-count implementations.
This 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.
This section illustrates intended use of this component.
This example shows the definition and use of a simple concrete day-count convention. This functionality suffices to demonstrate the requisite steps for having a working day-count convention:
bbldc::DateRangeDayCount
.First, define the (derived) my_DayCountConvention
class and implement its constructor inline (for convenience, directly within the derived-class definition):
Then, implement the destructor. Note, however, that we always implement a virtual destructor (non-inline) in the .cpp file (to indicate the unique location of the class's virtual table):
Next, we implement the (virtual) daysDiff
, firstDate
, lastDate
, and yearsDiff
methods, which incorporate the "policy" of what it means for this day-count convention to calculate day count, year fraction, and the valid range of the convention instance:
Then, create two bdlt::Date
variables, d1
and d2
, to use with the my_DayCountConvention
object and its day-count convention methods:
Next, we obtain a bbldc::DateRangeDayCount
reference from an instantiated my_DayCountConvention
:
Now, we compute the day count between the two dates:
Finally, we compute the year fraction between the two dates: