Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
tranche.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 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
20
21using namespace QuantLib;
22using std::string;
23using std::vector;
24
25namespace ore {
26namespace data {
27
29
30 XMLUtils::checkNode(node, "Tranche");
31
32 QL_REQUIRE(node, "No Tranche Node");
33
34 name_ = XMLUtils::getChildValue(node, "Name", true);
35 faceAmount_ = XMLUtils::getChildValueAsDouble(node, "Notional", true);
36 icRatio_ = XMLUtils::getChildValueAsDouble(node, "ICRatio", false, -1.0);
37 ocRatio_ = XMLUtils::getChildValueAsDouble(node, "OCRatio", false, -1.0);
38
39 //FloatingLegData
40 XMLNode* floater = XMLUtils::getChildNode(node, "FloatingLegData");
41 if(floater){
42 //Floating
43 concreteLegData_ = LegDataFactory::instance().build("Floating");
44 concreteLegData_->fromXML(XMLUtils::getChildNode(node, concreteLegData_->legNodeName()));
45 }
46
47 //FixedLegData
48 XMLNode* fixed = XMLUtils::getChildNode(node, "FixedLegData");
49 if(fixed){
50 //Fixed
51 concreteLegData_ = LegDataFactory::instance().build("Fixed");
52 concreteLegData_->fromXML(XMLUtils::getChildNode(node, concreteLegData_->legNodeName()));
53 }
54
55}
56
57
59
60 XMLNode* node = doc.allocNode("Tranche");
61
62 XMLUtils::addChild(doc, node, "Name", name_);
63 XMLUtils::addChild(doc, node, "Notional", faceAmount_);
64 XMLUtils::addChild(doc, node, "ICRatio", icRatio_);
65 XMLUtils::addChild(doc, node, "OCRatio", ocRatio_);
66 XMLUtils::appendNode(node, concreteLegData_->toXML(doc));
67
68 return node;
69}
70
71} // namespace data
72} // namespace ore
std::string name_
Definition: tranche.hpp:64
QuantLib::ext::shared_ptr< LegAdditionalData > concreteLegData_
Definition: tranche.hpp:68
virtual void fromXML(XMLNode *node) override
Definition: tranche.cpp:28
virtual XMLNode * toXML(ore::data::XMLDocument &doc) const override
Definition: tranche.cpp:58
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 Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
Definition: xmlutils.cpp:286
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23
cbo tranche data model and serialization