Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
creditdefaultswapdata.cpp File Reference
#include <boost/test/unit_test.hpp>
#include <oret/toplevelfixture.hpp>
#include <ored/portfolio/creditdefaultswapdata.hpp>
#include <ored/utilities/to_string.hpp>
#include <ql/currencies/europe.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testToFromXml)
 
 BOOST_AUTO_TEST_CASE (testConstructionWithExplicitCreditCurveId)
 
 BOOST_AUTO_TEST_CASE (testConstructionWithCdsReferenceInformation)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/3]

BOOST_AUTO_TEST_CASE ( testToFromXml  )

Definition at line 50 of file creditdefaultswapdata.cpp.

50 {
51
52 BOOST_TEST_MESSAGE("Testing toXML and fromXml for CdsReferenceInformation");
53
54 // Explicitly create a CdsReferenceInformation object
55 string referenceEntityId = "RED:2H6677";
56 CdsTier tier = CdsTier::SNRFOR;
57 Currency currency = EURCurrency();
58 CdsDocClause docClause = CdsDocClause::MM14;
59 CdsReferenceInformation inRef(referenceEntityId, tier, currency, docClause);
60
61 // Check the id() is as expected
62 string expId = referenceEntityId + "|" + to_string(tier) + "|" + currency.code() + "|" + to_string(docClause);
63 BOOST_CHECK_EQUAL(inRef.id(), expId);
64
65 // Use toXml to serialise to string
66 string xmlStr = inRef.toXMLString();
67
68 // Use fromXml to populate empty CdsReferenceInformation object
70 outRef.fromXMLString(xmlStr);
71
72 // Check against the original object
73 BOOST_CHECK_EQUAL(inRef.referenceEntityId(), outRef.referenceEntityId());
74 BOOST_CHECK_EQUAL(inRef.tier(), outRef.tier());
75 BOOST_CHECK_EQUAL(inRef.currency(), outRef.currency());
76 BOOST_CHECK_EQUAL(inRef.docClause(), outRef.docClause());
77 BOOST_CHECK_EQUAL(inRef.id(), outRef.id());
78}
const std::string & referenceEntityId() const
const QuantLib::Currency & currency() const
void fromXMLString(const std::string &xml)
Parse from XML string.
Definition: xmlutils.cpp:162
CdsDocClause
CDS documentation clause enumeration.
CdsTier
CDS debt tier enumeration.
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/3]

BOOST_AUTO_TEST_CASE ( testConstructionWithExplicitCreditCurveId  )

Definition at line 84 of file creditdefaultswapdata.cpp.

84 {
85
86 // Construct with explicit credit curve ID
87 string cdsCurveId = "RED:2H6677|SNRFOR|EUR|MM14";
88 CreditDefaultSwapData cdsData("DB", cdsCurveId, premiumLegData());
89
90 // Perform some checks
91 BOOST_CHECK_EQUAL(cdsData.issuerId(), "DB");
92 BOOST_CHECK(cdsData.settlesAccrual());
93 BOOST_CHECK_EQUAL(cdsData.protectionPaymentTime(), QuantExt::CreditDefaultSwap::ProtectionPaymentTime::atDefault);
94 BOOST_CHECK_EQUAL(cdsData.protectionStart(), Date());
95 BOOST_CHECK_EQUAL(cdsData.upfrontDate(), Date());
96 BOOST_CHECK_EQUAL(cdsData.upfrontFee(), Null<Real>());
97 BOOST_CHECK_EQUAL(cdsData.recoveryRate(), Null<Real>());
98 BOOST_CHECK(cdsData.referenceObligation().empty());
99
100 // Check the credit curve Id and reference information are as expected
101 BOOST_CHECK_EQUAL(cdsData.creditCurveId(), cdsCurveId);
102 BOOST_CHECK(!cdsData.referenceInformation());
103
104 // Use toXml to serialise to string
105 string xmlStr = cdsData.toXMLString();
106
107 // Use fromXml to populate empty CreditDefaultSwapData object
108 CreditDefaultSwapData xmlCdsData;
109 xmlCdsData.fromXMLString(xmlStr);
110
111 // Check that the CreditDefaultSwapData object from XML is the same as the explicitly created one
112 BOOST_CHECK_EQUAL(cdsData.issuerId(), xmlCdsData.issuerId());
113 BOOST_CHECK_EQUAL(cdsData.settlesAccrual(), xmlCdsData.settlesAccrual());
114 BOOST_CHECK_EQUAL(cdsData.protectionPaymentTime(), xmlCdsData.protectionPaymentTime());
115 BOOST_CHECK_EQUAL(cdsData.protectionStart(), xmlCdsData.protectionStart());
116 BOOST_CHECK_EQUAL(cdsData.upfrontDate(), xmlCdsData.upfrontDate());
117 BOOST_CHECK_EQUAL(cdsData.upfrontFee(), xmlCdsData.upfrontFee());
118 BOOST_CHECK_EQUAL(cdsData.recoveryRate(), xmlCdsData.recoveryRate());
119 BOOST_CHECK_EQUAL(cdsData.referenceObligation(), xmlCdsData.referenceObligation());
120 BOOST_CHECK_EQUAL(cdsData.creditCurveId(), xmlCdsData.creditCurveId());
121 // The following check is removed because we initialize reference information from the curve id
122 // where possible because it has 4 tokens serparated by |
123 // BOOST_CHECK(!xmlCdsData.referenceInformation());
124}
const std::string & referenceObligation() const
CDS Reference Obligation.
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/3]

BOOST_AUTO_TEST_CASE ( testConstructionWithCdsReferenceInformation  )

Definition at line 126 of file creditdefaultswapdata.cpp.

126 {
127
128 // CdsReferenceInformation object
129 string referenceEntityId = "RED:2H6677";
130 CdsTier tier = CdsTier::SNRFOR;
131 Currency currency = EURCurrency();
132 CdsDocClause docClause = CdsDocClause::MM14;
133 CdsReferenceInformation referenceInfo(referenceEntityId, tier, currency, docClause);
134
135 // Construct with CDS reference information
136 CreditDefaultSwapData cdsData("DB", referenceInfo, premiumLegData());
137
138 // Perform some checks
139 BOOST_CHECK_EQUAL(cdsData.issuerId(), "DB");
140 BOOST_CHECK(cdsData.settlesAccrual());
141 BOOST_CHECK_EQUAL(cdsData.protectionPaymentTime(), QuantExt::CreditDefaultSwap::ProtectionPaymentTime::atDefault);
142 BOOST_CHECK_EQUAL(cdsData.protectionStart(), Date());
143 BOOST_CHECK_EQUAL(cdsData.upfrontDate(), Date());
144 BOOST_CHECK_EQUAL(cdsData.upfrontFee(), Null<Real>());
145 BOOST_CHECK_EQUAL(cdsData.recoveryRate(), Null<Real>());
146 BOOST_CHECK(cdsData.referenceObligation().empty());
147
148 // Check the credit curve Id and reference information are as expected
149 BOOST_CHECK_EQUAL(cdsData.creditCurveId(), referenceInfo.id());
150 BOOST_CHECK(cdsData.referenceInformation());
151 BOOST_CHECK_EQUAL(referenceInfo.referenceEntityId(), cdsData.referenceInformation()->referenceEntityId());
152 BOOST_CHECK_EQUAL(referenceInfo.tier(), cdsData.referenceInformation()->tier());
153 BOOST_CHECK_EQUAL(referenceInfo.currency(), cdsData.referenceInformation()->currency());
154 BOOST_CHECK_EQUAL(referenceInfo.docClause(), cdsData.referenceInformation()->docClause());
155 BOOST_CHECK_EQUAL(referenceInfo.id(), cdsData.referenceInformation()->id());
156
157 // Use toXml to serialise to string
158 string xmlStr = cdsData.toXMLString();
159
160 // Use fromXml to populate empty CreditDefaultSwapData object
161 CreditDefaultSwapData xmlCdsData;
162 xmlCdsData.fromXMLString(xmlStr);
163
164 // Check that the CreditDefaultSwapData object from XML is the same as the explicitly created one
165 BOOST_CHECK_EQUAL(cdsData.issuerId(), xmlCdsData.issuerId());
166 BOOST_CHECK_EQUAL(cdsData.settlesAccrual(), xmlCdsData.settlesAccrual());
167 BOOST_CHECK_EQUAL(cdsData.protectionPaymentTime(), xmlCdsData.protectionPaymentTime());
168 BOOST_CHECK_EQUAL(cdsData.protectionStart(), xmlCdsData.protectionStart());
169 BOOST_CHECK_EQUAL(cdsData.upfrontDate(), xmlCdsData.upfrontDate());
170 BOOST_CHECK_EQUAL(cdsData.upfrontFee(), xmlCdsData.upfrontFee());
171 BOOST_CHECK_EQUAL(cdsData.recoveryRate(), xmlCdsData.recoveryRate());
172 BOOST_CHECK_EQUAL(cdsData.referenceObligation(), xmlCdsData.referenceObligation());
173 BOOST_CHECK_EQUAL(cdsData.creditCurveId(), xmlCdsData.creditCurveId());
174 BOOST_CHECK(xmlCdsData.referenceInformation());
175 BOOST_CHECK_EQUAL(referenceInfo.referenceEntityId(), xmlCdsData.referenceInformation()->referenceEntityId());
176 BOOST_CHECK_EQUAL(referenceInfo.tier(), xmlCdsData.referenceInformation()->tier());
177 BOOST_CHECK_EQUAL(referenceInfo.currency(), xmlCdsData.referenceInformation()->currency());
178 BOOST_CHECK_EQUAL(referenceInfo.docClause(), xmlCdsData.referenceInformation()->docClause());
179 BOOST_CHECK_EQUAL(referenceInfo.id(), xmlCdsData.referenceInformation()->id());
180}
const boost::optional< CdsReferenceInformation > & referenceInformation() const
+ Here is the call graph for this function: