Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
correlationcurveconfig.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
19#include <boost/test/unit_test.hpp>
22#include <oret/toplevelfixture.hpp>
23
24using namespace std;
25using namespace boost::unit_test_framework;
26using namespace QuantLib;
27using namespace ore::data;
28
29BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, ore::test::TopLevelFixture)
30
31BOOST_AUTO_TEST_SUITE(CorrelationCurveConfigTests)
32
33BOOST_AUTO_TEST_CASE(testParseCMSSpreadPriceQuoteCorrelationFromXml) {
34
35 BOOST_TEST_MESSAGE("Testing parsing of correlation curve configuration from XML");
36
37 // Create an XML string representation of the correlation curve configuration
38 string configXml;
39 configXml.append("<Correlation>");
40 configXml.append(" <CurveId>EUR-CMS-10Y/EUR-CMS-1Y</CurveId>");
41 configXml.append(" <CurveDescription>EUR CMS correlations</CurveDescription>");
42 configXml.append(" <CorrelationType>CMSSpread</CorrelationType>");
43 configXml.append(" <Currency>EUR</Currency>");
44 configXml.append(" <Dimension>ATM</Dimension>");
45 configXml.append(" <QuoteType>PRICE</QuoteType>");
46 configXml.append(" <Extrapolation>true</Extrapolation>");
47 configXml.append(" <Conventions>EUR-CMS-10Y-1Y-CONVENTION</Conventions>");
48 configXml.append(" <SwaptionVolatility>EUR</SwaptionVolatility>");
49 configXml.append(" <DiscountCurve>EUR-EONIA</DiscountCurve>");
50 configXml.append(" <Calendar>TARGET</Calendar>");
51 configXml.append(" <DayCounter>A365</DayCounter>");
52 configXml.append(" <BusinessDayConvention>Following</BusinessDayConvention>");
53 configXml.append(" <OptionTenors>1Y,2Y</OptionTenors>");
54 configXml.append(" <Index1>EUR-CMS-10Y</Index1>");
55 configXml.append(" <Index2>EUR-CMS-1Y</Index2>");
56 configXml.append("</CorrelationCurve>");
57
58 // Create the XMLNode
59 XMLDocument doc;
60 doc.fromXMLString(configXml);
61 XMLNode* configNode = doc.getFirstNode("Correlation");
62
63 // Parse correlation curve configuration from XML
65 config.fromXML(configNode);
66
67 // Expected vector of quotes
68 vector<string> quotes = {"CORRELATION/PRICE/EUR-CMS-10Y/EUR-CMS-1Y/1Y/ATM",
69 "CORRELATION/PRICE/EUR-CMS-10Y/EUR-CMS-1Y/2Y/ATM"};
70
71 // Check fields
72 BOOST_CHECK_EQUAL(config.curveID(), "EUR-CMS-10Y/EUR-CMS-1Y");
73 BOOST_CHECK_EQUAL(config.curveDescription(), "EUR CMS correlations");
74 BOOST_CHECK_EQUAL(config.index1(), "EUR-CMS-10Y");
75 BOOST_CHECK_EQUAL(config.index2(), "EUR-CMS-1Y");
76 BOOST_CHECK_EQUAL_COLLECTIONS(quotes.begin(), quotes.end(), config.quotes().begin(), config.quotes().end());
77 BOOST_CHECK_EQUAL(config.extrapolate(), true);
78 BOOST_CHECK_EQUAL(config.conventions(), "EUR-CMS-10Y-1Y-CONVENTION");
79 BOOST_CHECK_EQUAL(config.swaptionVolatility(), "EUR");
80 BOOST_CHECK_EQUAL(config.discountCurve(), "EUR-EONIA");
81 BOOST_CHECK_EQUAL(config.dayCounter().name(), "Actual/365 (Fixed)");
82 BOOST_CHECK_EQUAL(config.calendar().name(), "TARGET");
83 BOOST_CHECK_EQUAL(config.businessDayConvention(), BusinessDayConvention::Following);
84
85 vector<string> p;
86 p.push_back("1Y");
87 p.push_back("2Y");
88
89 BOOST_CHECK_EQUAL_COLLECTIONS(p.begin(), p.end(), config.optionTenors().begin(), config.optionTenors().end());
90}
91
92BOOST_AUTO_TEST_CASE(testParseGenericCorrelationFromXml) {
93
94 BOOST_TEST_MESSAGE("Testing parsing of correlation curve configuration from XML");
95
96 // Create an XML string representation of the correlation curve configuration
97 string configXml;
98 configXml.append("<Correlation>");
99 configXml.append(" <CurveId>EUR-CMS-10Y/EUR-CMS-1Y</CurveId>");
100 configXml.append(" <CurveDescription>EUR CMS correlations</CurveDescription>");
101 configXml.append(" <CorrelationType>Generic</CorrelationType>");
102 configXml.append(" <Dimension>ATM</Dimension>");
103 configXml.append(" <QuoteType>RATE</QuoteType>");
104 configXml.append(" <Extrapolation>true</Extrapolation>");
105 configXml.append(" <Calendar>TARGET</Calendar>");
106 configXml.append(" <DayCounter>A365</DayCounter>");
107 configXml.append(" <BusinessDayConvention>Following</BusinessDayConvention>");
108 configXml.append(" <OptionTenors>1Y,2Y</OptionTenors>");
109 configXml.append(" <Index1/>");
110 configXml.append(" <Index2/>");
111 configXml.append(" <Currency/>");
112 configXml.append("</CorrelationCurve>");
113
114 // Create the XMLNode
115 XMLDocument doc;
116 doc.fromXMLString(configXml);
117 XMLNode* configNode = doc.getFirstNode("Correlation");
118
119 // Parse correlation curve configuration from XML
121 config.fromXML(configNode);
122
123 // Check fields
124 BOOST_CHECK_EQUAL(config.curveID(), "EUR-CMS-10Y/EUR-CMS-1Y");
125 BOOST_CHECK_EQUAL(config.curveDescription(), "EUR CMS correlations");
126 BOOST_CHECK_EQUAL(config.extrapolate(), true);
127
128 BOOST_CHECK_EQUAL(config.dayCounter().name(), "Actual/365 (Fixed)");
129 BOOST_CHECK_EQUAL(config.calendar().name(), "TARGET");
130 BOOST_CHECK_EQUAL(config.businessDayConvention(), BusinessDayConvention::Following);
131
132 vector<string> p;
133 p.push_back("1Y");
134 p.push_back("2Y");
135
136 BOOST_CHECK_EQUAL_COLLECTIONS(p.begin(), p.end(), config.optionTenors().begin(), config.optionTenors().end());
137}
138
139BOOST_AUTO_TEST_CASE(testParseGenericCorrelationNullQuoteFromXml) {
140
141 BOOST_TEST_MESSAGE("Testing parsing of correlation curve configuration from XML");
142
143 // Create an XML string representation of the correlation curve configuration
144 string configXml;
145 configXml.append("<Correlation>");
146 configXml.append(" <CurveId>EUR-CMS-10Y/EUR-CMS-1Y</CurveId>");
147 configXml.append(" <CurveDescription>EUR CMS correlations</CurveDescription>");
148 configXml.append(" <CorrelationType>Generic</CorrelationType>");
149 configXml.append(" <QuoteType>NULL</QuoteType>");
150 configXml.append(" <Dimension/>");
151 configXml.append(" <Extrapolation/>");
152 configXml.append(" <Calendar>TARGET</Calendar>");
153 configXml.append(" <DayCounter>A365</DayCounter>");
154 configXml.append(" <BusinessDayConvention/>");
155 configXml.append(" <OptionTenors/>");
156 configXml.append(" <Index1/>");
157 configXml.append(" <Index2/>");
158 configXml.append(" <Currency/>");
159 configXml.append("</CorrelationCurve>");
160
161 // Create the XMLNode
162 XMLDocument doc;
163 doc.fromXMLString(configXml);
164 XMLNode* configNode = doc.getFirstNode("Correlation");
165
166 // Parse correlation curve configuration from XML
168 config.fromXML(configNode);
169
170 // Check fields
171 BOOST_CHECK_EQUAL(config.curveID(), "EUR-CMS-10Y/EUR-CMS-1Y");
172 BOOST_CHECK_EQUAL(config.curveDescription(), "EUR CMS correlations");
173
174 BOOST_CHECK_EQUAL(config.dayCounter().name(), "Actual/365 (Fixed)");
175 BOOST_CHECK_EQUAL(config.calendar().name(), "TARGET");
176}
177BOOST_AUTO_TEST_SUITE_END()
178
179BOOST_AUTO_TEST_SUITE_END()
Correlation curve configuration.
const vector< string > & optionTenors() const
void fromXML(XMLNode *node) override
const vector< string > & quotes() override
Return all the market quotes required for this config.
const BusinessDayConvention & businessDayConvention() const
const string & curveDescription() const
Definition: curveconfig.hpp:55
const string & curveID() const
Definition: curveconfig.hpp:54
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
void fromXMLString(const string &xmlString)
load a document from a hard-coded string
Definition: xmlutils.cpp:103
XMLNode * getFirstNode(const string &name) const
Definition: xmlutils.cpp:116
Map text representations to QuantLib/QuantExt types.
BOOST_AUTO_TEST_CASE(testParseCMSSpreadPriceQuoteCorrelationFromXml)