BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bbldc_terminatedbasicdaycountadapter.h
Go to the documentation of this file.
1/// @file bbldc_terminatedbasicdaycountadapter.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bbldc_terminatedbasicdaycountadapter.h -*-C++-*-
8#ifndef INCLUDED_BBLDC_TERMINATEDBASICDAYCOUNTADAPTER
9#define INCLUDED_BBLDC_TERMINATEDBASICDAYCOUNTADAPTER
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bbldc_terminatedbasicdaycountadapter bbldc_terminatedbasicdaycountadapter
15/// @brief Provide a parameterized day-count convention implementation.
16/// @addtogroup bbl
17/// @{
18/// @addtogroup bbldc
19/// @{
20/// @addtogroup bbldc_terminatedbasicdaycountadapter
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bbldc_terminatedbasicdaycountadapter-purpose"> Purpose</a>
25/// * <a href="#bbldc_terminatedbasicdaycountadapter-classes"> Classes </a>
26/// * <a href="#bbldc_terminatedbasicdaycountadapter-description"> Description </a>
27/// * <a href="#bbldc_terminatedbasicdaycountadapter-usage"> Usage </a>
28/// * <a href="#bbldc_terminatedbasicdaycountadapter-example-1-adapting-bbldc-terminatedisda30360eom"> Example 1: Adapting bbldc::TerminatedIsda30360Eom </a>
29///
30/// # Purpose {#bbldc_terminatedbasicdaycountadapter-purpose}
31/// Provide a parameterized day-count convention implementation.
32///
33/// # Classes {#bbldc_terminatedbasicdaycountadapter-classes}
34///
35/// - bbldc::TerminatedBasicDayCountAdapter: `bbldc::BasicDayCount` realization
36///
37/// # Description {#bbldc_terminatedbasicdaycountadapter-description}
38/// This component provides a parameterized (template)
39/// implementation, `bbldc::TerminatedBasicDayCountAdapter`, of the
40/// `bbldc::BasicDayCount` protocol that allows for special handling of a
41/// termination date (e.g., maturity date). The template argument can be any
42/// type supporting the following two class methods.
43/// @code
44/// int daysDiff(const bdlt::Date& beginDate,
45/// const bdlt::Date& endDate,
46/// const bdlt::Date& terminationDate);
47///
48/// double yearsDiff(const bdlt::Date& beginDate,
49/// const bdlt::Date& endDate,
50/// const bdlt::Date& terminationDate);
51/// @endcode
52/// The template class `bbldc::TerminatedBasicDayCountAdapter` provides
53/// convenient support for run-time polymorphic choice of day-count conventions
54/// (via conventional use of a base-class pointer or reference) without having
55/// to implement each derived type explicitly. In this sense,
56/// `bbldc::TerminatedBasicDayCountAdapter` adapts the various concrete
57/// "terminated" day-count convention classes (e.g.,
58/// `bbldc::TerminatedIsda30360Eom`) to a run-time binding mechanism.
59///
60/// ## Usage {#bbldc_terminatedbasicdaycountadapter-usage}
61///
62///
63/// This section illustrates intended use of this component.
64///
65/// ### Example 1: Adapting bbldc::TerminatedIsda30360Eom {#bbldc_terminatedbasicdaycountadapter-example-1-adapting-bbldc-terminatedisda30360eom}
66///
67///
68/// This example shows the procedure for using
69/// `bbldc::TerminatedBasicDayCountAdapter` to adapt the
70/// `bbldc::TerminatedIsda30360Eom` day-count convention to the
71/// `bbldc::BasicDayCount` protocol, and then the use of the day-count methods.
72///
73/// First, we define an instance of the adapted `bbldc::TerminatedIsda30360Eom`
74/// day-count convention and obtain a reference to the `bbldc::BasicDayCount`:
75/// @code
76/// const bbldc::TerminatedBasicDayCountAdapter<bbldc::TerminatedIsda30360Eom>
77/// myDcc(bdlt::Date(2004, 2, 29));
78/// const bbldc::BasicDayCount& dcc = myDcc;
79/// @endcode
80/// Then, create two `bdlt::Date` variables, `d1` and `d2`, with which to use
81/// the day-count convention methods:
82/// @code
83/// const bdlt::Date d1(2003, 10, 18);
84/// const bdlt::Date d2(2003, 12, 31);
85/// @endcode
86/// Now, use the base-class reference to compute the day count between the two
87/// dates:
88/// @code
89/// const int daysDiff = dcc.daysDiff(d1, d2);
90/// assert(72 == daysDiff);
91/// @endcode
92/// Finally, use the base-class reference to compute the year fraction between
93/// the two dates:
94/// @code
95/// const double yearsDiff = dcc.yearsDiff(d1, d2);
96/// // Need fuzzy comparison since 'yearsDiff' is a 'double'.
97/// assert(0.1999 < yearsDiff && 0.2001 > yearsDiff);
98/// @endcode
99/// @}
100/** @} */
101/** @} */
102
103/** @addtogroup bbl
104 * @{
105 */
106/** @addtogroup bbldc
107 * @{
108 */
109/** @addtogroup bbldc_terminatedbasicdaycountadapter
110 * @{
111 */
112
113#include <bblscm_version.h>
114
115#include <bbldc_basicdaycount.h>
116
117#include <bdlt_date.h>
118
119#include <bsls_keyword.h>
120
121
122namespace bbldc {
123
124 // ====================================
125 // class TerminatedBasicDayCountAdapter
126 // ====================================
127
128/// This `class` provides an "adapter" from the specified `CONVENTION` to
129/// the `bbldc::BasicDayCount` protocol that can be used for determining
130/// values based on dates according to the day-count `CONVENTION`.
131///
132/// See @ref bbldc_terminatedbasicdaycountadapter
133template <class CONVENTION>
135
136 // DATA
137 bdlt::Date d_terminationDate; // termination date used in all calculations
138
139 private:
140 // NOT IMPLEMENTED
144
145 public:
146 // CREATORS
147
148 /// Create a day-count adapter that uses the specified `terminationDate`
149 /// during.
150 TerminatedBasicDayCountAdapter(const bdlt::Date& terminationDate);
151
152 /// Destroy this object.
154
155 // ACCESSORS
156 int daysDiff(const bdlt::Date& beginDate, const bdlt::Date& endDate) const
158 // Return the (signed) number of days between the specified 'beginDate'
159 // and 'endDate' as per the 'CONVENTION' template policy. If
160 // 'beginDate <= endDate', then the result is non-negative. Note that
161 // reversing the order of 'beginDate' and 'endDate' negates the result.
162
163 /// Return the (signed fractional) number of years between the specified
164 /// `beginDate` and `endDate` as per the `CONVENTION` template policy.
165 /// If `beginDate <= endDate`, then the result is non-negative. Note
166 /// that reversing the order of `beginDate` and `endDate` negates the
167 /// result; specifically,
168 /// `|yearsDiff(b, e) + yearsDiff(e, b)| <= 1.0e-15` for all dates `b`
169 /// and `e`.
170 double yearsDiff(const bdlt::Date& beginDate,
171 const bdlt::Date& endDate) const BSLS_KEYWORD_OVERRIDE;
172};
173
174// ============================================================================
175// INLINE DEFINITIONS
176// ============================================================================
177
178 // ------------------------------------
179 // class TerminatedBasicDayCountAdapter
180 // ------------------------------------
181
182// CREATORS
183template <class CONVENTION>
184inline
186 TerminatedBasicDayCountAdapter(const bdlt::Date& terminationDate)
187: d_terminationDate(terminationDate)
188{
189}
190
191template <class CONVENTION>
192inline
196
197// ACCESSORS
198template <class CONVENTION>
199inline
201 const bdlt::Date& beginDate,
202 const bdlt::Date& endDate) const
203{
204 return CONVENTION::daysDiff(beginDate, endDate, d_terminationDate);
205}
206
207template <class CONVENTION>
208inline
209double
211 const bdlt::Date& beginDate,
212 const bdlt::Date& endDate) const
213{
214 return CONVENTION::yearsDiff(beginDate, endDate, d_terminationDate);
215}
216
217} // close package namespace
218
219
220#endif
221
222// ----------------------------------------------------------------------------
223// Copyright 2016 Bloomberg Finance L.P.
224//
225// Licensed under the Apache License, Version 2.0 (the "License");
226// you may not use this file except in compliance with the License.
227// You may obtain a copy of the License at
228//
229// http://www.apache.org/licenses/LICENSE-2.0
230//
231// Unless required by applicable law or agreed to in writing, software
232// distributed under the License is distributed on an "AS IS" BASIS,
233// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
234// See the License for the specific language governing permissions and
235// limitations under the License.
236// ----------------------------- END-OF-FILE ----------------------------------
237
238/** @} */
239/** @} */
240/** @} */
Definition bbldc_basicdaycount.h:163
Definition bbldc_terminatedbasicdaycountadapter.h:134
int daysDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate) const BSLS_KEYWORD_OVERRIDE
Definition bbldc_terminatedbasicdaycountadapter.h:200
~TerminatedBasicDayCountAdapter() BSLS_KEYWORD_OVERRIDE
Destroy this object.
Definition bbldc_terminatedbasicdaycountadapter.h:193
double yearsDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate) const BSLS_KEYWORD_OVERRIDE
Definition bbldc_terminatedbasicdaycountadapter.h:210
Definition bdlt_date.h:294
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_OVERRIDE
Definition bsls_keyword.h:653
Definition bbldc_basicactual360.h:107