QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
schedule.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2006, 2007, 2011 Ferdinando Ametrano
5 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
6 Copyright (C) 2003, 2004, 2005, 2006, 2009 StatPro Italia srl
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
26#ifndef quantlib_schedule_hpp
27#define quantlib_schedule_hpp
28
29#include <ql/time/calendars/nullcalendar.hpp>
30#include <ql/utilities/null.hpp>
31#include <ql/time/period.hpp>
32#include <ql/time/dategenerationrule.hpp>
33#include <ql/errors.hpp>
34#include <ql/optional.hpp>
35
36namespace QuantLib {
37
39
40 class Schedule {
41 public:
47 const std::vector<Date>&,
50 const ext::optional<BusinessDayConvention>& terminationDateConvention = ext::nullopt,
51 const ext::optional<Period>& tenor = ext::nullopt,
52 const ext::optional<DateGeneration::Rule>& rule = ext::nullopt,
53 const ext::optional<bool>& endOfMonth = ext::nullopt,
54 std::vector<bool> isRegular = std::vector<bool>(0));
56 Schedule(Date effectiveDate,
57 const Date& terminationDate,
58 const Period& tenor,
60 BusinessDayConvention convention,
61 BusinessDayConvention terminationDateConvention,
63 bool endOfMonth,
64 const Date& firstDate = Date(),
65 const Date& nextToLastDate = Date());
66 Schedule() = default;
68
69 Size size() const { return dates_.size(); }
70 const Date& operator[](Size i) const;
71 const Date& at(Size i) const;
72 const Date& date(Size i) const;
73 Date previousDate(const Date& refDate) const;
74 Date nextDate(const Date& refDate) const;
75 const std::vector<Date>& dates() const { return dates_; }
76 bool hasIsRegular() const;
77 bool isRegular(Size i) const;
78 const std::vector<bool>& isRegular() const;
80
82 bool empty() const { return dates_.empty(); }
83 const Calendar& calendar() const;
84 const Date& startDate() const;
85 const Date& endDate() const;
86 bool hasTenor() const;
87 const Period& tenor() const;
91 bool hasRule() const;
93 bool hasEndOfMonth() const;
94 bool endOfMonth() const;
96
98 typedef std::vector<Date>::const_iterator const_iterator;
99 const_iterator begin() const { return dates_.begin(); }
100 const_iterator end() const { return dates_.end(); }
101 const_iterator lower_bound(const Date& d = Date()) const;
103
105
106 Schedule after(const Date& truncationDate) const;
107 Schedule until(const Date& truncationDate) const;
109 private:
110 ext::optional<Period> tenor_;
113 ext::optional<BusinessDayConvention> terminationDateConvention_;
114 ext::optional<DateGeneration::Rule> rule_;
115 ext::optional<bool> endOfMonth_;
117 std::vector<Date> dates_;
118 std::vector<bool> isRegular_;
119 };
120
121
123
127 public:
128 MakeSchedule& from(const Date& effectiveDate);
129 MakeSchedule& to(const Date& terminationDate);
138 MakeSchedule& endOfMonth(bool flag=true);
141 operator Schedule() const;
142 private:
145 ext::optional<Period> tenor_;
146 ext::optional<BusinessDayConvention> convention_;
147 ext::optional<BusinessDayConvention> terminationDateConvention_;
149 bool endOfMonth_ = false;
151 };
152
157
158 // inline definitions
159
160 inline const Date& Schedule::date(Size i) const {
161 return dates_.at(i);
162 }
163
164 inline const Date& Schedule::operator[](Size i) const {
165 #if defined(QL_EXTRA_SAFETY_CHECKS)
166 return dates_.at(i);
167 #else
168 return dates_[i];
169 #endif
170 }
171
172 inline const Date& Schedule::at(Size i) const {
173 return dates_.at(i);
174 }
175
176 inline const Calendar& Schedule::calendar() const {
177 return calendar_;
178 }
179
180 inline const Date& Schedule::startDate() const {
181 return dates_.front();
182 }
183
184 inline const Date &Schedule::endDate() const { return dates_.back(); }
185
186 inline bool Schedule::hasTenor() const {
187 return static_cast<bool>(tenor_);
188 }
189
190 inline const Period& Schedule::tenor() const {
191 QL_REQUIRE(hasTenor(),
192 "full interface (tenor) not available");
193 return *tenor_;
194 }
195
197 return convention_;
198 }
199
200 inline bool
202 return static_cast<bool>(terminationDateConvention_);
203 }
204
208 "full interface (termination date bdc) not available");
210 }
211
212 inline bool Schedule::hasRule() const {
213 return static_cast<bool>(rule_);
214 }
215
217 QL_REQUIRE(hasRule(), "full interface (rule) not available");
218 return *rule_;
219 }
220
221 inline bool Schedule::hasEndOfMonth() const {
222 return static_cast<bool>(endOfMonth_);
223 }
224
225 inline bool Schedule::endOfMonth() const {
226 QL_REQUIRE(hasEndOfMonth(),
227 "full interface (end of month) not available");
228 return *endOfMonth_;
229 }
230
231}
232
233#endif
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
MakeSchedule & withConvention(BusinessDayConvention)
Definition: schedule.cpp:557
ext::optional< BusinessDayConvention > convention_
Definition: schedule.hpp:146
MakeSchedule & withTerminationDateConvention(BusinessDayConvention)
Definition: schedule.cpp:562
ext::optional< Period > tenor_
Definition: schedule.hpp:145
ext::optional< BusinessDayConvention > terminationDateConvention_
Definition: schedule.hpp:147
MakeSchedule & withRule(DateGeneration::Rule)
Definition: schedule.cpp:568
MakeSchedule & backwards()
Definition: schedule.cpp:578
MakeSchedule & to(const Date &terminationDate)
Definition: schedule.cpp:537
MakeSchedule & withTenor(const Period &)
Definition: schedule.cpp:542
DateGeneration::Rule rule_
Definition: schedule.hpp:148
MakeSchedule & withFirstDate(const Date &d)
Definition: schedule.cpp:588
MakeSchedule & from(const Date &effectiveDate)
Definition: schedule.cpp:532
MakeSchedule & endOfMonth(bool flag=true)
Definition: schedule.cpp:583
MakeSchedule & withFrequency(Frequency)
Definition: schedule.cpp:547
MakeSchedule & forwards()
Definition: schedule.cpp:573
MakeSchedule & withNextToLastDate(const Date &d)
Definition: schedule.cpp:593
MakeSchedule & withCalendar(const Calendar &)
Definition: schedule.cpp:552
Calendar for reproducing theoretical calculations.
Payment schedule.
Definition: schedule.hpp:40
Calendar calendar_
Definition: schedule.hpp:111
Date nextDate(const Date &refDate) const
Definition: schedule.cpp:500
const Date & endDate() const
Definition: schedule.hpp:184
ext::optional< Period > tenor_
Definition: schedule.hpp:110
const_iterator begin() const
Definition: schedule.hpp:99
ext::optional< BusinessDayConvention > terminationDateConvention_
Definition: schedule.hpp:113
std::vector< Date > dates_
Definition: schedule.hpp:117
const Calendar & calendar() const
Definition: schedule.hpp:176
const std::vector< Date > & dates() const
Definition: schedule.hpp:75
std::vector< bool > isRegular_
Definition: schedule.hpp:118
bool hasRule() const
Definition: schedule.hpp:212
bool empty() const
Definition: schedule.hpp:82
std::vector< Date >::const_iterator const_iterator
Definition: schedule.hpp:98
Date previousDate(const Date &refDate) const
Definition: schedule.cpp:508
bool endOfMonth() const
Definition: schedule.hpp:225
BusinessDayConvention convention_
Definition: schedule.hpp:112
const Date & startDate() const
Definition: schedule.hpp:180
ext::optional< bool > endOfMonth_
Definition: schedule.hpp:115
ext::optional< DateGeneration::Rule > rule_
Definition: schedule.hpp:114
Schedule after(const Date &truncationDate) const
truncated schedule
Definition: schedule.cpp:425
const Date & at(Size i) const
Definition: schedule.hpp:172
const Date & operator[](Size i) const
Definition: schedule.hpp:164
DateGeneration::Rule rule() const
Definition: schedule.hpp:216
bool hasTenor() const
Definition: schedule.hpp:186
bool hasEndOfMonth() const
Definition: schedule.hpp:221
const_iterator lower_bound(const Date &d=Date()) const
Definition: schedule.cpp:493
const std::vector< bool > & isRegular() const
Definition: schedule.cpp:527
const Date & date(Size i) const
Definition: schedule.hpp:160
Size size() const
Definition: schedule.hpp:69
const_iterator end() const
Definition: schedule.hpp:100
bool hasTerminationDateBusinessDayConvention() const
Definition: schedule.hpp:201
BusinessDayConvention businessDayConvention() const
Definition: schedule.hpp:196
bool hasIsRegular() const
Definition: schedule.cpp:516
Schedule until(const Date &truncationDate) const
Definition: schedule.cpp:459
const Period & tenor() const
Definition: schedule.hpp:190
BusinessDayConvention terminationDateBusinessDayConvention() const
Definition: schedule.hpp:206
Frequency
Frequency of events.
Definition: frequency.hpp:37
BusinessDayConvention
Business Day conventions.
std::size_t Size
size of a container
Definition: types.hpp:58
const boost::none_t & nullopt
Definition: optional.cpp:27
Definition: any.hpp:35
Date previousTwentieth(const Date &d, DateGeneration::Rule rule)
Definition: schedule.cpp:640