BDE 4.14.0 Production release
|
Provide a protocol for basic day-count calculations.
This component provides a protocol, bbldc::BasicDayCount
, for implementing an arbitrary day-count convention. Concrete implementations of this protocol may implement, say, the ISMA 30/360 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::BasicDayCount
. In conjunction with the adapter components (e.g., bbldc_basicbasicdaycountadapter ), bbldc::BasicDayCount
is intended to allow run-time binding of these and other similar day-count implementations.
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::BasicDayCount
.daysDiff
and yearsDiff
methods.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
and yearsDiff
methods, which incorporate the "policy" of what it means for this day-count convention to calculate day count and year fraction:
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::BasicDayCount
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: