Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
nettingsetdetails.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 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
21
23
24namespace ore {
25namespace data {
26
27NettingSetDetails::NettingSetDetails(const map<string, string>& nettingSetMap) {
28 for (const auto& m : nettingSetMap) {
29 if (m.first == "NettingSetId") {
30 nettingSetId_ = nettingSetMap.at(m.first);
31 } else if (m.first == "AgreementType") {
32 agreementType_ = nettingSetMap.at(m.first);
33 } else if (m.first == "CallType") {
34 callType_ = nettingSetMap.at(m.first);
35 } else if (m.first == "InitialMarginType") {
36 initialMarginType_ = nettingSetMap.at(m.first);
37 } else if (m.first == "LegalEntityId") {
38 legalEntityId_ = nettingSetMap.at(m.first);
39 } else {
40 WLOG("NettingSetDetails:: Unsupported field \'" << m.second << "\'");
41 }
42 }
43}
44
46 nettingSetId_ = XMLUtils::getChildValue(node, "NettingSetId", true);
47 agreementType_ = XMLUtils::getChildValue(node, "AgreementType", false);
48 callType_ = XMLUtils::getChildValue(node, "CallType", false);
49 initialMarginType_ = XMLUtils::getChildValue(node, "InitialMarginType", false);
50 legalEntityId_ = XMLUtils::getChildValue(node, "LegalEntityId", false);
51}
52
54 XMLNode* nettingSetDetailsNode = doc.allocNode("NettingSetDetails");
55 XMLUtils::addChild(doc, nettingSetDetailsNode, "NettingSetId", nettingSetId_);
56 if (!agreementType_.empty())
57 XMLUtils::addChild(doc, nettingSetDetailsNode, "AgreementType", agreementType_);
58 if (!callType_.empty())
59 XMLUtils::addChild(doc, nettingSetDetailsNode, "CallType", callType_);
60 if (!initialMarginType_.empty())
61 XMLUtils::addChild(doc, nettingSetDetailsNode, "InitialMarginType", initialMarginType_);
62 if (!legalEntityId_.empty())
63 XMLUtils::addChild(doc, nettingSetDetailsNode, "LegalEntityId", legalEntityId_);
64
65 return nettingSetDetailsNode;
66}
67
68const vector<string> NettingSetDetails::fieldNames(bool includeOptionalFields) {
69 vector<string> fieldNames;
70 if (includeOptionalFields)
71 fieldNames = {"NettingSetId", "AgreementType", "CallType", "InitialMarginType", "LegalEntityId"};
72 else
73 fieldNames = {"NettingSetId"};
74
75 return fieldNames;
76}
77
79 return vector<string>({"AgreementType", "CallType", "InitialMarginType", "LegalEntityId"});
80}
81
82const map<string, string> NettingSetDetails::mapRepresentation() const {
83 map<string, string> rep;
84 rep.insert({"NettingSetId", nettingSetId()});
85 rep.insert({"AgreementType", agreementType()});
86 rep.insert({"CallType", callType()});
87 rep.insert({"InitialMarginType", initialMarginType()});
88 rep.insert({"LegalEntityId", legalEntityId()});
89
90 return rep;
91}
92
93bool operator<(const NettingSetDetails& lhs, const NettingSetDetails& rhs) {
94 return std::tie(lhs.nettingSetId(), lhs.agreementType(), lhs.callType(), lhs.initialMarginType(),
95 lhs.legalEntityId()) < std::tie(rhs.nettingSetId(), rhs.agreementType(), rhs.callType(),
96 rhs.initialMarginType(), rhs.legalEntityId());
97}
98
99bool operator==(const NettingSetDetails& lhs, const NettingSetDetails& rhs) {
100 return (lhs.nettingSetId() == rhs.nettingSetId() && lhs.agreementType() == rhs.agreementType() &&
101 lhs.callType() == rhs.callType() && lhs.initialMarginType() == rhs.initialMarginType() &&
102 lhs.legalEntityId() == rhs.legalEntityId());
103}
104
105bool operator!=(const NettingSetDetails& lhs, const NettingSetDetails& rhs) { return !(lhs == rhs); }
106
107std::ostream& operator<<(std::ostream& out, const NettingSetDetails& nettingSetDetails) {
108 std::ostream& tmp = out << "NettingSetId=\'" << nettingSetDetails.nettingSetId() << "\'";
109
110 if (!nettingSetDetails.emptyOptionalFields()) {
111 return tmp << ", AgreementType=\'" << nettingSetDetails.agreementType() << "\', CallType=\'"
112 << nettingSetDetails.callType() << "\', InitialMarginType=\'"
113 << nettingSetDetails.initialMarginType() << "\', LegalEntityId=\'"
114 << nettingSetDetails.legalEntityId() << "\'";
115 }
116
117 return tmp;
118}
119
120} // namespace data
121} // namespace ore
Serializable object holding netting set identification data.
NettingSetDetails()
Default constructor.
static const vector< string > optionalFieldNames()
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
const map< string, string > mapRepresentation() const
Returns a map representation of the object.
const string & initialMarginType() const
const string & nettingSetId() const
static const vector< string > fieldNames(bool includeOptionalFields=true)
Returns the XML field names of all the private members.
const string & callType() const
const string & legalEntityId() const
const string & agreementType() const
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
Definition: xmlutils.cpp:132
XML Utilities Class.
Definition: xmlutils.hpp:119
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
Classes and functions for log message handling.
@ data
Definition: log.hpp:77
#define WLOG(text)
Logging Macro (Level = Warning)
Definition: log.hpp:550
bool operator<(const Dividend &d1, const Dividend &d2)
bool operator!=(const Filter &a, const Filter &b)
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
bool operator==(const Dividend &d1, const Dividend &d)
Serializable Credit Default Swap.
Definition: namespaces.docs:23
netting set details data model and serialization