Skip to content

Commit 15e1060

Browse files
committed
QPR-12184 allow removal of first and last date in schedule build
1 parent d706d7c commit 15e1060

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

ql/time/schedule.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ namespace QuantLib {
6161
const ext::optional<Period>& tenor,
6262
const ext::optional<DateGeneration::Rule>& rule,
6363
const ext::optional<bool>& endOfMonth,
64-
std::vector<bool> isRegular)
64+
std::vector<bool> isRegular,
65+
const bool removeFirstDate,
66+
const bool removeLastDate)
6567
: tenor_(tenor), calendar_(std::move(calendar)), convention_(convention),
6668
terminationDateConvention_(terminationDateConvention), rule_(rule), dates_(dates),
6769
isRegular_(std::move(isRegular)) {
@@ -70,6 +72,12 @@ namespace QuantLib {
7072
endOfMonth_ = false;
7173
else
7274
endOfMonth_ = endOfMonth;
75+
76+
if (removeFirstDate)
77+
dates_.erase(dates_.begin());
78+
79+
if (removeLastDate)
80+
dates_.pop_back();
7381

7482
QL_REQUIRE(isRegular_.empty() || isRegular_.size() == dates.size() - 1,
7583
"isRegular size (" << isRegular_.size()
@@ -84,9 +92,11 @@ namespace QuantLib {
8492
BusinessDayConvention convention,
8593
BusinessDayConvention terminationDateConvention,
8694
DateGeneration::Rule rule,
87-
bool endOfMonth,
95+
const bool endOfMonth,
8896
const Date& first,
89-
const Date& nextToLast)
97+
const Date& nextToLast,
98+
const bool removeFirstDate,
99+
const bool removeLastDate)
90100
: tenor_(tenor), calendar_(std::move(cal)), convention_(convention),
91101
terminationDateConvention_(terminationDateConvention), rule_(rule),
92102
endOfMonth_(allowsEndOfMonth(tenor) ? endOfMonth : false),
@@ -458,6 +468,12 @@ namespace QuantLib {
458468
isRegular_.erase(isRegular_.begin());
459469
}
460470

471+
if (removeFirstDate)
472+
dates_.erase(dates_.begin());
473+
474+
if (removeLastDate)
475+
dates_.pop_back();
476+
461477
QL_ENSURE(dates_.size()>1,
462478
"degenerate single date (" << dates_[0] << ") schedule" <<
463479
"\n seed date: " << seed <<

ql/time/schedule.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ namespace QuantLib {
5252
const ext::optional<Period>& tenor = ext::nullopt,
5353
const ext::optional<DateGeneration::Rule>& rule = ext::nullopt,
5454
const ext::optional<bool>& endOfMonth = ext::nullopt,
55-
std::vector<bool> isRegular = std::vector<bool>(0));
55+
std::vector<bool> isRegular = std::vector<bool>(0),
56+
const bool removeFirstDate = false,
57+
const bool removeLastDate = false);
5658
/*! rule based constructor */
5759
Schedule(Date effectiveDate,
5860
const Date& terminationDate,
@@ -61,9 +63,11 @@ namespace QuantLib {
6163
BusinessDayConvention convention,
6264
BusinessDayConvention terminationDateConvention,
6365
DateGeneration::Rule rule,
64-
bool endOfMonth,
66+
const bool endOfMonth,
6567
const Date& firstDate = Date(),
66-
const Date& nextToLastDate = Date());
68+
const Date& nextToLastDate = Date(),
69+
const bool removeFirstDate = false,
70+
const bool removeLastDate = false);
6771
Schedule() = default;
6872
//! \name Date access
6973
//@{

0 commit comments

Comments
 (0)