Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
equityvolcurveconfig.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
23#include <ql/errors.hpp>
24
26
27namespace ore {
28namespace data {
29
31 const string& curveID, const string& curveDescription, const string& currency,
32 const vector<QuantLib::ext::shared_ptr<VolatilityConfig>>& volatilityConfig, const string& equityId,
33 const string& dayCounter, const string& calendar, const OneDimSolverConfig& solverConfig,
34 const boost::optional<bool>& preferOutOfTheMoney)
35 : CurveConfig(curveID, curveDescription), ccy_(currency), volatilityConfig_(volatilityConfig),
36 equityId_(equityId), dayCounter_(dayCounter), calendar_(calendar), solverConfig_(solverConfig),
37 preferOutOfTheMoney_(preferOutOfTheMoney) {
40}
41
43 const string& curveID, const string& curveDescription, const string& currency,
44 const QuantLib::ext::shared_ptr<VolatilityConfig>& volatilityConfig, const string& equityId,
45 const string& dayCounter, const string& calendar, const OneDimSolverConfig& solverConfig,
46 const boost::optional<bool>& preferOutOfTheMoney)
47 : EquityVolatilityCurveConfig(curveID, curveDescription, currency,
48 std::vector<QuantLib::ext::shared_ptr<VolatilityConfig>>{volatilityConfig}, equityId, dayCounter,
49 calendar, solverConfig, preferOutOfTheMoney) {}
50
51const string EquityVolatilityCurveConfig::quoteStem(const string& volType) const {
52 return "EQUITY_OPTION/" + volType + "/" + equityId() + "/" + ccy_ + "/";
53}
54
56 // add quotes from all the volatility configs
57 for (auto vc : volatilityConfig_) {
58 if (QuantLib::ext::dynamic_pointer_cast<QuoteBasedVolatilityConfig>(vc)) {
59 // The quotes depend on the type of volatility structure that has been configured.
60 if (auto c = QuantLib::ext::dynamic_pointer_cast<ConstantVolatilityConfig>(vc)) {
61 quotes_.push_back(c->quote());
62 } else if (auto c = QuantLib::ext::dynamic_pointer_cast<VolatilityCurveConfig>(vc)) {
63 auto qs = c->quotes();
64 quotes_.insert(quotes_.end(), qs.begin(), qs.end());
65 } else if (auto c = QuantLib::ext::dynamic_pointer_cast<VolatilitySurfaceConfig>(vc)) {
66 // Clear the quotes_ if necessary and populate with surface quotes
67 string quoteStr;
68 string volType = to_string<MarketDatum::QuoteType>(c->quoteType());
69 for (const pair<string, string>& p : c->quotes()) {
70 if (p.first == "*" || p.second == "*") {
71 quoteStr = quoteStem(volType) + "*";
72 } else {
73 quoteStr = quoteStem(volType) + p.first + "/" + p.second;
74 }
75 quotes_.push_back(quoteStr);
76 }
77 }
78 }
79 }
80}
81
83 for (auto vc : volatilityConfig_) {
84 if (auto p = QuantLib::ext::dynamic_pointer_cast<ProxyVolatilityConfig>(vc)) {
85 requiredCurveIds_[CurveSpec::CurveType::Equity].insert(p->proxyVolatilityCurve());
86 requiredCurveIds_[CurveSpec::CurveType::EquityVolatility].insert(p->proxyVolatilityCurve());
87 if (!p->fxVolatilityCurve().empty())
88 requiredCurveIds_[CurveSpec::CurveType::FXVolatility].insert(p->fxVolatilityCurve());
89 if (!p->correlationCurve().empty())
90 requiredCurveIds_[CurveSpec::CurveType::Correlation].insert(p->correlationCurve());
91 }
92 }
93}
94
96 XMLUtils::checkNode(node, "EquityVolatility");
97
98 curveID_ = XMLUtils::getChildValue(node, "CurveId", true);
99 curveDescription_ = XMLUtils::getChildValue(node, "CurveDescription", true);
100 equityId_ = XMLUtils::getChildValue(node, "EquityId", false);
101 ccy_ = XMLUtils::getChildValue(node, "Currency", true);
102
103 calendar_ = XMLUtils::getChildValue(node, "Calendar", false);
104
105 XMLNode* n;
106 dayCounter_ = "A365";
107 if ((n = XMLUtils::getChildNode(node, "DayCounter")))
109
111 if (XMLNode* n = XMLUtils::getChildNode(node, "OneDimSolverConfig")) {
113 }
114
115 preferOutOfTheMoney_ = boost::none;
116 if (XMLNode* n = XMLUtils::getChildNode(node, "PreferOutOfTheMoney")) {
118 }
119
120 // In order to remain backward compatible, we first check for a dimension node
121 // If this is present we read the nodes as before but create volatilityConfigs from the inputs
122 // If no dimension nodes then we expect VolatilityConfig nodes - this is the preferred configuration
123 string dim = XMLUtils::getChildValue(node, "Dimension", false);
124 if (dim == "ATM" || dim == "Smile") {
125 vector<string> expiries = XMLUtils::getChildrenValuesAsStrings(node, "Expiries", true);
126 string strikeExtrapolation = "Flat";
127 string timeExtrapolation = "Flat";
128 XMLNode* timeNode = XMLUtils::getChildNode(node, "TimeExtrapolation");
129 if (timeNode) {
130 timeExtrapolation = XMLUtils::getChildValue(node, "TimeExtrapolation", true);
131 }
132 XMLNode* strikeNode = XMLUtils::getChildNode(node, "StrikeExtrapolation");
133 if (strikeNode) {
134 strikeExtrapolation = XMLUtils::getChildValue(node, "StrikeExtrapolation", true);
135 }
136 vector<string> strikes = XMLUtils::getChildrenValuesAsStrings(node, "Strikes", false);
137 if (dim == "ATM") {
138 QL_REQUIRE(strikes.size() == 0,
139 "Dimension ATM, but multiple strikes provided for EquityVolatility " << curveID_);
140 // if ATM create VolatilityCurveConfig which requires quotes to be provided
141 vector<string> quotes(expiries.size());
142 string stem = quoteStem("RATE_LNVOL");
143 if (expiries.size() == 1 && expiries.front() == "*") {
144 quotes[0] = (stem + "*");
145 } else {
146 Size i = 0;
147 for (auto ex : expiries) {
148 quotes[i] = (stem + ex + "/ATMF");
149 i++;
150 }
151 }
152 volatilityConfig_.push_back(
153 QuantLib::ext::make_shared<VolatilityCurveConfig>(quotes, timeExtrapolation, timeExtrapolation));
154 } else {
155 // if Smile create VolatilityStrikeSurfaceConfig
156 volatilityConfig_.push_back(QuantLib::ext::make_shared<VolatilityStrikeSurfaceConfig>(
157 strikes, expiries, "Linear", "Linear", true, timeExtrapolation, strikeExtrapolation));
158 }
159
160 } else if (dim == "") {
162 vcb.fromXML(node);
164 } else {
165 QL_FAIL("Only ATM and Smile dimensions, or Volatility Config supported for EquityVolatility " << curveID_);
166 }
167
168 if (auto tmp = XMLUtils::getChildNode(node, "Report")) {
170 }
171
174}
175
177
178 XMLNode* node = doc.allocNode("EquityVolatility");
179
180 XMLUtils::addChild(doc, node, "CurveId", curveID_);
181 XMLUtils::addChild(doc, node, "CurveDescription", curveDescription_);
182 XMLUtils::addChild(doc, node, "EquityId", equityId_);
183 XMLUtils::addChild(doc, node, "Currency", ccy_);
184 XMLUtils::addChild(doc, node, "DayCounter", dayCounter_);
185
186 XMLNode* vnode = doc.allocNode("VolatilityConfig");
187 for (auto vc : volatilityConfig_) {
188 XMLNode* n = vc->toXML(doc);
189 XMLUtils::appendNode(vnode, n);
190 }
191 XMLUtils::appendNode(node, vnode);
192
193 if (calendar_ != "NullCalendar")
194 XMLUtils::addChild(doc, node, "Calendar", calendar_);
195
196 if (!solverConfig_.empty())
198
200 XMLUtils::addChild(doc, node, "PreferOutOfTheMoney", *preferOutOfTheMoney_);
201
203
204 return node;
205}
206
208 for (auto vc : volatilityConfig_) {
209 if (auto p = QuantLib::ext::dynamic_pointer_cast<ProxyVolatilityConfig>(vc)) {
210 return true;
211 }
212 }
213 return false;
214}
215
218}
219
221
222 // Backward compatible with code that existed before EquityVolatilityCurveConfig
223 // accepted a solver configuration.
224 static OneDimSolverConfig res(100, 0.2, 0.0001, 0.01, 0.0001);
225
226 return res;
227}
228
229} // namespace data
230} // namespace ore
Base curve configuration.
Definition: curveconfig.hpp:41
vector< string > quotes_
Definition: curveconfig.hpp:74
virtual const vector< string > & quotes()
Return all the market quotes required for this config.
Definition: curveconfig.hpp:69
map< CurveSpec::CurveType, set< string > > requiredCurveIds_
Definition: curveconfig.hpp:75
Equity volatility structure configuration.
const string quoteStem(const std::string &volType) const
const std::vector< QuantLib::ext::shared_ptr< VolatilityConfig > > & volatilityConfig() const
XMLNode * toXML(XMLDocument &doc) const override
std::vector< QuantLib::ext::shared_ptr< VolatilityConfig > > volatilityConfig_
static OneDimSolverConfig defaultSolverConfig()
void fromXML(ore::data::XMLNode *node) override
bool empty() const
Return true if default constructed and not populated i.e. no useful configuration.
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
const std::vector< QuantLib::ext::shared_ptr< VolatilityConfig > > & volatilityConfig()
void fromXML(XMLNode *node) override
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
Definition: xmlutils.cpp:132
XML Utilities Class.
Definition: xmlutils.hpp:119
static void checkNode(XMLNode *n, const string &expectedName)
Definition: xmlutils.cpp:175
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 string getNodeValue(XMLNode *node)
Get a node's value.
Definition: xmlutils.cpp:489
static vector< string > getChildrenValuesAsStrings(XMLNode *node, const string &name, bool mandatory=false)
Definition: xmlutils.cpp:342
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
CurveSpec parser.
Equity volatility curve configuration classes.
bool parseBool(const string &s)
Convert text to bool.
Definition: parsers.cpp:144
@ data
Definition: log.hpp:77
Calendar calendar
Definition: utilities.cpp:441
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.
vector< Real > strikes
string conversion utilities