Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
expiry.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 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>
21#include <oret/toplevelfixture.hpp>
22
23using namespace QuantLib;
24using namespace ore::data;
25using namespace std;
26
27BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, ore::test::TopLevelFixture)
28
29BOOST_AUTO_TEST_SUITE(ExpiryTests)
30
31BOOST_AUTO_TEST_CASE(testExpiryDate) {
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}
55
56BOOST_AUTO_TEST_CASE(testExpiryPeriod) {
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}
80
81BOOST_AUTO_TEST_CASE(testContinuationExpiry) {
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}
106
107BOOST_AUTO_TEST_SUITE_END()
108
109BOOST_AUTO_TEST_SUITE_END()
const QuantLib::Date & expiryDate() const
Return the expiry date.
Definition: expiry.cpp:41
std::string toString() const override
Definition: expiry.cpp:45
const QuantLib::Period & expiryPeriod() const
Return the expiry period.
Definition: expiry.cpp:64
std::string toString() const override
Definition: expiry.cpp:68
QuantLib::Natural expiryIndex() const
Return the future continuation expiry index.
Definition: expiry.cpp:85
std::string toString() const override
Definition: expiry.cpp:93
Classes for representing an expiry for use in market quotes.
QuantLib::ext::shared_ptr< Expiry > parseExpiry(const string &strExpiry)
Parse an Expiry from its string representation, strExpiry.
Definition: expiry.cpp:110
BOOST_AUTO_TEST_CASE(testExpiryDate)
Definition: expiry.cpp:31