Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
reportconfig.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
20
22
23namespace ore {
24namespace data {
25
26using namespace QuantLib;
27
29 XMLUtils::checkNode(node, "Report");
30
31 if (auto tmp = XMLUtils::getChildNode(node, "ReportOnDeltaGrid")) {
33 } else {
34 reportOnDeltaGrid_ = boost::none;
35 }
36
37 if (auto tmp = XMLUtils::getChildNode(node, "ReportOnMoneynessGrid")) {
39 } else {
40 reportOnMoneynessGrid_ = boost::none;
41 }
42
43 if (auto tmp = XMLUtils::getChildNode(node, "ReportOnStrikeGrid")) {
45 } else {
46 reportOnStrikeGrid_ = boost::none;
47 }
48
49 if (auto tmp = XMLUtils::getChildNode(node, "ReportOnStrikeSpreadGrid")) {
51 } else {
52 reportOnStrikeGrid_ = boost::none;
53 }
54
55 if (auto tmp = XMLUtils::getChildNode(node, "Deltas")) {
57 } else {
58 deltas_ = boost::none;
59 }
60
61 if (auto tmp = XMLUtils::getChildNode(node, "Moneyness")) {
62 moneyness_ = parseListOfValues<Real>(XMLUtils::getNodeValue(tmp), &parseReal);
63 } else {
64 moneyness_ = boost::none;
65 }
66
67 if (auto tmp = XMLUtils::getChildNode(node, "Strikes")) {
68 strikes_ = parseListOfValues<Real>(XMLUtils::getNodeValue(tmp), &parseReal);
69 } else {
70 strikes_ = boost::none;
71 }
72
73 if (auto tmp = XMLUtils::getChildNode(node, "StrikeSpreads")) {
74 strikeSpreads_ = parseListOfValues<Real>(XMLUtils::getNodeValue(tmp), &parseReal);
75 } else {
76 strikeSpreads_ = boost::none;
77 }
78
79 if (auto tmp = XMLUtils::getChildNode(node, "Expiries")) {
80 expiries_ = parseListOfValues<Period>(XMLUtils::getNodeValue(tmp), &parsePeriod);
81 } else {
82 expiries_ = boost::none;
83 }
84
85 if (auto tmp = XMLUtils::getChildNode(node, "UnderlyingTenors")) {
86 underlyingTenors_ = parseListOfValues<Period>(XMLUtils::getNodeValue(tmp), &parsePeriod);
87 } else {
88 underlyingTenors_ = boost::none;
89 }
90}
91
93 XMLNode* node = doc.allocNode("Report");
95 XMLUtils::addChild(doc, node, "ReportOnDeltaGrid", *reportOnDeltaGrid_);
97 XMLUtils::addChild(doc, node, "ReportOnMoneynessGrid", *reportOnMoneynessGrid_);
98 if (deltas_)
99 XMLUtils::addGenericChildAsList(doc, node, "Deltas", *deltas_);
100 if (moneyness_)
101 XMLUtils::addGenericChildAsList(doc, node, "Moneyness", *moneyness_);
102 if (expiries_)
103 XMLUtils::addGenericChildAsList(doc, node, "Expiries", *expiries_);
105 XMLUtils::addGenericChildAsList(doc, node, "UnderlyingTenors", *underlyingTenors_);
106 return node;
107}
108
109ReportConfig effectiveReportConfig(const ReportConfig& globalConfig, const ReportConfig& localConfig) {
110 bool reportOnDeltaGrid = false;
111 bool reportOnMoneynessGrid = false;
112 bool reportOnStrikeGrid = false;
113 bool reportOnStrikeSpreadGrid = false;
114 std::vector<Real> moneyness;
115 std::vector<std::string> deltas;
116 std::vector<Real> strikes;
117 std::vector<Real> strikeSpreads;
118 std::vector<Period> expiries;
119 std::vector<Period> underlyingTenors;
120
121 if (localConfig.reportOnDeltaGrid())
122 reportOnDeltaGrid = *localConfig.reportOnDeltaGrid();
123 else if (globalConfig.reportOnDeltaGrid())
124 reportOnDeltaGrid = *globalConfig.reportOnDeltaGrid();
125
126 if (localConfig.reportOnMoneynessGrid())
127 reportOnMoneynessGrid = *localConfig.reportOnMoneynessGrid();
128 else if (globalConfig.reportOnMoneynessGrid())
129 reportOnMoneynessGrid = *globalConfig.reportOnMoneynessGrid();
130
131 if (localConfig.reportOnStrikeGrid())
132 reportOnStrikeGrid = *localConfig.reportOnStrikeGrid();
133 else if (globalConfig.reportOnStrikeGrid())
134 reportOnStrikeGrid = *globalConfig.reportOnStrikeGrid();
135
136 if (localConfig.reportOnStrikeSpreadGrid())
137 reportOnStrikeSpreadGrid = *localConfig.reportOnStrikeSpreadGrid();
138 else if (globalConfig.reportOnStrikeSpreadGrid())
139 reportOnStrikeSpreadGrid = *globalConfig.reportOnStrikeSpreadGrid();
140
141 if (localConfig.moneyness())
142 moneyness = *localConfig.moneyness();
143 else if (globalConfig.moneyness())
144 moneyness = *globalConfig.moneyness();
145
146 if (localConfig.deltas())
147 deltas = *localConfig.deltas();
148 else if (globalConfig.deltas())
149 deltas = *globalConfig.deltas();
150
151 if (localConfig.strikes())
152 strikes = *localConfig.strikes();
153 else if (globalConfig.strikes())
154 strikes = *globalConfig.strikes();
155
156 if (localConfig.strikeSpreads())
157 strikeSpreads = *localConfig.strikeSpreads();
158 else if (globalConfig.strikeSpreads())
159 strikeSpreads = *globalConfig.strikeSpreads();
160
161 if (localConfig.expiries())
162 expiries = *localConfig.expiries();
163 else if (globalConfig.expiries())
164 expiries = *globalConfig.expiries();
165
166 if (localConfig.underlyingTenors())
167 underlyingTenors = *localConfig.underlyingTenors();
168 else if (globalConfig.underlyingTenors())
169 underlyingTenors = *globalConfig.underlyingTenors();
170
171 return ReportConfig(reportOnDeltaGrid, reportOnMoneynessGrid, reportOnStrikeGrid, reportOnStrikeSpreadGrid, deltas,
172 moneyness, strikes, strikeSpreads, expiries, underlyingTenors);
173}
174
175} // namespace data
176} // namespace ore
boost::optional< std::vector< Real > > moneyness_
boost::optional< std::vector< Period > > expiries_
boost::optional< std::vector< std::string > > deltas_
const boost::optional< bool > reportOnDeltaGrid() const
const boost::optional< std::vector< Period > > & underlyingTenors() const
const boost::optional< std::vector< Real > > & strikes() const
boost::optional< bool > reportOnStrikeSpreadGrid_
boost::optional< bool > reportOnMoneynessGrid_
const boost::optional< std::vector< std::string > > & deltas() const
const boost::optional< bool > reportOnStrikeSpreadGrid() const
const boost::optional< bool > reportOnMoneynessGrid() const
const boost::optional< bool > reportOnStrikeGrid() const
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
const boost::optional< std::vector< Period > > & expiries() const
boost::optional< bool > reportOnStrikeGrid_
boost::optional< std::vector< Real > > strikes_
boost::optional< bool > reportOnDeltaGrid_
boost::optional< std::vector< Period > > underlyingTenors_
boost::optional< std::vector< Real > > strikeSpreads_
const boost::optional< std::vector< Real > > & moneyness() const
const boost::optional< std::vector< Real > > & strikeSpreads() const
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 addGenericChildAsList(XMLDocument &doc, XMLNode *n, const string &name, const vector< T > &values, const string &attrName="", const string &attr="")
Definition: xmlutils.hpp:144
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
Period parsePeriod(const string &s)
Convert text to QuantLib::Period.
Definition: parsers.cpp:171
bool parseBool(const string &s)
Convert text to bool.
Definition: parsers.cpp:144
Real parseReal(const string &s)
Convert text to Real.
Definition: parsers.cpp:112
@ data
Definition: log.hpp:77
std::vector< string > parseListOfValues(string s, const char escape, const char delim, const char quote)
Definition: parsers.cpp:639
ReportConfig effectiveReportConfig(const ReportConfig &globalConfig, const ReportConfig &localConfig)
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.
md report and arbitrage check configuration
vector< Real > strikes