Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
expiry.cpp File Reference
#include <boost/test/unit_test.hpp>
#include <ored/marketdata/expiry.hpp>
#include <oret/toplevelfixture.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testExpiryDate)
 
 BOOST_AUTO_TEST_CASE (testExpiryPeriod)
 
 BOOST_AUTO_TEST_CASE (testContinuationExpiry)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/3]

BOOST_AUTO_TEST_CASE ( testExpiryDate  )

Definition at line 31 of file expiry.cpp.

31 {
32
33 BOOST_TEST_MESSAGE("Testing expiry date...");
34
35 Date inputDate(13, Jan, 2020);
36
37 // Construct an ExpiryDate directly
38 ExpiryDate expiry(inputDate);
39 BOOST_CHECK_EQUAL(expiry.expiryDate(), inputDate);
40
41 // Write ExpiryDate to string
42 string strExpiry = expiry.toString();
43
44 // Parse ExpiryDate from string
45 QuantLib::ext::shared_ptr<Expiry> parsedExpiry;
46 BOOST_REQUIRE_NO_THROW(parsedExpiry = parseExpiry(strExpiry));
47
48 // Check that we get back an ExpiryDate
49 QuantLib::ext::shared_ptr<ExpiryDate> castExpiry = QuantLib::ext::dynamic_pointer_cast<ExpiryDate>(parsedExpiry);
50 BOOST_CHECK(castExpiry);
51
52 // Check its members
53 BOOST_CHECK_EQUAL(castExpiry->expiryDate(), inputDate);
54}
QuantLib::ext::shared_ptr< Expiry > parseExpiry(const string &strExpiry)
Parse an Expiry from its string representation, strExpiry.
Definition: expiry.cpp:110
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/3]

BOOST_AUTO_TEST_CASE ( testExpiryPeriod  )

Definition at line 56 of file expiry.cpp.

56 {
57
58 BOOST_TEST_MESSAGE("Testing expiry period...");
59
60 Period inputPeriod(3, Months);
61
62 // Construct an ExpiryPeriod directly
63 ExpiryPeriod expiry(inputPeriod);
64 BOOST_CHECK_EQUAL(expiry.expiryPeriod(), inputPeriod);
65
66 // Write ExpiryPeriod to string
67 string strExpiry = expiry.toString();
68
69 // Parse ExpiryPeriod from string
70 QuantLib::ext::shared_ptr<Expiry> parsedExpiry;
71 BOOST_REQUIRE_NO_THROW(parsedExpiry = parseExpiry(strExpiry));
72
73 // Check that we get back an ExpiryDate
74 QuantLib::ext::shared_ptr<ExpiryPeriod> castExpiry = QuantLib::ext::dynamic_pointer_cast<ExpiryPeriod>(parsedExpiry);
75 BOOST_CHECK(castExpiry);
76
77 // Check its members
78 BOOST_CHECK_EQUAL(castExpiry->expiryPeriod(), inputPeriod);
79}
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/3]

BOOST_AUTO_TEST_CASE ( testContinuationExpiry  )

Definition at line 81 of file expiry.cpp.

81 {
82
83 BOOST_TEST_MESSAGE("Testing future continuation expiry...");
84
85 Natural inputIndex = 2;
86
87 // Construct a FutureContinuationExpiry directly
88 FutureContinuationExpiry expiry(inputIndex);
89 BOOST_CHECK_EQUAL(expiry.expiryIndex(), inputIndex);
90
91 // Write FutureContinuationExpiry to string
92 string strExpiry = expiry.toString();
93
94 // Parse FutureContinuationExpiry from string
95 QuantLib::ext::shared_ptr<Expiry> parsedExpiry;
96 BOOST_REQUIRE_NO_THROW(parsedExpiry = parseExpiry(strExpiry));
97
98 // Check that we get back a FutureContinuationExpiry
99 QuantLib::ext::shared_ptr<FutureContinuationExpiry> castExpiry =
100 QuantLib::ext::dynamic_pointer_cast<FutureContinuationExpiry>(parsedExpiry);
101 BOOST_CHECK(castExpiry);
102
103 // Check its members
104 BOOST_CHECK_EQUAL(castExpiry->expiryIndex(), inputIndex);
105}
+ Here is the call graph for this function: