Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
optionpaymentdata.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
23using namespace QuantLib;
24using std::ostream;
25using std::string;
26using std::vector;
27
28namespace ore {
29namespace data {
30
32 : rulesBased_(false), lag_(0), convention_(Following), relativeTo_(RelativeTo::Expiry) {}
33
34OptionPaymentData::OptionPaymentData(const vector<string>& dates)
35 : strDates_(dates), rulesBased_(false), lag_(0), convention_(Following), relativeTo_(RelativeTo::Expiry) {
36 init();
37}
38
39OptionPaymentData::OptionPaymentData(const string& lag, const string& calendar, const string& convention,
40 const string& relativeTo)
41 : strLag_(lag), strCalendar_(calendar), strConvention_(convention), strRelativeTo_(relativeTo), rulesBased_(true),
42 lag_(0), convention_(Following), relativeTo_(RelativeTo::Expiry) {
43 init();
44}
45
47 XMLUtils::checkNode(node, "PaymentData");
48 if (XMLUtils::getChildNode(node, "Dates")) {
49 strDates_ = XMLUtils::getChildrenValues(node, "Dates", "Date", true);
50 rulesBased_ = false;
51 } else if (XMLNode* n = XMLUtils::getChildNode(node, "Rules")) {
52 strLag_ = XMLUtils::getChildValue(n, "Lag", true);
53 strCalendar_ = XMLUtils::getChildValue(n, "Calendar", true);
54 strConvention_ = XMLUtils::getChildValue(n, "Convention", true);
55 strRelativeTo_ = "Expiry";
56 if (XMLNode* rtNode = XMLUtils::getChildNode(n, "RelativeTo"))
58 rulesBased_ = true;
59 } else {
60 QL_FAIL("Expected that PaymentData node has a PaymentDates or PaymentRules child node.");
61 }
62 init();
63}
64
66 XMLNode* node = doc.allocNode("PaymentData");
67
68 if (rulesBased_) {
69 XMLNode* rulesNode = doc.allocNode("Rules");
70 XMLUtils::addChild(doc, rulesNode, "Lag", strLag_);
71 XMLUtils::addChild(doc, rulesNode, "Calendar", strCalendar_);
72 XMLUtils::addChild(doc, rulesNode, "Convention", strConvention_);
73 XMLUtils::addChild(doc, rulesNode, "RelativeTo", strRelativeTo_);
74 XMLUtils::appendNode(node, rulesNode);
75 } else {
76 XMLUtils::addChildren(doc, node, "Dates", "Date", strDates_);
77 }
78
79 return node;
80}
81
83 if (rulesBased_) {
88 } else {
89 QL_REQUIRE(strDates_.size() > 0, "Expected at least 1 option payment date.");
90 dates_.reserve(strDates_.size());
91 for (const string& d : strDates_) {
92 dates_.push_back(parseDate(d));
93 }
94 }
95}
96
98 if (strRelativeTo_ == "Expiry") {
100 } else if (strRelativeTo_ == "Exercise") {
102 } else {
103 QL_FAIL("Could not convert string " << strRelativeTo_ << " to a valid RelativeTo value.");
104 }
105}
106
107ostream& operator<<(ostream& out, const OptionPaymentData::RelativeTo& relativeTo) {
108 switch (relativeTo) {
110 return out << "Expiry";
112 return out << "Exercise";
113 default:
114 QL_FAIL("Could not convert the relativeTo enum value to string.");
115 }
116}
117
118} // namespace data
119} // namespace ore
void populateRelativeTo()
Populate the value of relativeTo_ member from string.
std::vector< QuantLib::Date > dates_
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
OptionPaymentData()
Default constructor.
RelativeTo
When we have payment rules, specifies what date the payment is relative to.
QuantLib::BusinessDayConvention convention_
std::vector< std::string > strDates_
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 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 > 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
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
Calendar parseCalendar(const string &s)
Convert text to QuantLib::Calendar.
Definition: parsers.cpp:157
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
BusinessDayConvention parseBusinessDayConvention(const string &s)
Convert text to QuantLib::BusinessDayConvention.
Definition: parsers.cpp:173
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::ostream & operator<<(std::ostream &out, EquityReturnType t)
Serializable Credit Default Swap.
Definition: namespaces.docs:23
option payment data model and serialization
Map text representations to QuantLib/QuantExt types.