Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CalendarAdjustmentConfig Class Reference

#include <ored/utilities/calendaradjustmentconfig.hpp>

+ Inheritance diagram for CalendarAdjustmentConfig:
+ Collaboration diagram for CalendarAdjustmentConfig:

Public Member Functions

 CalendarAdjustmentConfig ()
 
void addHolidays (const string &calname, const Date &d)
 This method adds d to the list of holidays for cal name. More...
 
void addBusinessDays (const string &calname, const Date &d)
 This method adds d to the list of business days for cal name. More...
 
void addBaseCalendar (const string &calname, const string &d)
 This method adds s as a base calendar for cal name. More...
 
const set< Date > & getHolidays (const string &calname) const
 Returns all the holidays for a given cal name. More...
 
const set< Date > & getBusinessDays (const string &calname) const
 Returns all the business days for a given calname. More...
 
set< string > getCalendars () const
 
const string & getBaseCalendar (const string &calname) const
 
void fromXML (XMLNode *node) override
 
XMLNodetoXML (XMLDocument &doc) const override
 
void append (const CalendarAdjustmentConfig &c)
 add all holidays and business days from c to this instance More...
 
- Public Member Functions inherited from XMLSerializable
virtual ~XMLSerializable ()
 
virtual void fromXML (XMLNode *node)=0
 
virtual XMLNodetoXML (XMLDocument &doc) const =0
 
void fromFile (const std::string &filename)
 
void toFile (const std::string &filename) const
 
void fromXMLString (const std::string &xml)
 Parse from XML string. More...
 
std::string toXMLString () const
 Parse from XML string. More...
 

Private Member Functions

string normalisedName (const string &) const
 

Private Attributes

map< string, string > baseCalendars_
 
map< string, set< Date > > additionalHolidays_
 
map< string, set< Date > > additionalBusinessDays_
 

Detailed Description

Definition at line 45 of file calendaradjustmentconfig.hpp.

Constructor & Destructor Documentation

◆ CalendarAdjustmentConfig()

Definition at line 28 of file calendaradjustmentconfig.cpp.

28{}

Member Function Documentation

◆ addHolidays()

void addHolidays ( const string &  calname,
const Date &  d 
)

This method adds d to the list of holidays for cal name.

Definition at line 30 of file calendaradjustmentconfig.cpp.

30 {
31 additionalHolidays_[normalisedName(calname)].insert(d);
32}
string normalisedName(const string &) const
map< string, set< Date > > additionalHolidays_
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addBusinessDays()

void addBusinessDays ( const string &  calname,
const Date &  d 
)

This method adds d to the list of business days for cal name.

Definition at line 34 of file calendaradjustmentconfig.cpp.

34 {
35 additionalBusinessDays_[normalisedName(calname)].insert(d);
36}
map< string, set< Date > > additionalBusinessDays_
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addBaseCalendar()

void addBaseCalendar ( const string &  calname,
const string &  d 
)

This method adds s as a base calendar for cal name.

Definition at line 38 of file calendaradjustmentconfig.cpp.

38 {
39 baseCalendars_[normalisedName(calname)] = s;
40}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getHolidays()

const set< Date > & getHolidays ( const string &  calname) const

Returns all the holidays for a given cal name.

Definition at line 42 of file calendaradjustmentconfig.cpp.

42 {
43 auto holidays = additionalHolidays_.find(normalisedName(calname));
44 if (holidays != additionalHolidays_.end()) {
45 return holidays->second;
46 } else {
47 static set<Date> empty;
48 return empty;
49 }
50}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getBusinessDays()

const set< Date > & getBusinessDays ( const string &  calname) const

Returns all the business days for a given calname.

Definition at line 52 of file calendaradjustmentconfig.cpp.

52 {
53 auto businessDays = additionalBusinessDays_.find(normalisedName(calname));
54 if (businessDays != additionalBusinessDays_.end()) {
55 return businessDays->second;
56 } else {
57 static set<Date> empty;
58 return empty;
59 }
60}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCalendars()

set< string > getCalendars ( ) const

Definition at line 62 of file calendaradjustmentconfig.cpp.

62 {
63 set<string> cals;
64 for (auto it : additionalHolidays_) {
65 cals.insert(it.first);
66 }
67 for (auto it : additionalBusinessDays_) {
68 cals.insert(it.first);
69 }
70 return cals;
71}
+ Here is the caller graph for this function:

◆ getBaseCalendar()

const string & getBaseCalendar ( const string &  calname) const

Definition at line 74 of file calendaradjustmentconfig.cpp.

74 {
75 auto bc = baseCalendars_.find(normalisedName(calname));
76
77 if (bc != baseCalendars_.end()) {
78 return bc->second;
79 } else {
80 static const string empty = "";
81 return empty;
82 }
83}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Implements XMLSerializable.

Definition at line 97 of file calendaradjustmentconfig.cpp.

97 {
98 XMLUtils::checkNode(node, "CalendarAdjustments");
99
100 //we loop once skipping any new calendars
101 for (auto calnode : XMLUtils::getChildrenNodes(node, "Calendar")) {
102 string calname = XMLUtils::getAttribute(calnode, "name");
103 string baseCalendar = XMLUtils::getChildValue(calnode, "BaseCalendar", false);
104 if (baseCalendar != "") {
105 // we check here if the baseCalendar is in the map before the new calendars are added
106 // this is because we don't want any new calendars to be defined in terms of other new calendars
107 parseCalendar(baseCalendar);
108 continue;
109 }
110 Calendar cal = parseCalendar(calname);
111
112 vector<string> holidayDates = XMLUtils::getChildrenValues(calnode, "AdditionalHolidays", "Date");
113 for (auto holiday : holidayDates) {
114 try {
115 Date h = parseDate(holiday);
116 addHolidays(calname, h);
117 cal.addHoliday(h);
118 } catch(std::exception&) {
119 ALOG("error parsing holiday " << holiday << " for calendar " << calname);
120 }
121 }
122 vector<string> businessDates = XMLUtils::getChildrenValues(calnode, "AdditionalBusinessDays", "Date");
123 for (auto businessDay : businessDates) {
124 try {
125 Date b = parseDate(businessDay);
126 addBusinessDays(calname, b);
127 cal.removeHoliday(b);
128 } catch(std::exception&) {
129 ALOG("error parsing business day " << businessDay << " for calendar " << calname);
130 }
131 }
132 }
133 //then loop again adding the new calendars
134 for (auto calnode : XMLUtils::getChildrenNodes(node, "Calendar")) {
135 string calname = XMLUtils::getAttribute(calnode, "name");
136 string baseCalendar = XMLUtils::getChildValue(calnode, "BaseCalendar", false);
137 if (baseCalendar == "")
138 continue;
139 Calendar cal = CalendarParser::instance().addCalendar(baseCalendar, calname);
140
141 vector<string> holidayDates = XMLUtils::getChildrenValues(calnode, "AdditionalHolidays", "Date");
142 for (auto holiday : holidayDates) {
143 try {
144 Date h = parseDate(holiday);
145 addHolidays(calname, h);
146 cal.addHoliday(h);
147 } catch(std::exception&) {
148 ALOG("error parsing business day " << holiday << " for calendar " << calname);
149 }
150
151 }
152 vector<string> businessDates = XMLUtils::getChildrenValues(calnode, "AdditionalBusinessDays", "Date");
153 for (auto businessDay : businessDates) {
154 try {
155 Date b = parseDate(businessDay);
156 addBusinessDays(calname, b);
157 cal.removeHoliday(b);
158 } catch(std::exception&) {
159 ALOG("error parsing business day " << businessDay << " for calendar " << calname);
160 }
161 }
162
163 addBaseCalendar(calname, baseCalendar);
164 }
165
166}
void addBusinessDays(const string &calname, const Date &d)
This method adds d to the list of business days for cal name.
void addBaseCalendar(const string &calname, const string &d)
This method adds s as a base calendar for cal name.
void addHolidays(const string &calname, const Date &d)
This method adds d to the list of holidays for cal name.
static string getAttribute(XMLNode *node, const string &attrName)
Definition: xmlutils.cpp:419
static void checkNode(XMLNode *n, const string &expectedName)
Definition: xmlutils.cpp:175
static vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
Definition: xmlutils.cpp:428
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
static vector< string > getChildrenValues(XMLNode *node, const string &names, const string &name, bool mandatory=false)
Definition: xmlutils.cpp:306
Calendar parseCalendar(const string &s)
Convert text to QuantLib::Calendar.
Definition: parsers.cpp:157
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
#define ALOG(text)
Logging Macro (Level = Alert)
Definition: log.hpp:544
+ Here is the call graph for this function:

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Implements XMLSerializable.

Definition at line 168 of file calendaradjustmentconfig.cpp.

168 {
169 XMLNode* node = doc.allocNode("CalendarAdjustments");
170 for (auto cal : getCalendars()) {
171 XMLNode* calendarNode = XMLUtils::addChild(doc, node, "Calendar");
172 XMLUtils::addAttribute(doc, calendarNode, "name", cal);
173 if (getBaseCalendar(cal) != "")
174 XMLUtils::addChild(doc, calendarNode, "BaseCalendar", getBaseCalendar(cal));
175 XMLNode* ahd = XMLUtils::addChild(doc, calendarNode, "AdditionalHolidays");
176 for (auto hol : getHolidays(cal)) {
177 XMLUtils::addChild(doc, ahd, "Date", to_string(hol));
178 }
179 XMLNode* abd = XMLUtils::addChild(doc, calendarNode, "AdditionalBusinessDays");
180 for (auto bd : getBusinessDays(cal)) {
181 XMLUtils::addChild(doc, abd, "Date", to_string(bd));
182 }
183 }
184 return node;
185}
const set< Date > & getHolidays(const string &calname) const
Returns all the holidays for a given cal name.
const string & getBaseCalendar(const string &calname) const
const set< Date > & getBusinessDays(const string &calname) const
Returns all the business days for a given calname.
static void addAttribute(XMLDocument &doc, XMLNode *node, const string &attrName, const string &attrValue)
Definition: xmlutils.cpp:412
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
+ Here is the call graph for this function:

◆ append()

void append ( const CalendarAdjustmentConfig c)

add all holidays and business days from c to this instance

Definition at line 86 of file calendaradjustmentconfig.cpp.

86 {
87 for (auto it : c.getCalendars()) {
88 for (auto h : c.getHolidays(it)) {
89 addHolidays(it, h);
90 }
91 for (auto b : c.getBusinessDays(it)) {
92 addBusinessDays(it, b);
93 }
94 }
95};
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ normalisedName()

string normalisedName ( const string &  c) const
private

Definition at line 84 of file calendaradjustmentconfig.cpp.

84{ return parseCalendar(c).name(); }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ baseCalendars_

map<string, string> baseCalendars_
private

Definition at line 75 of file calendaradjustmentconfig.hpp.

◆ additionalHolidays_

map<string, set<Date> > additionalHolidays_
private

Definition at line 76 of file calendaradjustmentconfig.hpp.

◆ additionalBusinessDays_

map<string, set<Date> > additionalBusinessDays_
private

Definition at line 77 of file calendaradjustmentconfig.hpp.