Skip to content

Commit 76081e1

Browse files
NathanielVolfangojenkins
authored andcommitted
QPR-11947 -- Convert ExerciseDates to ScheduleData format
1 parent 5b2c5ea commit 76081e1

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

OREData/ored/portfolio/optiondata.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,15 @@ void OptionData::fromXML(XMLNode* node) {
5454
exerciseFeeSettlementCalendar_ = XMLUtils::getChildValue(node, "ExerciseFeeSettlementCalendar", false);
5555
exerciseFeeSettlementConvention_ = XMLUtils::getChildValue(node, "ExerciseFeeSettlementConvention", false);
5656
exercisePrices_ = XMLUtils::getChildrenValuesAsDoubles(node, "ExercisePrices", "ExercisePrice", false);
57-
exerciseDates_ = XMLUtils::getChildrenValues(node, "ExerciseDates", "ExerciseDate", false);
57+
58+
if (XMLNode* n = XMLUtils::getChildNode(node, "ExerciseDates")) {
59+
if (XMLNode* ed = XMLUtils::getChildNode(n, "ExerciseDate")) {
60+
// For backward compatibility
61+
exerciseDates_ = XMLUtils::getChildrenValues(node, "ExerciseDates", "ExerciseDate");
62+
} else {
63+
exerciseDatesSchedule_.fromXML(n);
64+
}
65+
}
5866

5967
automaticExercise_ = boost::none;
6068
if (XMLNode* n = XMLUtils::getChildNode(node, "AutomaticExercise"))
@@ -146,8 +154,14 @@ ExerciseBuilder::ExerciseBuilder(const OptionData& optionData, const std::vector
146154
// build vector of sorted exercise dates
147155

148156
std::vector<QuantLib::Date> sortedExerciseDates;
149-
for (auto const& d : optionData.exerciseDates())
150-
sortedExerciseDates.push_back(parseDate(d));
157+
if (optionData.exerciseDatesSchedule().hasData()) {
158+
Schedule schedule = makeSchedule(optionData.exerciseDatesSchedule());
159+
sortedExerciseDates = schedule.dates();
160+
} else {
161+
// For backward compatibility
162+
for (auto const& d : optionData.exerciseDates())
163+
sortedExerciseDates.push_back(parseDate(d));
164+
}
151165
std::sort(sortedExerciseDates.begin(), sortedExerciseDates.end());
152166

153167
// build vector of alive exercise dates and corresponding native dates

OREData/ored/portfolio/optiondata.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class OptionData : public XMLSerializable {
7474
const string& style() const { return style_; }
7575
const bool& payoffAtExpiry() const { return payoffAtExpiry_; }
7676
const vector<string>& exerciseDates() const { return exerciseDates_; }
77+
const ScheduleData& exerciseDatesSchedule() const { return exerciseDatesSchedule_; }
7778
const string& noticePeriod() const { return noticePeriod_; }
7879
const string& noticeCalendar() const { return noticeCalendar_; }
7980
const string& noticeConvention() const { return noticeConvention_; }
@@ -95,6 +96,7 @@ class OptionData : public XMLSerializable {
9596
//! \name Setters
9697
//@{
9798
void setExerciseDates(const std::vector<std::string>& exerciseDates) { exerciseDates_ = exerciseDates; }
99+
void setExerciseDates(const ScheduleData& exerciseDatesSchedule) { exerciseDatesSchedule_ = exerciseDatesSchedule; }
98100
void setAutomaticExercise(bool automaticExercise) { automaticExercise_ = automaticExercise; }
99101
void setPaymentData(const OptionPaymentData& paymentData) { paymentData_ = paymentData; }
100102
void setCallPut(const string& callPut) { callPut_ = callPut; }
@@ -121,6 +123,7 @@ class OptionData : public XMLSerializable {
121123
string payoffType2_; // Geometric, Arithmetic
122124
string style_; // European, Bermudan, American
123125
bool payoffAtExpiry_; // Y or N
126+
ScheduleData exerciseDatesSchedule_;
124127
vector<string> exerciseDates_;
125128
string noticePeriod_;
126129
string noticeCalendar_;

0 commit comments

Comments
 (0)