Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
commodityvolcurveconfig.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 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
25using namespace QuantLib;
26using std::string;
27
28namespace ore {
29namespace data {
30
32 : optionExpiryRollDays_(0) {}
33
35 const string& curveId, const string& curveDescription, const std::string& currency,
36 const vector<QuantLib::ext::shared_ptr<VolatilityConfig>>& volatilityConfig, const string& dayCounter,
37 const string& calendar, const std::string& futureConventionsId, QuantLib::Natural optionExpiryRollDays,
38 const std::string& priceCurveId, const std::string& yieldCurveId, const std::string& quoteSuffix,
39 const OneDimSolverConfig& solverConfig, const boost::optional<bool>& preferOutOfTheMoney)
40 : CurveConfig(curveId, curveDescription), currency_(currency), volatilityConfig_(volatilityConfig),
41 dayCounter_(dayCounter), calendar_(calendar), futureConventionsId_(futureConventionsId),
42 optionExpiryRollDays_(optionExpiryRollDays), priceCurveId_(priceCurveId), yieldCurveId_(yieldCurveId),
43 quoteSuffix_(quoteSuffix), solverConfig_(solverConfig), preferOutOfTheMoney_(preferOutOfTheMoney) {
46}
47
49 if (!priceCurveId().empty())
51 if (!yieldCurveId().empty())
53 for (auto vc : volatilityConfig()) {
54 if (auto vapo = QuantLib::ext::dynamic_pointer_cast<VolatilityApoFutureSurfaceConfig>(vc)) {
56 parseCurveSpec(vapo->baseVolatilityId())->curveConfigID());
57 }
58 if (auto p = QuantLib::ext::dynamic_pointer_cast<ProxyVolatilityConfig>(vc)) {
59 requiredCurveIds_[CurveSpec::CurveType::Commodity].insert(p->proxyVolatilityCurve());
60 requiredCurveIds_[CurveSpec::CurveType::CommodityVolatility].insert(p->proxyVolatilityCurve());
61 if (!p->fxVolatilityCurve().empty())
62 requiredCurveIds_[CurveSpec::CurveType::FXVolatility].insert(p->fxVolatilityCurve());
63 if (!p->correlationCurve().empty())
64 requiredCurveIds_[CurveSpec::CurveType::Correlation].insert(p->correlationCurve());
65 }
66 }
67}
68
69const string& CommodityVolatilityConfig::currency() const { return currency_; }
70
71const string& CommodityVolatilityConfig::dayCounter() const { return dayCounter_; }
72
73const vector<QuantLib::ext::shared_ptr<VolatilityConfig>>& CommodityVolatilityConfig::volatilityConfig() const {
74 return volatilityConfig_;
75}
76
77const string& CommodityVolatilityConfig::calendar() const { return calendar_; }
78
80
82
84
86
88
89const boost::optional<bool>& CommodityVolatilityConfig::preferOutOfTheMoney() const {
91}
92
95}
96
98
99 // Some "reasonable" defaults for commodity volatility searches.
100 // Max eval of 100. Initial guess of 35%. Search between 1 bp and 200%.
101 static OneDimSolverConfig res(100, 0.35, 0.0001, std::make_pair(0.0001, 2.0));
102
103 return res;
104}
105
107
108 XMLUtils::checkNode(node, "CommodityVolatility");
109
110 curveID_ = XMLUtils::getChildValue(node, "CurveId", true);
111 curveDescription_ = XMLUtils::getChildValue(node, "CurveDescription", true);
112 currency_ = XMLUtils::getChildValue(node, "Currency", true);
113
115 vcb.fromXML(node);
117
118 dayCounter_ = "A365";
119 if (XMLNode* n = XMLUtils::getChildNode(node, "DayCounter"))
121
122 calendar_ = "NullCalendar";
123 if (XMLNode* n = XMLUtils::getChildNode(node, "Calendar"))
125
126 futureConventionsId_ = XMLUtils::getChildValue(node, "FutureConventions", false);
127
129 if (XMLNode* n = XMLUtils::getChildNode(node, "OptionExpiryRollDays"))
131
132 priceCurveId_ = XMLUtils::getChildValue(node, "PriceCurveId", false);
133 yieldCurveId_ = XMLUtils::getChildValue(node, "YieldCurveId", false);
134
135 quoteSuffix_ = XMLUtils::getChildValue(node, "QuoteSuffix", false);
136
138 if (XMLNode* n = XMLUtils::getChildNode(node, "OneDimSolverConfig")) {
140 }
141
142 preferOutOfTheMoney_ = boost::none;
143 if (XMLNode* n = XMLUtils::getChildNode(node, "PreferOutOfTheMoney")) {
145 }
146
147 if(auto tmp = XMLUtils::getChildNode(node, "Report")){
149 }
152}
153
155
156 XMLNode* node = doc.allocNode("CommodityVolatility");
157
158 XMLUtils::addChild(doc, node, "CurveId", curveID_);
159 XMLUtils::addChild(doc, node, "CurveDescription", curveDescription_);
160 XMLUtils::addChild(doc, node, "Currency", currency_);
161
162 XMLNode* vnode = doc.allocNode("VolatilityConfig");
163 for (auto vc : volatilityConfig_) {
164 XMLNode* n = vc->toXML(doc);
165 XMLUtils::appendNode(vnode, n);
166 }
167 XMLUtils::appendNode(node, vnode);
168
169 XMLUtils::addChild(doc, node, "DayCounter", dayCounter_);
170 XMLUtils::addChild(doc, node, "Calendar", calendar_);
171 if (!futureConventionsId_.empty())
172 XMLUtils::addChild(doc, node, "FutureConventions", futureConventionsId_);
173 XMLUtils::addChild(doc, node, "OptionExpiryRollDays", static_cast<int>(optionExpiryRollDays_));
174 if (!priceCurveId_.empty())
175 XMLUtils::addChild(doc, node, "PriceCurveId", priceCurveId_);
176 if (!yieldCurveId_.empty())
177 XMLUtils::addChild(doc, node, "YieldCurveId", yieldCurveId_);
178 if (!quoteSuffix_.empty())
179 XMLUtils::addChild(doc, node, "QuoteSuffix", quoteSuffix_);
180 if (!solverConfig_.empty())
183 XMLUtils::addChild(doc, node, "PreferOutOfTheMoney", *preferOutOfTheMoney_);
185 return node;
186}
187
189
190 for (auto config : volatilityConfig_) {
191 // The quotes depend on the type of volatility structure that has been configured.
192 if (auto vc = QuantLib::ext::dynamic_pointer_cast<ConstantVolatilityConfig>(config)) {
193 quotes_.push_back(vc->quote());
194 } else if (auto vc = QuantLib::ext::dynamic_pointer_cast<VolatilityCurveConfig>(config)) {
195 auto qs = vc->quotes();
196 quotes_.insert(quotes_.end(), qs.begin(), qs.end());
197 } else if (auto vc = QuantLib::ext::dynamic_pointer_cast<VolatilitySurfaceConfig>(config)) {
198 string quoteType = to_string(vc->quoteType());
199 string stem = "COMMODITY_OPTION/" + quoteType + "/" + curveID_ + "/" + currency_ + "/";
200 for (const pair<string, string>& p : vc->quotes()) {
201 string q = stem + p.first + "/" + p.second;
202 if (!quoteSuffix_.empty())
203 q += "/" + quoteSuffix_;
204 quotes_.push_back(q);
205 }
206 }
207 }
208}
209
210} // namespace data
211} // namespace ore
void populateQuotes()
Populate CurveConfig::quotes_ with the required quotes.
const std::vector< QuantLib::ext::shared_ptr< VolatilityConfig > > & volatilityConfig() const
const std::string & futureConventionsId() const
std::vector< QuantLib::ext::shared_ptr< VolatilityConfig > > volatilityConfig_
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
const boost::optional< bool > & preferOutOfTheMoney() const
static OneDimSolverConfig defaultSolverConfig()
Base curve configuration.
Definition: curveconfig.hpp:41
vector< string > quotes_
Definition: curveconfig.hpp:74
map< CurveSpec::CurveType, set< string > > requiredCurveIds_
Definition: curveconfig.hpp:75
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
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 XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
Commodity volatility curve configuration.
CurveSpec parser.
QuantLib::ext::shared_ptr< CurveSpec > parseCurveSpec(const string &s)
function to convert a string into a curve spec
bool parseBool(const string &s)
Convert text to bool.
Definition: parsers.cpp:144
Integer parseInteger(const string &s)
Convert text to QuantLib::Integer.
Definition: parsers.cpp:136
@ data
Definition: log.hpp:77
Calendar calendar
Definition: utilities.cpp:441
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.
string conversion utilities