Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
schedule.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file portfolio/schedule.hpp
20 \brief trade schedule data model and serialization
21 \ingroup tradedata
22*/
23
24#pragma once
25
27#include <ql/time/schedule.hpp>
28// #include <ored/utilities/parsers.hpp>
29
30namespace ore {
31namespace data {
32
33//! Serializable object holding schedule Rules data
34/*!
35 \ingroup tradedata
36*/
38public:
39 //! Default constructor
41
42 ScheduleRules(const string& startDate, const string& endDate, const string& tenor, const string& calendar,
43 const string& convention, const string& termConvention, const string& rule,
44 const string& endOfMonth = "N", const string& firstDate = "", const string& lastDate = "",
45 const bool removeFirstDate = false, const bool removeLastDate = false,
46 const string& endOfMonthConvention = "")
51
52 //! Check if key attributes are empty
53 const bool hasData() const { return !startDate_.empty() && !tenor_.empty(); }
54
55 //! \name Inspectors
56 //@{
57 const string& startDate() const { return startDate_; }
58 // might be empty, indicating a perpetual schedule
59 const string& endDate() const { return endDate_; }
60 const string& tenor() const { return tenor_; }
61 const string& calendar() const { return calendar_; }
62 const string& convention() const { return convention_; }
63 const string& termConvention() const { return termConvention_; }
64 const string& rule() const { return rule_; }
65 const string& endOfMonth() const { return endOfMonth_; }
66 const string& endOfMonthConvention() const { return endOfMonthConvention_; }
67 const string& firstDate() const { return firstDate_; }
68 const string& lastDate() const { return lastDate_; }
69 bool removeFirstDate() const { return removeFirstDate_; }
70 bool removeLastDate() const { return removeLastDate_; }
71 //@}
72
73 //! \name Modifiers
74 //@{
75 string& modifyStartDate() { return startDate_; }
76 string& modifyEndDate() { return endDate_; }
77 string& modifyCalendar() { return calendar_; }
78 string& modifyConvention() { return convention_; }
81 //@}
82
83 //! \name Serialisation
84 //@{
85 virtual void fromXML(XMLNode* node) override;
86 virtual XMLNode* toXML(XMLDocument& doc) const override;
87 //@}
88private:
89 string startDate_;
90 string endDate_;
91 string tenor_;
92 string calendar_;
95 string rule_;
98 string firstDate_;
99 string lastDate_;
101 bool removeFirstDate_ = false;
102 bool removeLastDate_ = false;
103 bool was1T_ = false;
104};
105
106//! Serializable object holding schedule Dates data
107/*!
108 \ingroup tradedata
109*/
111public:
112 //! Default constructor
114 //! Constructor
115 ScheduleDates(const string& calendar, const string& convention, const string& tenor, const vector<string>& dates,
116 const string& endOfMonth = "", const string& endOfMonthConvention = "")
119
120 //! Check if key attributes are empty
121 bool hasData() const { return dates_.size() > 0 && !tenor_.empty(); }
122
123 //! \name Inspectors
124 //@{
125 const string& calendar() const { return calendar_; }
126 const string& convention() const { return convention_; }
127 const string& tenor() const { return tenor_; }
128 const string& endOfMonth() const { return endOfMonth_; }
129 const string& endOfMonthConvention() const { return endOfMonthConvention_; }
130 const vector<string>& dates() const { return dates_; }
131 //@}
132
133 //! \name Modifiers
134 //@{
135 vector<string>& modifyDates() { return dates_; }
136 //@}
137
138 //! \name Serialisation
139 //@{
140 virtual void fromXML(XMLNode* node) override;
141 virtual XMLNode* toXML(XMLDocument& doc) const override;
142 //@}
143private:
144 string calendar_;
146 string tenor_;
149 vector<string> dates_;
150 bool was1T_ = false;
151};
152
153//! Serializable object holding Derived schedule data
154/*!
155 \ingroup tradedata
156*/
158public:
159 //! Default constructor
161 //! Constructor
162 ScheduleDerived(const string& baseSchedule, const string& calendar, const string& convention, const string& shift,
163 const bool removeFirstDate = false, const bool removeLastDate = false)
166
167 //! \name Inspectors
168 //@{
169 const string& baseSchedule() const { return baseSchedule_; }
170 const string& calendar() const { return calendar_; }
171 const string& convention() const { return convention_; }
172 const string& shift() const { return shift_; }
173 bool removeFirstDate() const { return removeFirstDate_; }
174 bool removeLastDate() const { return removeLastDate_; }
175 //@}
176
177 //! \name Modifiers
178 //@{
179 string& modifyCalendar() { return calendar_; }
180 string& modifyConvention() { return convention_; }
181 string& modifyShift() { return shift_; }
182 //@}
183
184 //! \name Serialisation
185 //@{
186 virtual void fromXML(XMLNode* node) override;
187 virtual XMLNode* toXML(XMLDocument& doc) const override;
188 //@}
189private:
191 string calendar_;
193 string shift_;
194 bool removeFirstDate_ = false;
195 bool removeLastDate_ = false;
196};
197
198//! Serializable schedule data
199/*!
200 \ingroup tradedata
201*/
203public:
204 //! Default constructor
206 //! Constructor with ScheduleDates
207 ScheduleData(const ScheduleDates& dates, const string& name = "") : name_(name) { addDates(dates); }
208 //! Constructor with ScheduleRules
209 ScheduleData(const ScheduleRules& rules, const string& name = "") : name_(name) { addRules(rules); }
210 //! Constructor with ScheduleDerived
212
213 //! Add dates
214 void addDates(const ScheduleDates& dates) { dates_.emplace_back(dates); }
215 //! Add rules
216 void addRules(const ScheduleRules& rules) { rules_.emplace_back(rules); }
217 //! Add derived schedules
219 derived_.emplace_back(derived);
220 hasDerived_ = true;
221 }
222 //! Check if has any dates/rules/derived schedules
223 bool hasData() const { return dates_.size() > 0 || rules_.size() > 0 || derived_.size() > 0; }
224 vector<string> baseScheduleNames();
225
226 //! \name Inspectors
227 //@{
228 const vector<ScheduleDates>& dates() const { return dates_; }
229 const vector<ScheduleRules>& rules() const { return rules_; }
230 const vector<ScheduleDerived>& derived() const { return derived_; }
231 const string& name() const { return name_; }
232 const bool& hasDerived() const { return hasDerived_; }
233 //@}
234
235 //! \name Modifiers
236 //@{
237 vector<ScheduleDates>& modifyDates() { return dates_; }
238 vector<ScheduleRules>& modifyRules() { return rules_; }
239 vector<ScheduleDerived>& modifyDerived() { return derived_; }
240 //@}
241
242 //! \name Serialisation
243 //@{
244 virtual void fromXML(XMLNode* node) override;
245 virtual XMLNode* toXML(XMLDocument& doc) const override;
246 //@}
247private:
248 vector<ScheduleDates> dates_;
249 vector<ScheduleRules> rules_;
250 vector<ScheduleDerived> derived_;
251 string name_ = "";
252 bool hasDerived_ = false;
253};
254
255// Container class to support building of derived schedules
257// USAGE:
258// 1. Initialise a ScheduleBuilder obj
259// 2. For each Schedule obj that will be built from a given ScheduleData obj:
260// i. Initialise an empty Schedule obj
261// ii. Add the Schedule obj in i. and the corresponding ScheduleData obj into the ScheduleBuilder obj in 1.
262// using the ScheduleBuilder::add() method.
263// 3. Once all required schedules are added for the instrument/leg, call ScheduleBuilder::makeSchedules()
264// with the appropriate openEndDateReplacement, if relevant.
265// If successful, each Schedule obj, derived or otherwise, should have been assigned the correct schedule.
266// NOTE / WARNING:
267// * The schedules should be initialised at the same, or higher, scope as the call to makeSchedules() (and to add())
268
269public:
270 void add(QuantLib::Schedule& schedule, const ScheduleData& scheduleData);
271 void makeSchedules(const QuantLib::Date& openEndDateReplacement = QuantLib::Null<QuantLib::Date>());
272
273private:
274 map<string, pair<ScheduleData, QuantLib::Schedule&>> schedules_;
275};
276
277//! Functions
278QuantLib::Schedule makeSchedule(const ScheduleData& data,
279 const QuantLib::Date& openEndDateReplacement = QuantLib::Null<QuantLib::Date>(),
280 const map<string, QuantLib::Schedule>& baseSchedules = map<string, QuantLib::Schedule>());
281QuantLib::Schedule makeSchedule(const ScheduleDates& dates);
282QuantLib::Schedule makeSchedule(const ScheduleRules& rules,
283 const QuantLib::Date& openEndDateReplacement = QuantLib::Null<QuantLib::Date>());
284QuantLib::Schedule makeSchedule(const ScheduleDerived& derived, const QuantLib::Schedule& baseSchedule);
285
286} // namespace data
287} // namespace ore
void makeSchedules(const QuantLib::Date &openEndDateReplacement=QuantLib::Null< QuantLib::Date >())
Definition: schedule.cpp:214
map< string, pair< ScheduleData, QuantLib::Schedule & > > schedules_
Definition: schedule.hpp:274
void add(QuantLib::Schedule &schedule, const ScheduleData &scheduleData)
Definition: schedule.cpp:209
Serializable schedule data.
Definition: schedule.hpp:202
vector< ScheduleDates > dates_
Definition: schedule.hpp:248
const vector< ScheduleDates > & dates() const
Definition: schedule.hpp:228
ScheduleData(const ScheduleDates &dates, const string &name="")
Constructor with ScheduleDates.
Definition: schedule.hpp:207
ScheduleData(const ScheduleDerived &derived, const string &name="")
Constructor with ScheduleDerived.
Definition: schedule.hpp:211
vector< ScheduleDerived > derived_
Definition: schedule.hpp:250
const vector< ScheduleDerived > & derived() const
Definition: schedule.hpp:230
bool hasData() const
Check if has any dates/rules/derived schedules.
Definition: schedule.hpp:223
vector< string > baseScheduleNames()
Definition: schedule.cpp:172
void addDates(const ScheduleDates &dates)
Add dates.
Definition: schedule.hpp:214
ScheduleData(const ScheduleRules &rules, const string &name="")
Constructor with ScheduleRules.
Definition: schedule.hpp:209
void addRules(const ScheduleRules &rules)
Add rules.
Definition: schedule.hpp:216
vector< ScheduleDates > & modifyDates()
Definition: schedule.hpp:237
ScheduleData()
Default constructor.
Definition: schedule.hpp:205
virtual void fromXML(XMLNode *node) override
Definition: schedule.cpp:179
vector< ScheduleRules > rules_
Definition: schedule.hpp:249
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: schedule.cpp:198
const vector< ScheduleRules > & rules() const
Definition: schedule.hpp:229
vector< ScheduleDerived > & modifyDerived()
Definition: schedule.hpp:239
const bool & hasDerived() const
Definition: schedule.hpp:232
vector< ScheduleRules > & modifyRules()
Definition: schedule.hpp:238
void addDerived(const ScheduleDerived &derived)
Add derived schedules.
Definition: schedule.hpp:218
const string & name() const
Definition: schedule.hpp:231
Serializable object holding schedule Dates data.
Definition: schedule.hpp:110
vector< string > dates_
Definition: schedule.hpp:149
bool hasData() const
Check if key attributes are empty.
Definition: schedule.hpp:121
const string & endOfMonthConvention() const
Definition: schedule.hpp:129
const string & convention() const
Definition: schedule.hpp:126
virtual void fromXML(XMLNode *node) override
Definition: schedule.cpp:124
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: schedule.cpp:134
const string & tenor() const
Definition: schedule.hpp:127
vector< string > & modifyDates()
Definition: schedule.hpp:135
ScheduleDates()
Default constructor.
Definition: schedule.hpp:113
const vector< string > & dates() const
Definition: schedule.hpp:130
ScheduleDates(const string &calendar, const string &convention, const string &tenor, const vector< string > &dates, const string &endOfMonth="", const string &endOfMonthConvention="")
Constructor.
Definition: schedule.hpp:115
const string & calendar() const
Definition: schedule.hpp:125
const string & endOfMonth() const
Definition: schedule.hpp:128
Serializable object holding Derived schedule data.
Definition: schedule.hpp:157
bool removeLastDate() const
Definition: schedule.hpp:174
const string & convention() const
Definition: schedule.hpp:171
ScheduleDerived(const string &baseSchedule, const string &calendar, const string &convention, const string &shift, const bool removeFirstDate=false, const bool removeLastDate=false)
Constructor.
Definition: schedule.hpp:162
virtual void fromXML(XMLNode *node) override
Definition: schedule.cpp:146
ScheduleDerived()
Default constructor.
Definition: schedule.hpp:160
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: schedule.cpp:156
const string & baseSchedule() const
Definition: schedule.hpp:169
const string & calendar() const
Definition: schedule.hpp:170
bool removeFirstDate() const
Definition: schedule.hpp:173
const string & shift() const
Definition: schedule.hpp:172
Serializable object holding schedule Rules data.
Definition: schedule.hpp:37
const string & termConvention() const
Definition: schedule.hpp:63
const string & endDate() const
Definition: schedule.hpp:59
string & modifyEndDate()
Definition: schedule.hpp:76
ScheduleRules()
Default constructor.
Definition: schedule.hpp:40
const string & endOfMonthConvention() const
Definition: schedule.hpp:66
const string & rule() const
Definition: schedule.hpp:64
const string & startDate() const
Definition: schedule.hpp:57
bool removeLastDate() const
Definition: schedule.hpp:70
const string & convention() const
Definition: schedule.hpp:62
const string & lastDate() const
Definition: schedule.hpp:68
virtual void fromXML(XMLNode *node) override
Definition: schedule.cpp:75
string & modifyStartDate()
Definition: schedule.hpp:75
string & modifyConvention()
Definition: schedule.hpp:78
string & modifyTermConvention()
Definition: schedule.hpp:79
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: schedule.cpp:102
const string & tenor() const
Definition: schedule.hpp:60
string & modifyEndOfMonthConvention()
Definition: schedule.hpp:80
const string & calendar() const
Definition: schedule.hpp:61
string & modifyCalendar()
Definition: schedule.hpp:77
bool removeFirstDate() const
Definition: schedule.hpp:69
const string & endOfMonth() const
Definition: schedule.hpp:65
const bool hasData() const
Check if key attributes are empty.
Definition: schedule.hpp:53
ScheduleRules(const string &startDate, const string &endDate, const string &tenor, const string &calendar, const string &convention, const string &termConvention, const string &rule, const string &endOfMonth="N", const string &firstDate="", const string &lastDate="", const bool removeFirstDate=false, const bool removeLastDate=false, const string &endOfMonthConvention="")
Definition: schedule.hpp:42
const string & firstDate() const
Definition: schedule.hpp:67
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
Base class for all serializable classes.
Definition: xmlutils.hpp:101
@ data
Definition: log.hpp:77
Schedule makeSchedule(const ScheduleDates &data)
Definition: schedule.cpp:263
Serializable Credit Default Swap.
Definition: namespaces.docs:23
XML utility functions.