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
19#include <boost/test/unit_test.hpp>
20#include <oret/datapaths.hpp>
21#include <oret/toplevelfixture.hpp>
22
24#include <ql/time/calendars/unitedstates.hpp>
25
26using namespace std;
27using namespace boost::unit_test_framework;
28using namespace QuantLib;
29using namespace ore::data;
30
31BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, ore::test::TopLevelFixture)
32
33BOOST_AUTO_TEST_SUITE(OptionPaymentDataTests)
34
35BOOST_AUTO_TEST_CASE(testDefaultConstruction) {
36
37 BOOST_TEST_MESSAGE("Testing default construction...");
38
40
41 BOOST_CHECK(!opd.rulesBased());
42 BOOST_CHECK(opd.dates().empty());
43 BOOST_CHECK_EQUAL(opd.lag(), 0);
44 BOOST_CHECK_EQUAL(opd.calendar(), Calendar());
45 BOOST_CHECK_EQUAL(opd.convention(), Following);
46 BOOST_CHECK_EQUAL(opd.relativeTo(), OptionPaymentData::RelativeTo::Expiry);
47}
48
49BOOST_AUTO_TEST_CASE(testDatesBasedConstruction) {
50
51 BOOST_TEST_MESSAGE("Testing dates based construction...");
52
53 vector<string> strDates{"2020-06-08", "2020-09-08"};
54 OptionPaymentData opd(strDates);
55
56 vector<Date> expDates{Date(8, Jun, 2020), Date(8, Sep, 2020)};
57 BOOST_CHECK(!opd.rulesBased());
58 BOOST_CHECK_EQUAL_COLLECTIONS(opd.dates().begin(), opd.dates().end(), expDates.begin(), expDates.end());
59 BOOST_CHECK_EQUAL(opd.lag(), 0);
60 BOOST_CHECK_EQUAL(opd.calendar(), Calendar());
61 BOOST_CHECK_EQUAL(opd.convention(), Following);
62 BOOST_CHECK_EQUAL(opd.relativeTo(), OptionPaymentData::RelativeTo::Expiry);
63}
64
65BOOST_AUTO_TEST_CASE(testDatesBasedFromXml) {
66
67 BOOST_TEST_MESSAGE("Testing dates based fromXML...");
68
69 // XML input
70 string xml;
71 xml.append("<PaymentData>");
72 xml.append(" <Dates>");
73 xml.append(" <Date>2020-06-08</Date>");
74 xml.append(" <Date>2020-09-08</Date>");
75 xml.append(" </Dates>");
76 xml.append("</PaymentData>");
77
78 // Load OptionPaymentData from XML
80 opd.fromXMLString(xml);
81
82 // Check is as expected.
83 vector<Date> expDates{Date(8, Jun, 2020), Date(8, Sep, 2020)};
84 BOOST_CHECK(!opd.rulesBased());
85 BOOST_CHECK_EQUAL_COLLECTIONS(opd.dates().begin(), opd.dates().end(), expDates.begin(), expDates.end());
86 BOOST_CHECK_EQUAL(opd.lag(), 0);
87 BOOST_CHECK_EQUAL(opd.calendar(), Calendar());
88 BOOST_CHECK_EQUAL(opd.convention(), Following);
89 BOOST_CHECK_EQUAL(opd.relativeTo(), OptionPaymentData::RelativeTo::Expiry);
90}
91
92BOOST_AUTO_TEST_CASE(testDatesBasedToXml) {
93
94 BOOST_TEST_MESSAGE("Testing dates based toXML...");
95
96 // Construct explicitly
97 vector<string> strDates{"2020-06-08", "2020-09-08"};
98 OptionPaymentData inOpd(strDates);
99
100 // Write to XML and read the result from XML to populate new object
101 OptionPaymentData outOpd;
102 outOpd.fromXMLString(inOpd.toXMLString());
103
104 // Check is as expected.
105 BOOST_CHECK(!outOpd.rulesBased());
106 BOOST_CHECK_EQUAL_COLLECTIONS(outOpd.dates().begin(), outOpd.dates().end(), inOpd.dates().begin(),
107 inOpd.dates().end());
108 BOOST_CHECK_EQUAL(outOpd.lag(), 0);
109 BOOST_CHECK_EQUAL(outOpd.calendar(), Calendar());
110 BOOST_CHECK_EQUAL(outOpd.convention(), Following);
111 BOOST_CHECK_EQUAL(outOpd.relativeTo(), OptionPaymentData::RelativeTo::Expiry);
112}
113
114BOOST_AUTO_TEST_CASE(testRulesBasedConstruction) {
115
116 BOOST_TEST_MESSAGE("Testing rules based construction...");
117
118 OptionPaymentData opd("5", "USD", "Following", "Exercise");
119
120 BOOST_CHECK(opd.rulesBased());
121 BOOST_CHECK(opd.dates().empty());
122 BOOST_CHECK_EQUAL(opd.lag(), 5);
123 BOOST_CHECK_EQUAL(opd.calendar(), UnitedStates(UnitedStates::Settlement));
124 BOOST_CHECK_EQUAL(opd.convention(), Following);
125 BOOST_CHECK_EQUAL(opd.relativeTo(), OptionPaymentData::RelativeTo::Exercise);
126}
127
128BOOST_AUTO_TEST_CASE(testRulesBasedFromXml) {
129
130 BOOST_TEST_MESSAGE("Testing rules based fromXML...");
131
132 // XML input
133 string xml;
134 xml.append("<PaymentData>");
135 xml.append(" <Rules>");
136 xml.append(" <Lag>3</Lag>");
137 xml.append(" <Calendar>US</Calendar>");
138 xml.append(" <Convention>ModifiedFollowing</Convention>");
139 xml.append(" <RelativeTo>Expiry</RelativeTo>");
140 xml.append(" </Rules>");
141 xml.append("</PaymentData>");
142
143 // Load OptionPaymentData from XML
145 opd.fromXMLString(xml);
146
147 // Check is as expected.
148 BOOST_CHECK(opd.rulesBased());
149 BOOST_CHECK(opd.dates().empty());
150 BOOST_CHECK_EQUAL(opd.lag(), 3);
151 BOOST_CHECK_EQUAL(opd.calendar(), UnitedStates(UnitedStates::Settlement));
152 BOOST_CHECK_EQUAL(opd.convention(), ModifiedFollowing);
153 BOOST_CHECK_EQUAL(opd.relativeTo(), OptionPaymentData::RelativeTo::Expiry);
154}
155
156BOOST_AUTO_TEST_CASE(testRulesBasedToXml) {
157
158 BOOST_TEST_MESSAGE("Testing rules based toXML...");
159
160 // Construct explicitly
161 OptionPaymentData inOpd("3", "USD", "ModifiedFollowing", "Exercise");
162
163 // Write to XML and read the result from XML to populate new object
164 OptionPaymentData outOpd;
165 outOpd.fromXMLString(inOpd.toXMLString());
166
167 // Check is as expected.
168 BOOST_CHECK(outOpd.rulesBased());
169 BOOST_CHECK(outOpd.dates().empty());
170 BOOST_CHECK_EQUAL(outOpd.lag(), 3);
171 BOOST_CHECK_EQUAL(outOpd.calendar(), UnitedStates(UnitedStates::Settlement));
172 BOOST_CHECK_EQUAL(outOpd.convention(), ModifiedFollowing);
173 BOOST_CHECK_EQUAL(outOpd.relativeTo(), OptionPaymentData::RelativeTo::Exercise);
174}
175
176BOOST_AUTO_TEST_SUITE_END()
177
178BOOST_AUTO_TEST_SUITE_END()
QuantLib::BusinessDayConvention convention() const
QuantLib::Natural lag() const
const QuantLib::Calendar & calendar() const
const std::vector< QuantLib::Date > & dates() const
std::string toXMLString() const
Parse from XML string.
Definition: xmlutils.cpp:168
void fromXMLString(const std::string &xml)
Parse from XML string.
Definition: xmlutils.cpp:162
option payment data model and serialization
BOOST_AUTO_TEST_CASE(testDefaultConstruction)