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

#include <orea/simm/simmbasicnamemapper.hpp>

+ Inheritance diagram for SimmBasicNameMapper:
+ Collaboration diagram for SimmBasicNameMapper:

Public Member Functions

std::string qualifier (const std::string &externalName) const override
 
std::string validTo (const std::string &externalName) const
 Qualifier mapping expiry (ISO date), may be blank and interpreted as QL::maxDate() More...
 
QuantLib::Date validToDate (const std::string &externalName) const
 Qualifier mapping expiry (QuantLib date) More...
 
std::string validFrom (const std::string &externalName) const
 Qualifier mapping start date (ISO date), may be blank and interpreted as QL::minDate() More...
 
QuantLib::Date validFromDate (const std::string &externalName) const
 Qualifier mapping startDate (QuantLib date) More...
 
bool hasQualifier (const std::string &externalName) const override
 Has qualifier. More...
 
bool hasValidQualifier (const std::string &externalName, const QuantLib::Date &referenceDate) const
 Has qualifier that is valid w.r.t. given reference date. More...
 
std::string externalName (const std::string &qualifier) const override
 reverse lookup on qualifier More...
 
- Public Member Functions inherited from SimmNameMapper
virtual ~SimmNameMapper ()
 Destructor. More...
 
virtual std::string qualifier (const std::string &externalName) const =0
 
virtual bool hasQualifier (const std::string &externalName) const =0
 
virtual std::string externalName (const std::string &qualifier) const =0
 
- 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)
 
std::string toXMLString () const
 

Serialisation

std::map< std::string, std::string > mapping_
 
std::map< std::string, std::string > validFrom_
 
std::map< std::string, std::string > validTo_
 
ore::data::XMLNodetoXML (ore::data::XMLDocument &doc) const override
 
void fromXML (ore::data::XMLNode *node) override
 
void addMapping (const std::string &externalName, const std::string &qualifier, const std::string &validFrom="", const std::string &validTo="")
 Add a single mapping. More...
 

Detailed Description

Definition at line 35 of file simmbasicnamemapper.hpp.

Member Function Documentation

◆ qualifier()

string qualifier ( const std::string &  externalName) const
overridevirtual

Return the SIMM Qualifier for a given external name.

Warning:
If the externalName cannot be mapped to a qualifier the externalName itself is returned. In this way, the mapper is basic and places the burden on the caller to call it only when a mapping is needed.

Implements SimmNameMapper.

Definition at line 35 of file simmbasicnamemapper.cpp.

35 {
36 // Returns mapping if there is one found else returns the externalName
37 auto m = mapping_.find(externalName);
38 if (m != mapping_.end()) {
39 Date vt = validToDate(externalName);
40 Date vf = validFromDate(externalName);
41 Date today = Settings::instance().evaluationDate();
42 if (vt >= today && vf <= today)
43 return m->second;
44 else {
45 ALOG("Name mapping for external name " << externalName << " is expired");
46 return externalName;
47 }
48 } else {
49 return externalName;
50 }
51}
QuantLib::Date validToDate(const std::string &externalName) const
Qualifier mapping expiry (QuantLib date)
std::map< std::string, std::string > mapping_
QuantLib::Date validFromDate(const std::string &externalName) const
Qualifier mapping startDate (QuantLib date)
std::string externalName(const std::string &qualifier) const override
reverse lookup on qualifier
#define ALOG(text)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validTo()

string validTo ( const std::string &  externalName) const

Qualifier mapping expiry (ISO date), may be blank and interpreted as QL::maxDate()

Definition at line 53 of file simmbasicnamemapper.cpp.

53 {
54 // Returns mapping expiry date string
55 auto v = validTo_.find(externalName);
56 if (v != validTo_.end())
57 return v->second;
58 else
59 return {};
60}
std::map< std::string, std::string > validTo_
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validToDate()

Date validToDate ( const std::string &  externalName) const

Qualifier mapping expiry (QuantLib date)

Definition at line 71 of file simmbasicnamemapper.cpp.

71 {
72 // Returns mapping expiry date
73 string valid = validTo_.at(externalName);
74 if (!valid.empty())
75 return ore::data::parseDate(valid);
76 else
77 return Date::maxDate();
78}
Date parseDate(const string &s)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validFrom()

string validFrom ( const std::string &  externalName) const

Qualifier mapping start date (ISO date), may be blank and interpreted as QL::minDate()

Definition at line 62 of file simmbasicnamemapper.cpp.

62 {
63 // Returns mapping start date string
64 auto v = validFrom_.find(externalName);
65 if (v != validFrom_.end())
66 return v->second;
67 else
68 return {};
69}
std::map< std::string, std::string > validFrom_
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validFromDate()

Date validFromDate ( const std::string &  externalName) const

Qualifier mapping startDate (QuantLib date)

Definition at line 80 of file simmbasicnamemapper.cpp.

80 {
81 // Returns mapping start date
82 string valid = validFrom_.at(externalName);
83 if (!valid.empty())
84 return ore::data::parseDate(valid);
85 else
86 return Date::minDate();
87}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasQualifier()

bool hasQualifier ( const std::string &  externalName) const
overridevirtual

Has qualifier.

Implements SimmNameMapper.

Definition at line 89 of file simmbasicnamemapper.cpp.

89{ return mapping_.count(externalName) > 0; }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasValidQualifier()

bool hasValidQualifier ( const std::string &  externalName,
const QuantLib::Date &  referenceDate 
) const

Has qualifier that is valid w.r.t. given reference date.

Definition at line 91 of file simmbasicnamemapper.cpp.

92 {
95}
bool hasQualifier(const std::string &externalName) const override
Has qualifier.
Date referenceDate
+ Here is the call graph for this function:

◆ externalName()

std::string externalName ( const std::string &  qualifier) const
overridevirtual

reverse lookup on qualifier

Implements SimmNameMapper.

Definition at line 97 of file simmbasicnamemapper.cpp.

97 {
98 for (auto it = mapping_.begin(); it != mapping_.end(); ++it)
99 if (it->second == qualifier)
100 return it->first;
101 return qualifier;
102}
std::string qualifier(const std::string &externalName) const override
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toXML()

XMLNode * toXML ( ore::data::XMLDocument doc) const
overridevirtual

Implements XMLSerializable.

Definition at line 152 of file simmbasicnamemapper.cpp.

152 {
153
154 LOG("Start toXML for SIMM name mappings");
155
156 XMLNode* node = doc.allocNode("SIMMNameMappings");
157 for (const auto& kv : mapping_) {
158 XMLNode* mappingNode = doc.allocNode("Mapping");
159 string vt = validTo(kv.first);
160 if (vt != "")
161 XMLUtils::addChild(doc, mappingNode, "ValidTo", vt);
162 string vf = validFrom(kv.first);
163 if (vf != "")
164 XMLUtils::addChild(doc, mappingNode, "ValidFrom", vf);
165 XMLUtils::addChild(doc, mappingNode, "Name", kv.first);
166 XMLUtils::addChild(doc, mappingNode, "Qualifier", kv.second);
167 XMLUtils::appendNode(node, mappingNode);
168 }
169
170 LOG("Finished toXML for SIMM name mappings");
171
172 return node;
173}
std::string validFrom(const std::string &externalName) const
Qualifier mapping start date (ISO date), may be blank and interpreted as QL::minDate()
std::string validTo(const std::string &externalName) const
Qualifier mapping expiry (ISO date), may be blank and interpreted as QL::maxDate()
XMLNode * allocNode(const string &nodeName)
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
static void appendNode(XMLNode *parent, XMLNode *child)
#define LOG(text)
+ Here is the call graph for this function:

◆ fromXML()

void fromXML ( ore::data::XMLNode node)
overridevirtual

Implements XMLSerializable.

Definition at line 104 of file simmbasicnamemapper.cpp.

104 {
105 XMLUtils::checkNode(node, "SIMMNameMappings");
106
107 // Every time a call to fromXML is made, the map is cleared
108 mapping_.clear();
109
110 LOG("Start parsing SIMMNameMappings");
111
112 for (XMLNode* mappingNode = XMLUtils::getChildNode(node, "Mapping"); mappingNode;
113 mappingNode = XMLUtils::getNextSibling(mappingNode, "Mapping")) {
114
115 string validTo = XMLUtils::getChildValue(mappingNode, "ValidTo", false);
116 string validFrom = XMLUtils::getChildValue(mappingNode, "ValidFrom", false);
117 string name = XMLUtils::getChildValue(mappingNode, "Name", false);
118 string qualifier = XMLUtils::getChildValue(mappingNode, "Qualifier", false);
119 if (name == "" || qualifier == "") {
120 ALOG("skip name mapping for name '" << name << "' and qualifier '" << qualifier << "'");
121 continue;
122 }
123
124 if (validTo != "") {
125 // Check whether the provided validTo attribute is a valid date, ALERT and ignore if it is not
126 try {
128 } catch(std::exception&) {
129 ALOG("Cannot parse name mapping validTo " << validTo << " for qualifier " << qualifier << ", ignore");
130 validTo = "";
131 }
132 }
133
134 if (validFrom != "") {
135 // Check whether the provided validTo attribute is a valid date, ALERT and ignore if it is not
136 try {
138 } catch(std::exception&) {
139 ALOG("Cannot parse name mapping validFrom " << validFrom << " for qualifier " << qualifier << ", ignore");
140 validFrom = "";
141 }
142 }
143
147 }
148
149 LOG("Finished parsing SIMMNameMappings");
150}
static void checkNode(XMLNode *n, const string &expectedName)
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
static XMLNode * getChildNode(XMLNode *n, const string &name="")
static XMLNode * getNextSibling(XMLNode *node, const string &name="")
string name
+ Here is the call graph for this function:

◆ addMapping()

void addMapping ( const std::string &  externalName,
const std::string &  qualifier,
const std::string &  validFrom = "",
const std::string &  validTo = "" 
)

Add a single mapping.

Definition at line 175 of file simmbasicnamemapper.cpp.

176 {
177 // Just overwrite if name already exists
181 if (validTo != "") {
182 try {
184 } catch (std::exception&) {
185 ALOG("Cannot parse name mapping validTo " << validTo << " for qualifier " << qualifier << ", ignore");
187 }
188 }
189 if (validFrom != "") {
190 try {
192 } catch (std::exception&) {
193 ALOG("Cannot parse name mapping validTo " << validFrom << " for qualifier " << qualifier << ", ignore");
195 }
196 }
197}
+ Here is the call graph for this function:

Member Data Documentation

◆ mapping_

std::map<std::string, std::string> mapping_
protected

A mapping from external name to SIMM Qualifier

Definition at line 81 of file simmbasicnamemapper.hpp.

◆ validFrom_

std::map<std::string, std::string> validFrom_
protected

Start and expiry date (ISO) of each mapping

Definition at line 85 of file simmbasicnamemapper.hpp.

◆ validTo_

std::map<std::string, std::string> validTo_
protected

Definition at line 85 of file simmbasicnamemapper.hpp.