Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
rangebound.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
22
23namespace ore {
24namespace data {
25using namespace QuantLib;
26
28 XMLUtils::checkNode(node, "RangeBound");
29 if (auto n = XMLUtils::getChildNode(node, "RangeFrom"))
31 else
32 from_ = Null<Real>();
33 if (auto n = XMLUtils::getChildNode(node, "RangeTo"))
35 else
36 to_ = Null<Real>();
37 if (auto n = XMLUtils::getChildNode(node, "Leverage"))
39 else
40 leverage_ = Null<Real>();
41 if (auto n = XMLUtils::getChildNode(node, "Strike"))
43 else
44 strike_ = Null<Real>();
45 if (auto n = XMLUtils::getChildNode(node, "StrikeAdjustment"))
47 else
48 strikeAdjustment_ = Null<Real>();
49}
50
52 XMLNode* node = doc.allocNode("RangeBound");
53 if (from_ != Null<Real>())
54 XMLUtils::addChild(doc, node, "RangeFrom", from_);
55 if (to_ != Null<Real>())
56 XMLUtils::addChild(doc, node, "RangeTo", to_);
57 if (leverage_ != Null<Real>())
58 XMLUtils::addChild(doc, node, "Leverage", leverage_);
59 if (strike_ != Null<Real>())
60 XMLUtils::addChild(doc, node, "Strike", strike_);
61 if (strikeAdjustment_ != Null<Real>())
62 XMLUtils::addChild(doc, node, "StrikeAdjustment", strikeAdjustment_);
63 return node;
64}
65
66bool operator==(const RangeBound& a, const RangeBound& b) {
67 return a.from() == b.from() && a.to() == b.to() && a.leverage() == b.leverage() && a.strike() == b.strike() &&
69}
70
71namespace {
72std::string output(const Real d) {
73 if (d == Null<Real>())
74 return "na";
75 else
76 return std::to_string(d);
77}
78} // namespace
79
80std::ostream& operator<<(std::ostream& out, const RangeBound& t) {
81 return out << "[" << output(t.from()) << ", " << output(t.to()) << "] x " << output(t.leverage()) << " @ "
82 << output(t.strike()) << " +- " << output(t.strikeAdjustment());
83}
84
85std::ostream& operator<<(std::ostream& out, const std::vector<RangeBound>& t) {
86 std::ostringstream s;
87 s << "[ ";
88 for (Size i = 0; i < t.size(); ++i)
89 s << t[i] << (i < t.size() - 1 ? ", " : "");
90 s << " ]";
91 return out << s.str();
92}
93
94} // namespace data
95} // namespace ore
Serializable obejct holding range bound data.
Definition: rangebound.hpp:39
virtual void fromXML(ore::data::XMLNode *node) override
Definition: rangebound.cpp:27
Real leverage() const
Definition: rangebound.hpp:51
virtual ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
Definition: rangebound.cpp:51
Real strike() const
Definition: rangebound.hpp:52
Real strikeAdjustment() const
Definition: rangebound.hpp:53
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 XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
static string getNodeValue(XMLNode *node)
Get a node's value.
Definition: xmlutils.cpp:489
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
Real parseReal(const string &s)
Convert text to Real.
Definition: parsers.cpp:112
@ data
Definition: log.hpp:77
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
bool operator==(const Dividend &d1, const Dividend &d)
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.
rangebound data model