BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bbldc_basicdaycount.h
Go to the documentation of this file.
1/// @file bbldc_basicdaycount.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bbldc_basicdaycount.h -*-C++-*-
8#ifndef INCLUDED_BBLDC_BASICDAYCOUNT
9#define INCLUDED_BBLDC_BASICDAYCOUNT
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bbldc_basicdaycount bbldc_basicdaycount
15/// @brief Provide a protocol for basic day-count calculations.
16/// @addtogroup bbl
17/// @{
18/// @addtogroup bbldc
19/// @{
20/// @addtogroup bbldc_basicdaycount
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bbldc_basicdaycount-purpose"> Purpose</a>
25/// * <a href="#bbldc_basicdaycount-classes"> Classes </a>
26/// * <a href="#bbldc_basicdaycount-description"> Description </a>
27/// * <a href="#bbldc_basicdaycount-usage"> Usage </a>
28/// * <a href="#bbldc_basicdaycount-example-1-definition-and-use-of-a-concrete-day-count-convention"> Example 1: Definition and Use of a Concrete Day-Count Convention </a>
29///
30/// # Purpose {#bbldc_basicdaycount-purpose}
31/// Provide a protocol for basic day-count calculations.
32///
33/// # Classes {#bbldc_basicdaycount-classes}
34///
35/// - bbldc::BasicDayCount: protocol for basic day-count calculations
36///
37/// @see bbldc_basicbasicdaycountadapter
38///
39/// # Description {#bbldc_basicdaycount-description}
40/// This component provides a protocol, `bbldc::BasicDayCount`, for
41/// implementing an arbitrary day-count convention. Concrete implementations of
42/// this protocol may implement, say, the ISMA 30/360 day-count convention, or a
43/// custom day-count convention appropriate for some niche market.
44///
45/// Several of the components in `bbldc` provide individual day-count convention
46/// support through interfaces that are functionally identical to the abstract
47/// interface provided by this component, except that they do not inherit from
48/// `bbldc::BasicDayCount`. In conjunction with the adapter components (e.g.,
49/// @ref bbldc_basicbasicdaycountadapter ), `bbldc::BasicDayCount` is intended to
50/// allow run-time binding of these and other similar day-count implementations.
51///
52/// ## Usage {#bbldc_basicdaycount-usage}
53///
54///
55/// This section illustrates intended use of this component.
56///
57/// ### Example 1: Definition and Use of a Concrete Day-Count Convention {#bbldc_basicdaycount-example-1-definition-and-use-of-a-concrete-day-count-convention}
58///
59///
60/// This example shows the definition and use of a simple concrete day-count
61/// convention. This functionality suffices to demonstrate the requisite steps
62/// for having a working day-count convention:
63/// * Define a concrete day-count type derived from `bbldc::BasicDayCount`.
64/// * Implement the pure virtual `daysDiff` and `yearsDiff` methods.
65/// * Instantiate and use an object of the concrete type.
66///
67/// First, define the (derived) `my_DayCountConvention` class and implement its
68/// constructor inline (for convenience, directly within the derived-class
69/// definition):
70/// @code
71/// // my_daycountconvention.h
72///
73/// class my_DayCountConvention : public bbldc::BasicDayCount {
74/// public:
75/// my_DayCountConvention() { }
76/// virtual ~my_DayCountConvention();
77/// virtual int daysDiff(const bdlt::Date& beginDate,
78/// const bdlt::Date& endDate) const;
79/// // Return the (signed) number of days between the specified ...
80/// virtual double yearsDiff(const bdlt::Date& beginDate,
81/// const bdlt::Date& endDate) const;
82/// // Return the (signed fractional) number of years between the ...
83/// };
84/// @endcode
85/// Then, implement the destructor. Note, however, that we always implement a
86/// virtual destructor (non-inline) in the .cpp file (to indicate the *unique*
87/// location of the class's virtual table):
88/// @code
89/// // my_daycountconvention.cpp
90///
91/// // ...
92///
93/// my_DayCountConvention::~my_DayCountConvention() { }
94/// @endcode
95/// Next, we implement the (virtual) `daysDiff` and `yearsDiff` methods, which
96/// incorporate the "policy" of what it means for this day-count convention to
97/// calculate day count and year fraction:
98/// @code
99/// int my_DayCountConvention::daysDiff(const bdlt::Date& beginDate,
100/// const bdlt::Date& endDate) const
101/// {
102/// return endDate - beginDate;
103/// }
104///
105/// double my_DayCountConvention::yearsDiff(const bdlt::Date& beginDate,
106/// const bdlt::Date& endDate) const
107/// {
108/// return static_cast<double>((endDate - beginDate) / 365.0);
109/// }
110/// @endcode
111/// Then, create two `bdlt::Date` variables, `d1` and `d2`, to use with the
112/// `my_DayCountConvention` object and its day-count convention methods:
113/// @code
114/// const bdlt::Date d1(2003, 10, 19);
115/// const bdlt::Date d2(2003, 12, 31);
116/// @endcode
117/// Next, we obtain a `bbldc::BasicDayCount` reference from an instantiated
118/// `my_DayCountConvention`:
119/// @code
120/// my_DayCountConvention myDcc;
121/// const bbldc::BasicDayCount& dcc = myDcc;
122/// @endcode
123/// Now, we compute the day count between the two dates:
124/// @code
125/// const int daysDiff = dcc.daysDiff(d1, d2);
126/// assert(73 == daysDiff);
127/// @endcode
128/// Finally, we compute the year fraction between the two dates:
129/// @code
130/// const double yearsDiff = dcc.yearsDiff(d1, d2);
131/// // Need fuzzy comparison since 'yearsDiff' is a 'double'.
132/// assert(0.1999 < yearsDiff && 0.2001 > yearsDiff);
133/// @endcode
134/// @}
135/** @} */
136/** @} */
137
138/** @addtogroup bbl
139 * @{
140 */
141/** @addtogroup bbldc
142 * @{
143 */
144/** @addtogroup bbldc_basicdaycount
145 * @{
146 */
147
148#include <bblscm_version.h>
149
150#include <bdlt_date.h>
151
152
153namespace bbldc {
154
155 // ===================
156 // class BasicDayCount
157 // ===================
158
159/// This `class` provides a protocol for determining values based on dates
160/// according to derived implementations of specific day-count conventions.
161///
162/// See @ref bbldc_basicdaycount
164
165 public:
166 // CREATORS
167
168 /// Destroy this object.
169 virtual ~BasicDayCount();
170
171 // ACCESSORS
172
173 /// Return the (signed) number of days between the specified `beginDate`
174 /// and `endDate`. If `beginDate <= endDate`, then the result is
175 /// non-negative. Note that reversing the order of `beginDate` and
176 /// `endDate` negates the result.
177 virtual int daysDiff(const bdlt::Date& beginDate,
178 const bdlt::Date& endDate) const = 0;
179
180 /// Return the (signed fractional) number of years between the specified
181 /// `beginDate` and `endDate`. If `beginDate <= endDate`, then the
182 /// result is non-negative. Note that reversing the order of
183 /// `beginDate` and `endDate` negates the result; specifically,
184 /// `|yearsDiff(b, e) + yearsDiff(e, b)| <= 1.0e-15` for all dates `b`
185 /// and `e`.
186 virtual double yearsDiff(const bdlt::Date& beginDate,
187 const bdlt::Date& endDate) const = 0;
188};
189
190} // close package namespace
191
192
193#endif
194
195// ----------------------------------------------------------------------------
196// Copyright 2015 Bloomberg Finance L.P.
197//
198// Licensed under the Apache License, Version 2.0 (the "License");
199// you may not use this file except in compliance with the License.
200// You may obtain a copy of the License at
201//
202// http://www.apache.org/licenses/LICENSE-2.0
203//
204// Unless required by applicable law or agreed to in writing, software
205// distributed under the License is distributed on an "AS IS" BASIS,
206// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
207// See the License for the specific language governing permissions and
208// limitations under the License.
209// ----------------------------- END-OF-FILE ----------------------------------
210
211/** @} */
212/** @} */
213/** @} */
Definition bbldc_basicdaycount.h:163
virtual int daysDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate) const =0
virtual ~BasicDayCount()
Destroy this object.
virtual double yearsDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate) const =0
Definition bdlt_date.h:294
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bbldc_basicactual360.h:107