BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bbldc_basicactual360.h
Go to the documentation of this file.
1/// @file bbldc_basicactual360.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bbldc_basicactual360.h -*-C++-*-
8#ifndef INCLUDED_BBLDC_BASICACTUAL360
9#define INCLUDED_BBLDC_BASICACTUAL360
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bbldc_basicactual360 bbldc_basicactual360
15/// @brief Provide stateless functions for the Actual/360 convention.
16/// @addtogroup bbl
17/// @{
18/// @addtogroup bbldc
19/// @{
20/// @addtogroup bbldc_basicactual360
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bbldc_basicactual360-purpose"> Purpose</a>
25/// * <a href="#bbldc_basicactual360-classes"> Classes </a>
26/// * <a href="#bbldc_basicactual360-description"> Description </a>
27/// * <a href="#bbldc_basicactual360-usage"> Usage </a>
28/// * <a href="#bbldc_basicactual360-example-1-computing-day-count-and-year-fraction"> Example 1: Computing Day Count and Year Fraction </a>
29///
30/// # Purpose {#bbldc_basicactual360-purpose}
31/// Provide stateless functions for the Actual/360 convention.
32///
33/// # Classes {#bbldc_basicactual360-classes}
34///
35/// - bbldc::BasicActual360: Actual/360 convention stateless functions
36///
37/// # Description {#bbldc_basicactual360-description}
38/// This component provides a `struct`, `bbldc::BasicActual360`,
39/// that serves as a namespace for defining a suite of date-related functions
40/// used to compute the day count and the year fraction between two dates as per
41/// the Actual/360 day-count convention. In this day-count convention, we
42/// simply measure the number of days occurring in a time period, and to
43/// calculate years, divide that by 360. Note that this means the number of
44/// years between January 1, 2005 and January 1, 2006 is about 1.0139. No
45/// end-of-month rule adjustments are made. Given `beginDate` and `endDate`:
46/// @code
47/// yearsDiff ::= sign(endDate - beginDate) *
48/// (days between beginDate and endDate) / 360.0
49/// @endcode
50///
51/// ## Usage {#bbldc_basicactual360-usage}
52///
53///
54/// This section illustrates intended use of this component.
55///
56/// ### Example 1: Computing Day Count and Year Fraction {#bbldc_basicactual360-example-1-computing-day-count-and-year-fraction}
57///
58///
59/// The following snippets of code illustrate how to use `bbldc::BasicActual360`
60/// methods. First, create four `bdlt::Date` variables:
61/// @code
62/// const bdlt::Date dA(2004, 2, 1);
63/// const bdlt::Date dB(2004, 3, 1);
64/// const bdlt::Date dC(2004, 5, 1);
65/// const bdlt::Date dD(2005, 2, 1);
66/// @endcode
67/// Then, compute the day count between some pairs of these dates:
68/// @code
69/// int daysDiff;
70/// daysDiff = bbldc::BasicActual360::daysDiff(dA, dB);
71/// assert( 29 == daysDiff);
72/// daysDiff = bbldc::BasicActual360::daysDiff(dA, dC);
73/// assert( 90 == daysDiff);
74/// daysDiff = bbldc::BasicActual360::daysDiff(dA, dD);
75/// assert(366 == daysDiff);
76/// daysDiff = bbldc::BasicActual360::daysDiff(dB, dC);
77/// assert( 61 == daysDiff);
78/// @endcode
79/// Finally, compute the year fraction between some of the dates:
80/// @code
81/// double yearsDiff;
82/// yearsDiff = bbldc::BasicActual360::yearsDiff(dA, dC);
83/// assert(0.25 == yearsDiff);
84/// yearsDiff = bbldc::BasicActual360::yearsDiff(dA, dD);
85/// // Need fuzzy comparison since 'yearsDiff' is a 'double'.
86/// assert(yearsDiff < 1.0167 && yearsDiff > 1.0166);
87/// @endcode
88/// @}
89/** @} */
90/** @} */
91
92/** @addtogroup bbl
93 * @{
94 */
95/** @addtogroup bbldc
96 * @{
97 */
98/** @addtogroup bbldc_basicactual360
99 * @{
100 */
101
102#include <bblscm_version.h>
103
104#include <bdlt_date.h>
105
106
107namespace bbldc {
108
109 // =====================
110 // struct BasicActual360
111 // =====================
112
113/// This `struct` provides a namespace for a suite of pure functions that
114/// compute values based on dates according to the Actual/360 day-count
115/// convention.
117
118 // CLASS METHODS
119
120 /// Return the (signed) number of days between the specified `beginDate`
121 /// and `endDate` according to the Actual/360 day-count convention. If
122 /// `beginDate <= endDate` then the result is non-negative. Note that
123 /// reversing the order of `beginDate` and `endDate` negates the result.
124 static int daysDiff(const bdlt::Date& beginDate,
125 const bdlt::Date& endDate);
126
127 /// Return the (signed fractional) number of years between the specified
128 /// `beginDate` and `endDate` according to the Actual/360 day-count
129 /// convention. If `beginDate <= endDate` then the result is
130 /// non-negative. Note that reversing the order of `beginDate` and
131 /// `endDate` negates the result; specifically,
132 /// `|yearsDiff(b, e) + yearsDiff(e, b)| <= 1.0e-15` for all dates `b`
133 /// and `e`.
134 static double yearsDiff(const bdlt::Date& beginDate,
135 const bdlt::Date& endDate);
136};
137
138// ============================================================================
139// INLINE DEFINITIONS
140// ============================================================================
141
142 // ----------------
143 // struct Actual360
144 // ----------------
145
146// CLASS METHODS
147inline
149 const bdlt::Date& endDate)
150{
151 return endDate - beginDate;
152}
153
154} // close package namespace
155
156
157#endif
158
159// ----------------------------------------------------------------------------
160// Copyright 2015 Bloomberg Finance L.P.
161//
162// Licensed under the Apache License, Version 2.0 (the "License");
163// you may not use this file except in compliance with the License.
164// You may obtain a copy of the License at
165//
166// http://www.apache.org/licenses/LICENSE-2.0
167//
168// Unless required by applicable law or agreed to in writing, software
169// distributed under the License is distributed on an "AS IS" BASIS,
170// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
171// See the License for the specific language governing permissions and
172// limitations under the License.
173// ----------------------------- END-OF-FILE ----------------------------------
174
175/** @} */
176/** @} */
177/** @} */
Definition bdlt_date.h:294
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bbldc_basicactual360.h:107
Definition bbldc_basicactual360.h:116
static int daysDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate)
Definition bbldc_basicactual360.h:148
static double yearsDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate)