Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
expiry.hpp
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/*! \file ored/marketdata/expiry.hpp
20 \brief Classes for representing an expiry for use in market quotes.
21 \ingroup marketdata
22*/
23
24#pragma once
25
26#include <ql/shared_ptr.hpp>
29#include <ql/time/date.hpp>
30#include <ql/types.hpp>
31#include <string>
32
33#include <boost/serialization/base_object.hpp>
34#include <boost/serialization/export.hpp>
35
36namespace ore {
37namespace data {
38
39/*! Abstract base class to hold information that describes an expiry.
40 */
41class Expiry {
42public:
43 virtual ~Expiry() {}
44
45 //! Populate the Expiry object from \p strExpiry
46 virtual void fromString(const std::string& strExpiry) = 0;
47
48 //! Write the Expiry object to string
49 virtual std::string toString() const = 0;
50
51 //! Will be used for Expiry comparison.
52 friend bool operator==(const Expiry& lhs, const Expiry& rhs);
53
54protected:
55 //! Override in derived classes to compare specific expiries.
56 virtual bool equal_to(const Expiry& other) const = 0;
57
58private:
59 //! Serialization
61 template <class Archive> void serialize(Archive& ar, const unsigned int version);
62};
63
64/*! Expiry consisting of an explicit expiry date
65 */
66class ExpiryDate : public Expiry {
67public:
68 //! Default constructor.
69 ExpiryDate();
70
71 //! Constructor with explicit expiry date.
72 ExpiryDate(const QuantLib::Date& expiryDate);
73
74 //! Return the expiry date.
75 const QuantLib::Date& expiryDate() const;
76
77 /*! Populate ExpiryDate object from \p strExpiryDate which should be a date.
78 An exception is thrown if \p strExpiryDate cannot be parsed as a \c QuantLib::Date.
79 */
80 void fromString(const std::string& strExpiryDate) override;
81
82 /*! Writes the ExpiryDate object to string. This returns the string representation of
83 the expiry date.
84 */
85 std::string toString() const override;
86
87protected:
88 bool equal_to(const Expiry& other) const override;
89
90private:
91 QuantLib::Date expiryDate_;
92 //! Serialization
94 template <class Archive> void serialize(Archive& ar, const unsigned int version);
95};
96
97/*! Expiry consisting of a period
98 */
99class ExpiryPeriod : public Expiry {
100public:
101 //! Default constructor.
102 ExpiryPeriod();
103
104 //! Constructor with expiry period.
105 ExpiryPeriod(const QuantLib::Period& expiryPeriod);
106
107 //! Return the expiry period.
108 const QuantLib::Period& expiryPeriod() const;
109
110 /*! Populate ExpiryPeriod object from \p strExpiryPeriod which should be a period.
111 An exception is thrown if \p strExpiryPeriod cannot be parsed as a \c QuantLib::Period.
112 */
113 void fromString(const std::string& strExpiryPeriod) override;
114
115 /*! Writes the ExpiryPeriod object to string. This returns the string representation of
116 the expiry period.
117 */
118 std::string toString() const override;
119
120protected:
121 bool equal_to(const Expiry& other) const override;
122
123private:
124 QuantLib::Period expiryPeriod_;
125 //! Serialization
127 template <class Archive> void serialize(Archive& ar, const unsigned int version);
128};
129
130/*! Expiry represented by a future continuation index
131 */
133public:
134 //! Constructor with optional explicit future continuation index.
135 FutureContinuationExpiry(QuantLib::Natural expiryIndex = 1);
136
137 //! Return the future continuation expiry index.
138 QuantLib::Natural expiryIndex() const;
139
140 /*! Populate FutureContinuationExpiry object from \p strIndex which should be of the form \c c<Index> where
141 Index is a positive integer. An exception is thrown if \p strIndex is not of this form.
142 */
143 void fromString(const std::string& strIndex) override;
144
145 /*! Writes the FutureContinuationExpiry object to string. This returns the string representation of
146 the future continuation index i.e. a string of the form \c c<Index>.
147 */
148 std::string toString() const override;
149
150protected:
151 bool equal_to(const Expiry& other) const override;
152
153private:
154 QuantLib::Natural expiryIndex_;
155 //! Serialization
157 template <class Archive> void serialize(Archive& ar, const unsigned int version);
158};
159
160//! Write \p strike to stream.
161std::ostream& operator<<(std::ostream& os, const Expiry& expiry);
162
163//! Parse an Expiry from its string representation, \p strExpiry.
164QuantLib::ext::shared_ptr<Expiry> parseExpiry(const std::string& strExpiry);
165
166} // namespace data
167} // namespace ore
168
QuantLib::Date expiryDate_
Definition: expiry.hpp:91
const QuantLib::Date & expiryDate() const
Return the expiry date.
Definition: expiry.cpp:41
ExpiryDate()
Default constructor.
Definition: expiry.cpp:37
ExpiryDate(const QuantLib::Date &expiryDate)
Constructor with explicit expiry date.
friend class boost::serialization::access
Serialization.
Definition: expiry.hpp:93
std::string toString() const override
Definition: expiry.cpp:45
bool equal_to(const Expiry &other) const override
Override in derived classes to compare specific expiries.
Definition: expiry.cpp:47
void fromString(const std::string &strExpiryDate) override
Definition: expiry.cpp:43
void serialize(Archive &ar, const unsigned int version)
Definition: expiry.cpp:55
virtual std::string toString() const =0
Write the Expiry object to string.
virtual ~Expiry()
Definition: expiry.hpp:43
friend class boost::serialization::access
Serialization.
Definition: expiry.hpp:60
virtual bool equal_to(const Expiry &other) const =0
Override in derived classes to compare specific expiries.
friend bool operator==(const Expiry &lhs, const Expiry &rhs)
Will be used for Expiry comparison.
Definition: expiry.cpp:33
void serialize(Archive &ar, const unsigned int version)
Definition: expiry.cpp:35
virtual void fromString(const std::string &strExpiry)=0
Populate the Expiry object from strExpiry.
const QuantLib::Period & expiryPeriod() const
Return the expiry period.
Definition: expiry.cpp:64
ExpiryPeriod(const QuantLib::Period &expiryPeriod)
Constructor with expiry period.
QuantLib::Period expiryPeriod_
Definition: expiry.hpp:124
friend class boost::serialization::access
Serialization.
Definition: expiry.hpp:126
std::string toString() const override
Definition: expiry.cpp:68
bool equal_to(const Expiry &other) const override
Override in derived classes to compare specific expiries.
Definition: expiry.cpp:70
void fromString(const std::string &strExpiryPeriod) override
Definition: expiry.cpp:66
void serialize(Archive &ar, const unsigned int version)
Definition: expiry.cpp:78
ExpiryPeriod()
Default constructor.
Definition: expiry.cpp:60
void fromString(const std::string &strIndex) override
Definition: expiry.cpp:87
QuantLib::Natural expiryIndex() const
Return the future continuation expiry index.
Definition: expiry.cpp:85
QuantLib::Natural expiryIndex_
Definition: expiry.hpp:154
friend class boost::serialization::access
Serialization.
Definition: expiry.hpp:156
std::string toString() const override
Definition: expiry.cpp:93
bool equal_to(const Expiry &other) const override
Override in derived classes to compare specific expiries.
Definition: expiry.cpp:95
void serialize(Archive &ar, const unsigned int version)
Definition: expiry.cpp:103
BOOST_CLASS_EXPORT_KEY(ore::data::ExpiryDate)
@ data
Definition: log.hpp:77
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
QuantLib::ext::shared_ptr< Expiry > parseExpiry(const string &strExpiry)
Parse an Expiry from its string representation, strExpiry.
Definition: expiry.cpp:110
Serializable Credit Default Swap.
Definition: namespaces.docs:23
support for QuantLib::Date serialization
support for QuantLib::Period serialization