/usr/include/ql/time/schedule.hpp is in libquantlib0-dev 1.12-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2006, 2007, 2011 Ferdinando Ametrano
Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
Copyright (C) 2003, 2004, 2005, 2006, 2009 StatPro Italia srl
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<quantlib-dev@lists.sf.net>. The license is also available online at
<http://quantlib.org/license.shtml>.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
/*! \file schedule.hpp
\brief date schedule
*/
#ifndef quantlib_schedule_hpp
#define quantlib_schedule_hpp
#include <ql/time/calendars/nullcalendar.hpp>
#include <ql/utilities/null.hpp>
#include <ql/time/period.hpp>
#include <ql/time/dategenerationrule.hpp>
#include <ql/errors.hpp>
#include <boost/optional.hpp>
namespace QuantLib {
//! Payment schedule
/*! \ingroup datetime */
class Schedule {
public:
/*! constructor that takes any list of dates, and optionally
meta information that can be used by client classes. Note
that neither the list of dates nor the meta information is
checked for plausibility in any sense. */
Schedule(const std::vector<Date>&,
const Calendar& calendar = NullCalendar(),
const BusinessDayConvention
convention = Unadjusted,
boost::optional<BusinessDayConvention>
terminationDateConvention = boost::none,
const boost::optional<Period> tenor = boost::none,
boost::optional<DateGeneration::Rule> rule = boost::none,
boost::optional<bool> endOfMonth = boost::none,
const std::vector<bool>& isRegular = std::vector<bool>(0));
/*! rule based constructor */
Schedule(Date effectiveDate,
const Date& terminationDate,
const Period& tenor,
const Calendar& calendar,
BusinessDayConvention convention,
BusinessDayConvention terminationDateConvention,
DateGeneration::Rule rule,
bool endOfMonth,
const Date& firstDate = Date(),
const Date& nextToLastDate = Date());
Schedule() {}
//! \name Date access
//@{
Size size() const { return dates_.size(); }
const Date& operator[](Size i) const;
const Date& at(Size i) const;
const Date& date(Size i) const;
Date previousDate(const Date& refDate) const;
Date nextDate(const Date& refDate) const;
const std::vector<Date>& dates() const { return dates_; }
bool hasIsRegular() const;
bool isRegular(Size i) const;
const std::vector<bool>& isRegular() const;
//@}
//! \name Other inspectors
//@{
bool empty() const { return dates_.empty(); }
const Calendar& calendar() const;
const Date& startDate() const;
const Date& endDate() const;
bool hasTenor() const;
const Period& tenor() const;
BusinessDayConvention businessDayConvention() const;
bool hasTerminationDateBusinessDayConvention() const;
BusinessDayConvention terminationDateBusinessDayConvention() const;
bool hasRule() const;
DateGeneration::Rule rule() const;
bool hasEndOfMonth() const;
bool endOfMonth() const;
//@}
//! \name Iterators
//@{
typedef std::vector<Date>::const_iterator const_iterator;
const_iterator begin() const { return dates_.begin(); }
const_iterator end() const { return dates_.end(); }
const_iterator lower_bound(const Date& d = Date()) const;
//@}
//! \name Utilities
//@{
//! truncated schedule
Schedule until(const Date& truncationDate) const;
//@}
private:
boost::optional<Period> tenor_;
Calendar calendar_;
BusinessDayConvention convention_;
boost::optional<BusinessDayConvention> terminationDateConvention_;
boost::optional<DateGeneration::Rule> rule_;
boost::optional<bool> endOfMonth_;
Date firstDate_, nextToLastDate_;
std::vector<Date> dates_;
std::vector<bool> isRegular_;
};
//! helper class
/*! This class provides a more comfortable interface to the
argument list of Schedule's constructor.
*/
class MakeSchedule {
public:
MakeSchedule();
MakeSchedule& from(const Date& effectiveDate);
MakeSchedule& to(const Date& terminationDate);
MakeSchedule& withTenor(const Period&);
MakeSchedule& withFrequency(Frequency);
MakeSchedule& withCalendar(const Calendar&);
MakeSchedule& withConvention(BusinessDayConvention);
MakeSchedule& withTerminationDateConvention(BusinessDayConvention);
MakeSchedule& withRule(DateGeneration::Rule);
MakeSchedule& forwards();
MakeSchedule& backwards();
MakeSchedule& endOfMonth(bool flag=true);
MakeSchedule& withFirstDate(const Date& d);
MakeSchedule& withNextToLastDate(const Date& d);
operator Schedule() const;
private:
Calendar calendar_;
Date effectiveDate_, terminationDate_;
boost::optional<Period> tenor_;
boost::optional<BusinessDayConvention> convention_;
boost::optional<BusinessDayConvention> terminationDateConvention_;
DateGeneration::Rule rule_;
bool endOfMonth_;
Date firstDate_, nextToLastDate_;
};
// inline definitions
inline const Date& Schedule::date(Size i) const {
return dates_.at(i);
}
inline const Date& Schedule::operator[](Size i) const {
#if defined(QL_EXTRA_SAFETY_CHECKS)
return dates_.at(i);
#else
return dates_[i];
#endif
}
inline const Date& Schedule::at(Size i) const {
return dates_.at(i);
}
inline const Calendar& Schedule::calendar() const {
return calendar_;
}
inline const Date& Schedule::startDate() const {
return dates_.front();
}
inline const Date &Schedule::endDate() const { return dates_.back(); }
inline bool Schedule::hasTenor() const {
return tenor_ != boost::none;
}
inline const Period& Schedule::tenor() const {
QL_REQUIRE(hasTenor(),
"full interface (tenor) not available");
return *tenor_;
}
inline BusinessDayConvention Schedule::businessDayConvention() const {
return convention_;
}
inline bool
Schedule::hasTerminationDateBusinessDayConvention() const {
return terminationDateConvention_ != boost::none;
}
inline BusinessDayConvention
Schedule::terminationDateBusinessDayConvention() const {
QL_REQUIRE(hasTerminationDateBusinessDayConvention(),
"full interface (termination date bdc) not available");
return *terminationDateConvention_;
}
inline bool Schedule::hasRule() const {
return rule_ != boost::none;
}
inline DateGeneration::Rule Schedule::rule() const {
QL_REQUIRE(hasRule(), "full interface (rule) not available");
return *rule_;
}
inline bool Schedule::hasEndOfMonth() const {
return endOfMonth_ != boost::none;
}
inline bool Schedule::endOfMonth() const {
QL_REQUIRE(hasEndOfMonth(),
"full interface (end of month) not available");
return *endOfMonth_;
}
}
#endif
|