Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
equitycurveconfig.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
22#include <ql/errors.hpp>
23
24using namespace QuantLib;
25
26namespace ore {
27namespace data {
28
29EquityCurveConfig::EquityCurveConfig(const string& curveID, const string& curveDescription,
30 const string& forecastingCurve, const string& currency, const string& calendar,
31 const EquityCurveConfig::Type& type, const string& equitySpotQuote,
32 const vector<string>& fwdQuotes, const string& dayCountID,
33 const string& dividendInterpVariable, const string& dividendInterpMethod,
34 const bool dividendExtrapolation, const bool extrapolation,
35 const QuantLib::Exercise::Type& exerciseStyle)
36 : CurveConfig(curveID, curveDescription), fwdQuotes_(fwdQuotes), forecastingCurve_(forecastingCurve),
37 currency_(currency), calendar_(calendar), type_(type), equitySpotQuoteID_(equitySpotQuote), dayCountID_(dayCountID),
38 divInterpVariable_(dividendInterpVariable), divInterpMethod_(dividendInterpMethod), dividendExtrapolation_(dividendExtrapolation),
39 extrapolation_(extrapolation), exerciseStyle_(exerciseStyle) {
41 quotes_.insert(quotes_.begin(), equitySpotQuote);
43}
44
46 if (!forecastingCurve().empty())
48}
49
51 XMLUtils::checkNode(node, "EquityCurve");
52
53 curveID_ = XMLUtils::getChildValue(node, "CurveId", true);
54 curveDescription_ = XMLUtils::getChildValue(node, "CurveDescription", true);
55 forecastingCurve_ = XMLUtils::getChildValue(node, "ForecastingCurve", true);
56 currency_ = XMLUtils::getChildValue(node, "Currency", true);
57 calendar_ = XMLUtils::getChildValue(node, "Calendar", false);
60 exerciseStyle_ = parseExerciseType(XMLUtils::getChildValue(node, "ExerciseStyle", true));
61 equitySpotQuoteID_ = XMLUtils::getChildValue(node, "SpotQuote", true);
62 dayCountID_ = XMLUtils::getChildValue(node, "DayCounter", false);
63 fwdQuotes_ = XMLUtils::getChildrenValues(node, "Quotes", "Quote");
65 if (equitySpotQuoteID_ != "")
66 quotes_.insert(quotes_.begin(), equitySpotQuoteID_);
67
68 XMLNode* divInterpNode = XMLUtils::getChildNode(node, "DividendInterpolation");
69 if (divInterpNode) {
70 divInterpVariable_ = XMLUtils::getChildValue(divInterpNode, "InterpolationVariable", true);
71 divInterpMethod_ = XMLUtils::getChildValue(divInterpNode, "InterpolationMethod", true);
72 } else {
73 divInterpVariable_ = "Zero";
74 divInterpMethod_ = divInterpVariable_ == "Zero" ? "Linear" : "LogLinear";
75 }
76 dividendExtrapolation_ = XMLUtils::getChildValueAsBool(node, "DividendExtrapolation", false, false);
77 extrapolation_ = XMLUtils::getChildValueAsBool(node, "Extrapolation", false, false);
78
79 if (type_ == Type::NoDividends) {
80 QL_REQUIRE(fwdQuotes_.size() == 0,
81 "Invalid EquityCurveConfig, no Quotes should be present when type=NoDividends");
82 QL_REQUIRE(divInterpNode == nullptr,
83 "Invalid EquityCurveConfig, no DividendInterpolation should be present when type=NoDividends");
84 } else {
85 QL_REQUIRE(fwdQuotes_.size() > 0, "Invalid EquityCurveConfig, Quotes should be present when type!=NoDividends");
86 }
88}
89
91 XMLNode* node = doc.allocNode("EquityCurve");
92 XMLUtils::addChild(doc, node, "CurveId", curveID_);
93 XMLUtils::addChild(doc, node, "CurveDescription", curveDescription_);
94 XMLUtils::addChild(doc, node, "Currency", currency_);
95 XMLUtils::addChild(doc, node, "Calendar", calendar_);
96 XMLUtils::addChild(doc, node, "ForecastingCurve", forecastingCurve_);
97 XMLUtils::addChild(doc, node, "Type", to_string(type_));
99 XMLUtils::addChild(doc, node, "ExerciseStyle", to_string(exerciseStyle_));
100 XMLUtils::addChild(doc, node, "SpotQuote", equitySpotQuoteID_);
101 XMLUtils::addChildren(doc, node, "Quotes", "Quote", fwdQuotes_);
102 XMLUtils::addChild(doc, node, "DayCounter", dayCountID_);
103
104 if (type_ != Type::NoDividends) {
105 XMLNode* divInterpNode = XMLUtils::addChild(doc, node, "DividendInterpolation");
106 XMLUtils::addChild(doc, divInterpNode, "InterpolationVariable", divInterpVariable_);
107 XMLUtils::addChild(doc, divInterpNode, "InterpolationMethod", divInterpMethod_);
108 }
109 XMLUtils::addChild(doc, node, "DividendExtrapolation", dividendExtrapolation_);
110 XMLUtils::addChild(doc, node, "Extrapolation", extrapolation_);
111
112 return node;
113}
114
115std::ostream& operator<<(std::ostream& out, EquityCurveConfig::Type t) {
116 switch (t) {
118 return out << "DividendYield";
120 return out << "ForwardPrice";
122 return out << "ForwardDividendPrice";
124 return out << "OptionPremium";
126 return out << "NoDividends";
127 default:
128 QL_FAIL("unknown EquityCurveConfig::Type(" << int(t) << ")");
129 }
130}
131
133 if (str == "DividendYield")
135 else if (str == "ForwardPrice")
137 else if (str == "ForwardDividendPrice")
139 else if (str == "OptionPremium")
141 else if (str == "NoDividends")
143 QL_FAIL("Invalid EquityCurveConfig::Type " << str);
144}
145
146} // namespace data
147} // namespace ore
Base curve configuration.
Definition: curveconfig.hpp:41
vector< string > quotes_
Definition: curveconfig.hpp:74
map< CurveSpec::CurveType, set< string > > requiredCurveIds_
Definition: curveconfig.hpp:75
const string & forecastingCurve() const
Type
Supported equity curve types.
EquityCurveConfig()
Default constructor.
QuantLib::Exercise::Type exerciseStyle_
const vector< string > & fwdQuotes()
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const 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 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 string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
static bool getChildValueAsBool(XMLNode *node, const string &name, bool mandatory=false, bool defaultValue=true)
Definition: xmlutils.cpp:296
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
static vector< string > getChildrenValues(XMLNode *node, const string &names, const string &name, bool mandatory=false)
Definition: xmlutils.cpp:306
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
Equity curve configuration classes.
Exercise::Type parseExerciseType(const std::string &s)
Convert text to QuantLib::Exercise::Type.
Definition: parsers.cpp:466
@ data
Definition: log.hpp:77
Calendar calendar
Definition: utilities.cpp:441
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
EquityCurveConfig::Type parseEquityCurveConfigType(const std::string &str)
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