BDE 4.39.x 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///
78/// /// Return the (signed) number of days between the specified ...
79/// virtual int daysDiff(const bdlt::Date& beginDate,
80/// const bdlt::Date& endDate) const;
81///
82/// /// Return the (signed fractional) number of years between the ...
83/// virtual double yearsDiff(const bdlt::Date& beginDate,
84/// const bdlt::Date& endDate) const;
85/// };
86/// @endcode
87/// Then, implement the destructor. Note, however, that we always implement a
88/// virtual destructor (non-inline) in the .cpp file (to indicate the *unique*
89/// location of the class's virtual table):
90/// @code
91/// // my_daycountconvention.cpp
92///
93/// // ...
94///
95/// my_DayCountConvention::~my_DayCountConvention() { }
96/// @endcode
97/// Next, we implement the (virtual) `daysDiff` and `yearsDiff` methods, which
98/// incorporate the "policy" of what it means for this day-count convention to
99/// calculate day count and year fraction:
100/// @code
101/// int my_DayCountConvention::daysDiff(const bdlt::Date& beginDate,
102/// const bdlt::Date& endDate) const
103/// {
104/// return endDate - beginDate;
105/// }
106///
107/// double my_DayCountConvention::yearsDiff(const bdlt::Date& beginDate,
108/// const bdlt::Date& endDate) const
109/// {
110/// return static_cast<double>((endDate - beginDate) / 365.0);
111/// }
112/// @endcode
113/// Then, create two `bdlt::Date` variables, `d1` and `d2`, to use with the
114/// `my_DayCountConvention` object and its day-count convention methods:
115/// @code
116/// const bdlt::Date d1(2003, 10, 19);
117/// const bdlt::Date d2(2003, 12, 31);
118/// @endcode
119/// Next, we obtain a `bbldc::BasicDayCount` reference from an instantiated
120/// `my_DayCountConvention`:
121/// @code
122/// my_DayCountConvention myDcc;
123/// const bbldc::BasicDayCount& dcc = myDcc;
124/// @endcode
125/// Now, we compute the day count between the two dates:
126/// @code
127/// const int daysDiff = dcc.daysDiff(d1, d2);
128/// assert(73 == daysDiff);
129/// @endcode
130/// Finally, we compute the year fraction between the two dates:
131/// @code
132/// const double yearsDiff = dcc.yearsDiff(d1, d2);
133/// // Need fuzzy comparison since 'yearsDiff' is a 'double'.
134/// assert(0.1999 < yearsDiff && 0.2001 > yearsDiff);
135/// @endcode
136/// @}
137/** @} */
138/** @} */
139
140/** @addtogroup bbl
141 * @{
142 */
143/** @addtogroup bbldc
144 * @{
145 */
146/** @addtogroup bbldc_basicdaycount
147 * @{
148 */
149
150#include <bblscm_version.h>
151
152#include <bdlt_date.h>
153
154
155namespace bbldc {
156
157 // ===================
158 // class BasicDayCount
159 // ===================
160
161/// This `class` provides a protocol for determining values based on dates
162/// according to derived implementations of specific day-count conventions.
163///
164/// See @ref bbldc_basicdaycount
166
167 public:
168 // CREATORS
169
170 /// Destroy this object.
171 virtual ~BasicDayCount();
172
173 // ACCESSORS
174
175 /// Return the (signed) number of days between the specified `beginDate`
176 /// and `endDate`. If `beginDate <= endDate`, then the result is non-negative.
177 ///
178 /// \note Note that reversing the order of `beginDate` and
179 /// `endDate` negates the result.
180 virtual int daysDiff(const bdlt::Date& beginDate,
181 const bdlt::Date& endDate) const = 0;
182
183 /// Return the (signed fractional) number of years between the specified
184 /// `beginDate` and `endDate`. If `beginDate <= endDate`, then the result is non-negative.
185 ///
186 /// \note Note that reversing the order of
187 /// `beginDate` and `endDate` negates the result; specifically,
188 /// `|yearsDiff(b, e) + yearsDiff(e, b)| <= 1.0e-15` for all dates `b`
189 /// and `e`.
190 virtual double yearsDiff(const bdlt::Date& beginDate,
191 const bdlt::Date& endDate) const = 0;
192};
193
194} // close package namespace
195
196
197#endif
198
199// ----------------------------------------------------------------------------
200// Copyright 2015 Bloomberg Finance L.P.
201//
202// Licensed under the Apache License, Version 2.0 (the "License");
203// you may not use this file except in compliance with the License.
204// You may obtain a copy of the License at
205//
206// http://www.apache.org/licenses/LICENSE-2.0
207//
208// Unless required by applicable law or agreed to in writing, software
209// distributed under the License is distributed on an "AS IS" BASIS,
210// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
211// See the License for the specific language governing permissions and
212// limitations under the License.
213// ----------------------------- END-OF-FILE ----------------------------------
214
215/** @} */
216/** @} */
217/** @} */
Definition bbldc_basicdaycount.h:165
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)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bbldc_basicactual360.h:107