Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
barrierdata.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 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 ORE is free software: you can redistribute it and/or modify it
8 under the terms of the Modified BSD License. You should have received a
9 copy of the license along with this program.
10 The license is also available online at <http://opensourcerisk.org>
11 This program is distributed on the basis that it will form a useful
12 contribution to risk analytics and model standardisation, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
15 */
16
19
20using namespace QuantLib;
21
22namespace ore {
23namespace data {
24
26 XMLUtils::checkNode(node, "BarrierData");
27 type_ = XMLUtils::getChildValue(node, "Type", true);
28 style_ = XMLUtils::getChildValue(node, "Style", false);
29 XMLNode* levelData = XMLUtils::getChildNode(node, "LevelData");
30 if (levelData) {
31 vector<XMLNode*> lvls = XMLUtils::getChildrenNodes(levelData, "Level");
32 for (auto& n : lvls) {
33 TradeBarrier barrier;
34 barrier.fromXML(n);
35 tradeBarriers_.push_back(barrier);
36 levels_.push_back(XMLUtils::getChildValueAsDouble(n, "Value", true));
37 }
38 } else {
39 levels_ = XMLUtils::getChildrenValuesAsDoubles(node, "Levels", "Level");
40 for (Size i = 0; i < levels_.size(); i++)
41 tradeBarriers_.push_back(TradeBarrier(levels_[i], ""));
42 }
43 rebate_ = XMLUtils::getChildValueAsDouble(node, "Rebate", false);
44 rebateCurrency_ = XMLUtils::getChildValue(node, "RebateCurrency", false);
45 rebatePayTime_ = XMLUtils::getChildValue(node, "RebatePayTime", false);
46 initialized_ = true;
47}
48
50 XMLNode* node = doc.allocNode("BarrierData");
51 XMLUtils::addChild(doc, node, "Type", type_);
52 if (!style_.empty())
53 XMLUtils::addChild(doc, node, "Style", style_);
54 XMLUtils::addChild(doc, node, "Rebate", rebate_);
55 XMLUtils::addChildren(doc, node, "Levels", "Level", levels_);
56 if (!rebateCurrency_.empty())
57 XMLUtils::addChild(doc, node, "RebateCurrency", rebateCurrency_);
58 if (!rebatePayTime_.empty())
59 XMLUtils::addChild(doc, node, "RebatePayTime", rebatePayTime_);
60 return node;
61}
62} // namespace data
63} // namespace oreplus
std::string rebatePayTime_
Definition: barrierdata.hpp:68
virtual void fromXML(ore::data::XMLNode *node) override
Definition: barrierdata.cpp:25
std::string rebateCurrency_
Definition: barrierdata.hpp:67
virtual ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
Definition: barrierdata.cpp:49
std::vector< double > levels_
Definition: barrierdata.hpp:64
std::vector< ore::data::TradeBarrier > tradeBarriers_
Definition: barrierdata.hpp:66
void fromXML(XMLNode *node)
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
Definition: xmlutils.cpp:132
static vector< Real > getChildrenValuesAsDoubles(XMLNode *node, const string &names, const string &name, bool mandatory=false)
Definition: xmlutils.cpp:319
static void addChildren(XMLDocument &doc, XMLNode *n, const string &names, const string &name, const vector< T > &values)
Definition: xmlutils.cpp:502
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 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
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.