Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
nettingsetmanager.cpp
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
22#include <ql/errors.hpp>
23
24namespace ore {
25namespace data {
26
28
29void NettingSetManager::add(const QuantLib::ext::shared_ptr<NettingSetDefinition>& nettingSet) {
30 const NettingSetDetails& k = nettingSet->nettingSetDetails();
31
32 std::pair<NettingSetDetails, QuantLib::ext::shared_ptr<NettingSetDefinition>> newNetSetDef(k, nettingSet);
33
34 bool added = data_.insert(newNetSetDef).second;
35 if (added)
36 uniqueKeys_.push_back(k);
37
38 QL_REQUIRE(data_.size() == uniqueKeys_.size(), "NettingSetManager: vector/map size mismatch");
39}
40
41bool NettingSetManager::has(const NettingSetDetails& nettingSetDetails) const {
42 return data_.find(nettingSetDetails) != data_.end();
43}
44
45bool NettingSetManager::has(const string& id) const {
46 return has(NettingSetDetails(id));
47}
48
50 data_.clear();
51 uniqueKeys_.clear();
52}
53
54const bool NettingSetManager::empty() const {
55 return data_.empty();
56}
57
59 for (const auto& nsd : data_) {
60 if (nsd.second->activeCsaFlag() && nsd.second->csaDetails()->calculateIMAmount())
61 return true;
62 }
63 return false;
64}
65
66const set<NettingSetDetails> NettingSetManager::calculateIMNettingSets() const {
67 set<NettingSetDetails> calculateIMNettingSets = set<NettingSetDetails>();
68 for (const auto& nsd : data_) {
69 if (nsd.second->activeCsaFlag() && nsd.second->csaDetails()->calculateIMAmount()) {
70 calculateIMNettingSets.insert(nsd.first);
71 }
72 }
74}
75
76QuantLib::ext::shared_ptr<NettingSetDefinition> NettingSetManager::get(const NettingSetDetails& nettingSetDetails) const {
77 if (has(nettingSetDetails))
78 return data_.find(nettingSetDetails)->second;
79 else
80 QL_FAIL("NettingSetDefinition not found in manager: " << nettingSetDetails);
81}
82
83QuantLib::ext::shared_ptr<NettingSetDefinition> NettingSetManager::get(const string& id) const {
84 auto found = std::find_if(data_.begin(), data_.end(),
85 [&id](const auto& details) { return details.first.nettingSetId() == id; });
86 if (found != data_.end())
87 return found->second;
88 else
89 QL_FAIL("NettingSetDefinition not found in manager: " + id);
90}
91
93 XMLUtils::checkNode(node, "NettingSetDefinitions");
94 vector<XMLNode*> nettingSetNodes = XMLUtils::getChildrenNodes(node, "NettingSet");
95 for (unsigned i = 0; i < nettingSetNodes.size(); i++) {
96 XMLNode* child = nettingSetNodes[i];
97 try {
98 QuantLib::ext::shared_ptr<NettingSetDefinition> nettingSet(new NettingSetDefinition(child));
99 add(nettingSet);
100 } catch (std::exception& ex) {
101 StructuredConfigurationWarningMessage("Netting set manager", "", "Failed to parse netting set definition",
102 ex.what())
103 .log();
104 }
105 }
106}
107
109 XMLNode* node = doc.allocNode("NettingSetDefinitions");
110 // map<NettingSetDetails, const QuantLib::ext::shared_ptr<NettingSetDefinition>>::iterator it;
111 for (auto it = data_.begin(); it != data_.end(); ++it)
112 XMLUtils::appendNode(node, it->second->toXML(doc));
113 return node;
114}
115} // namespace data
116} // namespace ore
void log() const
generate Boost log record to pass to corresponding sinks
Definition: log.cpp:491
Serializable object holding netting set identification data.
vector< NettingSetDetails > uniqueKeys_
map< NettingSetDetails, const QuantLib::ext::shared_ptr< NettingSetDefinition > > data_
const std::set< NettingSetDetails > calculateIMNettingSets() const
const bool calculateIMAmount() const
void add(const QuantLib::ext::shared_ptr< NettingSetDefinition > &nettingSet)
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
bool has(const string &id) const
QuantLib::ext::shared_ptr< NettingSetDefinition > get(const string &id) const
Utility classes for Structured warnings, contains the configuration type and ID (NettingSetId,...
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
Definition: xmlutils.cpp:132
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 void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
Classes and functions for log message handling.
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Manager class for repository of netting set details.
Class for structured configuration warnings.