Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
strike.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/strike.hpp
20 \brief Classes for representing a strike using various conventions.
21 \ingroup marketdata
22*/
23
24#pragma once
25
26#include <ql/experimental/fx/deltavolquote.hpp>
27#include <ql/option.hpp>
28#include <ql/types.hpp>
29
30#include <boost/optional.hpp>
31#include <boost/serialization/base_object.hpp>
32#include <boost/serialization/export.hpp>
33#include <boost/serialization/version.hpp>
34#include <boost/serialization/optional.hpp>
35#include <ql/shared_ptr.hpp>
36
37namespace ore {
38namespace data {
39
40/*! Abstract base class to hold information that describes a strike.
41 Need to use Base in class Name to differentiate from existing ore::data::Strike.
42*/
44public:
45 virtual ~BaseStrike() {}
46
47 //! Populate the Strike object from \p strStrike
48 virtual void fromString(const std::string& strStrike) = 0;
49
50 //! Write the Strike object to string
51 virtual std::string toString() const = 0;
52
53 //! Will be used for Strike comparison.
54 friend bool operator==(const BaseStrike& lhs, const BaseStrike& rhs);
55
56protected:
57 //! Override in derived classes to compare specific Strikes.
58 virtual bool equal_to(const BaseStrike& other) const = 0;
59
60private:
61 //! Serialization
63 template <class Archive> void serialize(Archive& ar, const unsigned int version);
64};
65
66/*! Strike implementation where the strike is described by a single number that represents the absolute strike level.
67 */
68class AbsoluteStrike : public BaseStrike {
69public:
70 //! Default constructor.
72
73 //! Constructor with explicit strike.
74 AbsoluteStrike(QuantLib::Real strike);
75
76 //! Return the absolute strike level.
77 QuantLib::Real strike() const;
78
79 /*! Populate AbsoluteStrike object from \p strStrike which should be a number.
80 An exception is thrown if \p strStrike cannot be parsed as a \c QuantLib::Real.
81 */
82 void fromString(const std::string& strStrike) override;
83
84 /*! Writes the AbsoluteStrike object to string. This returns the string representation of
85 the absolute strike number.
86 */
87 std::string toString() const override;
88
89protected:
90 bool equal_to(const BaseStrike& other) const override;
91
92private:
93 QuantLib::Real strike_;
94 //! Serialization
96 template <class Archive> void serialize(Archive& ar, const unsigned int version);
97};
98
99/*! Strike implementation where the strike is described by a delta type, an option type and a delta level.
100 */
101class DeltaStrike : public BaseStrike {
102public:
103 //! Default constructor.
104 DeltaStrike();
105
106 //! Explicit constructor
107 DeltaStrike(QuantLib::DeltaVolQuote::DeltaType deltaType, QuantLib::Option::Type optionType, QuantLib::Real delta);
108
109 //! \name Inspectors
110 //@{
111 //! Return the delta type
112 QuantLib::DeltaVolQuote::DeltaType deltaType() const;
113
114 //! Return the option type
115 QuantLib::Option::Type optionType() const;
116
117 //! Return the delta level
118 QuantLib::Real delta() const;
119 //@}
120
121 /*! Populate DeltaStrike object from \p strStrike.
122
123 The \p strStrike is expected to be of the form `DEL / Spot|Fwd|PaSpot|PaFwd / Call|Put / DELTA_VALUE`. An
124 exception is thrown if \p strStrike is not of this form and cannot be parsed properly.
125 */
126 void fromString(const std::string& strStrike) override;
127
128 /*! Writes the DeltaStrike object to string.
129
130 The string representation of the DeltaStrike object is of the form
131 `DEL / Spot|Fwd|PaSpot|PaFwd / Call|Put / DELTA_VALUE`.
132 */
133 std::string toString() const override;
134
135protected:
136 bool equal_to(const BaseStrike& other) const override;
137
138private:
139 QuantLib::DeltaVolQuote::DeltaType deltaType_;
140 QuantLib::Option::Type optionType_;
141 QuantLib::Real delta_;
142 //! Serialization
144 template <class Archive> void serialize(Archive& ar, const unsigned int version);
145};
146
147/*! Strike implementation for an at-the-money strike of various types.
148 */
149class AtmStrike : public BaseStrike {
150public:
151 //! Default constructor.
152 AtmStrike();
153
154 /*! Explicit constructor. Note that:
155 - an \p atmType of \c AtmNull throws an error.
156 - if \p atmType is \c AtmDeltaNeutral, a \c deltaType is needed.
157 - if \p atmType is not \c AtmDeltaNeutral, \c deltaType should not be provided.
158 - if \p atmType is \c AtmPutCall50, \p deltaType must be \c DeltaVolQuote::Fwd.
159 */
160 AtmStrike(QuantLib::DeltaVolQuote::AtmType atmType,
161 boost::optional<QuantLib::DeltaVolQuote::DeltaType> deltaType = boost::none);
162
163 //! \name Inspectors
164 //@{
165 //! Return the ATM type
166 QuantLib::DeltaVolQuote::AtmType atmType() const;
167
168 //! Return the delta type
169 boost::optional<QuantLib::DeltaVolQuote::DeltaType> deltaType() const;
170 //@}
171
172 /*! Populate AtmStrike object from \p strStrike.
173
174 The \p strStrike is expected to be of the form:
175 `ATM / AtmSpot|AtmFwd|AtmDeltaNeutral|AtmVegaMax|AtmGammaMax|AtmPutCall50` followed by an optional
176 `/ DEL / Spot|Fwd|PaSpot|PaFwd` to specify the delta if it is needed. An exception is thrown if \p strStrike
177 is not of this form and cannot be parsed properly.
178 */
179 void fromString(const std::string& strStrike) override;
180
181 /*! Writes the AtmStrike object to string.
182
183 The string representation of the DeltaStrike object is of the form
184 `ATM / AtmSpot|AtmFwd|AtmDeltaNeutral|AtmVegaMax|AtmGammaMax|AtmPutCall50` followed by an optional
185 `/ DEL / Spot|Fwd|PaSpot|PaFwd` if the delta type has been populated.
186 */
187 std::string toString() const override;
188
189protected:
190 bool equal_to(const BaseStrike& other) const override;
191
192private:
193 QuantLib::DeltaVolQuote::AtmType atmType_;
194 boost::optional<QuantLib::DeltaVolQuote::DeltaType> deltaType_;
195
196 //! Perform validation
197 void check() const;
198
199 //! Serialization
201 template <class Archive> void serialize(Archive& ar, const unsigned int version);
202};
203
204/*! Strike implementation where the strike is described by a moneyness type and a moneyness level.
205 */
207public:
208 /*! The MoneynessStrike type.
209 - When the moneyness type is \c Spot, the moneyness level will be interpreted as the implicit strike divided
210 by the spot value.
211 - When the moneyness type is \c Forward, the moneyness level will be interpreted as the implicit strike
212 divided by the forward value.
213 */
214 enum class Type { Spot, Forward };
215
216 //! Default constructor.
218
219 //! Explicit constructor.
221
222 //! \name Inspectors
223 //@{
224 //! Return the moneyness type
225 Type type() const;
226
227 //! Return the moneyness level.
228 QuantLib::Real moneyness() const;
229 //@}
230
231 /*! Populate MoneynessStrike object from \p strStrike.
232
233 The \p strStrike is expected to be of the form `MNY / Spot|Fwd / MONEYNESS_VALUE`.
234 */
235 void fromString(const std::string& strStrike) override;
236
237 /*! Writes the MoneynessStrike object to string.
238
239 The string representation of the MoneynessStrike object is of the form `MNY / Spot|Fwd / MONEYNESS_VALUE`.
240 */
241 std::string toString() const override;
242
243protected:
244 bool equal_to(const BaseStrike& other) const override;
245
246private:
248 QuantLib::Real moneyness_;
249
250 //! Serialization
252 template <class Archive> void serialize(Archive& ar, const unsigned int version);
253};
254
255//! Write \p strike to stream.
256std::ostream& operator<<(std::ostream& os, const BaseStrike& strike);
257
258//! Write \p deltaType to stream. Not provided in QuantLib so add it here.
259std::ostream& operator<<(std::ostream& os, QuantLib::DeltaVolQuote::DeltaType type);
260
261//! Write \p atmType to stream. Not provided in QuantLib so add it here.
262std::ostream& operator<<(std::ostream& os, QuantLib::DeltaVolQuote::AtmType type);
263
264//! Write MoneynessStrike::Type, \p type, to stream.
265std::ostream& operator<<(std::ostream& os, MoneynessStrike::Type type);
266
267//! Parse MoneynessStrike::Type from \p type
268MoneynessStrike::Type parseMoneynessType(const std::string& type);
269
270//! Parse a Strike from its string representation, \p strStrike.
271QuantLib::ext::shared_ptr<BaseStrike> parseBaseStrike(const std::string& strStrike);
272
273template <class Archive> void registerBaseStrike(Archive& ar) {
274 ar.template register_type<AbsoluteStrike>();
275 ar.template register_type<DeltaStrike>();
276 ar.template register_type<AtmStrike>();
277 ar.template register_type<MoneynessStrike>();
278}
279
280} // namespace data
281} // namespace ore
282
bool equal_to(const BaseStrike &other) const override
Override in derived classes to compare specific Strikes.
Definition: strike.cpp:50
void serialize(Archive &ar, const unsigned int version)
Definition: strike.cpp:291
void fromString(const std::string &strStrike) override
Definition: strike.cpp:46
QuantLib::Real strike() const
Return the absolute strike level.
Definition: strike.cpp:44
AbsoluteStrike(QuantLib::Real strike)
Constructor with explicit strike.
friend class boost::serialization::access
Serialization.
Definition: strike.hpp:95
std::string toString() const override
Definition: strike.cpp:48
QuantLib::Real strike_
Definition: strike.hpp:93
AbsoluteStrike()
Default constructor.
Definition: strike.cpp:40
QuantLib::DeltaVolQuote::AtmType atmType_
Definition: strike.hpp:193
void check() const
Perform validation.
Definition: strike.cpp:154
bool equal_to(const BaseStrike &other) const override
Override in derived classes to compare specific Strikes.
Definition: strike.cpp:145
void fromString(const std::string &strStrike) override
Definition: strike.cpp:109
boost::optional< QuantLib::DeltaVolQuote::DeltaType > deltaType() const
Return the delta type.
Definition: strike.cpp:107
AtmStrike()
Default constructor.
Definition: strike.cpp:98
QuantLib::DeltaVolQuote::AtmType atmType() const
Return the ATM type.
Definition: strike.cpp:105
AtmStrike(QuantLib::DeltaVolQuote::AtmType atmType, boost::optional< QuantLib::DeltaVolQuote::DeltaType > deltaType=boost::none)
friend class boost::serialization::access
Serialization.
Definition: strike.hpp:200
std::string toString() const override
Definition: strike.cpp:130
void serialize(Archive &ar, const unsigned int version)
Definition: strike.cpp:303
boost::optional< QuantLib::DeltaVolQuote::DeltaType > deltaType_
Definition: strike.hpp:194
virtual bool equal_to(const BaseStrike &other) const =0
Override in derived classes to compare specific Strikes.
virtual void fromString(const std::string &strStrike)=0
Populate the Strike object from strStrike.
virtual std::string toString() const =0
Write the Strike object to string.
friend class boost::serialization::access
Serialization.
Definition: strike.hpp:62
friend bool operator==(const BaseStrike &lhs, const BaseStrike &rhs)
Will be used for Strike comparison.
Definition: strike.cpp:38
virtual ~BaseStrike()
Definition: strike.hpp:45
void serialize(Archive &ar, const unsigned int version)
Definition: strike.cpp:289
QuantLib::Real delta() const
Return the delta level.
Definition: strike.cpp:67
bool equal_to(const BaseStrike &other) const override
Override in derived classes to compare specific Strikes.
Definition: strike.cpp:90
DeltaStrike()
Default constructor.
Definition: strike.cpp:58
void fromString(const std::string &strStrike) override
Definition: strike.cpp:69
DeltaStrike(QuantLib::DeltaVolQuote::DeltaType deltaType, QuantLib::Option::Type optionType, QuantLib::Real delta)
Explicit constructor.
QuantLib::DeltaVolQuote::DeltaType deltaType_
Definition: strike.hpp:139
QuantLib::Option::Type optionType_
Definition: strike.hpp:140
QuantLib::DeltaVolQuote::DeltaType deltaType() const
Return the delta type.
Definition: strike.cpp:63
friend class boost::serialization::access
Serialization.
Definition: strike.hpp:143
std::string toString() const override
Definition: strike.cpp:82
QuantLib::Option::Type optionType() const
Return the option type.
Definition: strike.cpp:65
QuantLib::Real delta_
Definition: strike.hpp:141
void serialize(Archive &ar, const unsigned int version)
Definition: strike.cpp:296
bool equal_to(const BaseStrike &other) const override
Override in derived classes to compare specific Strikes.
Definition: strike.cpp:195
MoneynessStrike(Type type, QuantLib::Real moneyness)
Explicit constructor.
void fromString(const std::string &strStrike) override
Definition: strike.cpp:175
QuantLib::Real moneyness_
Definition: strike.hpp:248
QuantLib::Real moneyness() const
Return the moneyness level.
Definition: strike.cpp:173
friend class boost::serialization::access
Serialization.
Definition: strike.hpp:251
std::string toString() const override
Definition: strike.cpp:187
MoneynessStrike()
Default constructor.
Definition: strike.cpp:167
Type type() const
Return the moneyness type.
Definition: strike.cpp:171
void serialize(Archive &ar, const unsigned int version)
Definition: strike.cpp:309
@ data
Definition: log.hpp:77
BOOST_CLASS_EXPORT_KEY(ore::data::AbsoluteStrike)
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
MoneynessStrike::Type parseMoneynessType(const string &type)
Parse MoneynessStrike::Type from type.
Definition: strike.cpp:252
QuantLib::ext::shared_ptr< BaseStrike > parseBaseStrike(const string &strStrike)
Parse a Strike from its string representation, strStrike.
Definition: strike.cpp:262
void registerBaseStrike(Archive &ar)
Definition: strike.hpp:273
Serializable Credit Default Swap.
Definition: namespaces.docs:23