QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
payoffs.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2003, 2006 Ferdinando Ametrano
5 Copyright (C) 2006 Warren Chou
6 Copyright (C) 2006, 2008 StatPro Italia srl
7 Copyright (C) 2006 Chiara Fornarola
8
9 This file is part of QuantLib, a free-software/open-source library
10 for financial quantitative analysts and developers - http://quantlib.org/
11
12 QuantLib is free software: you can redistribute it and/or modify it
13 under the terms of the QuantLib license. You should have received a
14 copy of the license along with this program; if not, please email
15 <quantlib-dev@lists.sf.net>. The license is also available online at
16 <http://quantlib.org/license.shtml>.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the license for more details.
21*/
22
23/*! \file payoffs.hpp
24 \brief Payoffs for various options
25*/
26
27#ifndef quantlib_payoffs_hpp
28#define quantlib_payoffs_hpp
29
30#include <ql/option.hpp>
31#include <ql/payoff.hpp>
32
33namespace QuantLib {
34
35 //! Dummy %payoff class
36 class NullPayoff : public Payoff {
37 public:
38 //! \name Payoff interface
39 //@{
40 std::string name() const override;
41 std::string description() const override;
42 Real operator()(Real price) const override;
43 void accept(AcyclicVisitor&) override;
44 //@}
45 };
46
47
48 //! Intermediate class for put/call payoffs
49 class TypePayoff : public Payoff {
50 public:
51 Option::Type optionType() const { return type_; };
52 //! \name Payoff interface
53 //@{
54 std::string description() const override;
55 //@}
56 protected:
57 explicit TypePayoff(Option::Type type) : type_(type) {}
59 };
60
61 ////! Intermediate class for payoffs based on a fixed strike
62 //class StrikedPayoff : public Payoff {
63 // public:
64 // StrikedPayoff(Real strike) : strike_(strike) {}
65 // Real strike() const { return strike_; };
66 // //! \name Payoff interface
67 // //@{
68 // std::string description() const;
69 // //@}
70 // protected:
71 // Real strike_;
72 //};
73
74 //! %Payoff based on a floating strike
76 public:
78 //! \name Payoff interface
79 //@{
80 std::string name() const override { return "FloatingType"; }
81 Real operator()(Real price, Real strike) const;
82 Real operator()(Real price) const override;
83 void accept(AcyclicVisitor&) override;
84 //@}
85 };
86
87 //! Intermediate class for payoffs based on a fixed strike
89 //, public StrikedPayoff
90 {
91 public:
92 //! \name Payoff interface
93 //@{
94 std::string description() const override;
95 //@}
96 Real strike() const { return strike_; };
97 protected:
100 : TypePayoff(type), strike_(strike) {}
102 };
103
104 //! Plain-vanilla payoff
106 public:
108 Real strike)
109 : StrikedTypePayoff(type, strike) {}
110 //! \name Payoff interface
111 //@{
112 std::string name() const override { return "Vanilla"; }
113 Real operator()(Real price) const override;
114 void accept(AcyclicVisitor&) override;
115 //@}
116 };
117
118 //! %Payoff with strike expressed as percentage
120 public:
122 Real moneyness)
123 : StrikedTypePayoff(type, moneyness) {}
124 //! \name Payoff interface
125 //@{
126 std::string name() const override { return "PercentageStrike"; }
127 Real operator()(Real price) const override;
128 void accept(AcyclicVisitor&) override;
129 //@}
130 };
131
132 /*! Definitions of Binary path-independent payoffs used below,
133 can be found in M. Rubinstein, E. Reiner:"Unscrambling The Binary Code", Risk, Vol.4 no.9,1991.
134 (see: http://www.in-the-money.com/artandpap/Binary%20Options.doc)
135 */
136
137 //! Binary asset-or-nothing payoff
139 public:
141 Real strike)
142 : StrikedTypePayoff(type, strike) {}
143 //! \name Payoff interface
144 //@{
145 std::string name() const override { return "AssetOrNothing"; }
146 Real operator()(Real price) const override;
147 void accept(AcyclicVisitor&) override;
148 //@}
149 };
150
151 //! Binary cash-or-nothing payoff
153 public:
155 Real strike,
158 //! \name Payoff interface
159 //@{
160 std::string name() const override { return "CashOrNothing"; }
161 std::string description() const override;
162 Real operator()(Real price) const override;
163 void accept(AcyclicVisitor&) override;
164 //@}
165 Real cashPayoff() const { return cashPayoff_;}
166 protected:
168 };
169
170 //! Binary gap payoff
171 /*! This payoff is equivalent to being a) long a PlainVanillaPayoff at
172 the first strike (same Call/Put type) and b) short a
173 CashOrNothingPayoff at the first strike (same Call/Put type) with
174 cash payoff equal to the difference between the second and the first
175 strike.
176 \warning this payoff can be negative depending on the strikes
177 */
179 public:
181 Real strike,
182 Real secondStrike) // a.k.a. payoff strike
184 //! \name Payoff interface
185 //@{
186 std::string name() const override { return "Gap"; }
187 std::string description() const override;
188 Real operator()(Real price) const override;
189 void accept(AcyclicVisitor&) override;
190 //@}
191 Real secondStrike() const { return secondStrike_;}
192 protected:
194 };
195
196 //! Binary supershare and superfund payoffs
197
198 //! Binary superfund payoff
199 /*! Superfund sometimes also called "supershare", which can lead to ambiguity; within QuantLib
200 the terms supershare and superfund are used consistently according to the definitions in
201 Bloomberg OVX function's help pages.
202 */
203 /*! This payoff is equivalent to being (1/lowerstrike) a) long (short) an AssetOrNothing
204 Call (Put) at the lower strike and b) short (long) an AssetOrNothing
205 Call (Put) at the higher strike
206 */
208 public:
213 QL_REQUIRE(strike>0.0,
214 "strike (" << strike << ") must be "
215 "positive");
217 "second strike (" << secondStrike << ") must be "
218 "higher than first strike (" << strike << ")");
219 }
220 //! \name Payoff interface
221 //@{
222 std::string name() const override { return "SuperFund"; }
223 Real operator()(Real price) const override;
224 void accept(AcyclicVisitor&) override;
225 //@}
226 Real secondStrike() const { return secondStrike_;}
227 protected:
229 };
230
231 //! Binary supershare payoff
233 public:
241 "second strike (" << secondStrike << ") must be "
242 "higher than first strike (" << strike << ")");}
243
244 //! \name Payoff interface
245 //@{
246 std::string name() const override { return "SuperShare"; }
247 std::string description() const override;
248 Real operator()(Real price) const override;
249 void accept(AcyclicVisitor&) override;
250 //@}
251 Real secondStrike() const { return secondStrike_;}
252 Real cashPayoff() const { return cashPayoff_;}
253 protected:
256 };
257}
258
259#endif
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
Binary asset-or-nothing payoff.
Definition: payoffs.hpp:138
Real operator()(Real price) const override
Definition: payoffs.cpp:129
void accept(AcyclicVisitor &) override
Definition: payoffs.cpp:140
AssetOrNothingPayoff(Option::Type type, Real strike)
Definition: payoffs.hpp:140
std::string name() const override
Definition: payoffs.hpp:145
Binary cash-or-nothing payoff.
Definition: payoffs.hpp:152
Real operator()(Real price) const override
Definition: payoffs.cpp:154
std::string description() const override
Definition: payoffs.cpp:148
void accept(AcyclicVisitor &) override
Definition: payoffs.cpp:165
std::string name() const override
Definition: payoffs.hpp:160
CashOrNothingPayoff(Option::Type type, Real strike, Real cashPayoff)
Definition: payoffs.hpp:154
Payoff based on a floating strike
Definition: payoffs.hpp:75
void accept(AcyclicVisitor &) override
Definition: payoffs.cpp:83
std::string name() const override
Definition: payoffs.hpp:80
FloatingTypePayoff(Option::Type type)
Definition: payoffs.hpp:77
Real operator()(Real price, Real strike) const
Definition: payoffs.cpp:65
Binary gap payoff.
Definition: payoffs.hpp:178
Real operator()(Real price) const override
Definition: payoffs.cpp:178
std::string description() const override
Definition: payoffs.cpp:172
GapPayoff(Option::Type type, Real strike, Real secondStrike)
Definition: payoffs.hpp:180
void accept(AcyclicVisitor &) override
Definition: payoffs.cpp:189
Real secondStrike() const
Definition: payoffs.hpp:191
std::string name() const override
Definition: payoffs.hpp:186
Dummy payoff class.
Definition: payoffs.hpp:36
Real operator()(Real price) const override
Definition: payoffs.cpp:35
std::string description() const override
Definition: payoffs.cpp:31
void accept(AcyclicVisitor &) override
Definition: payoffs.cpp:39
std::string name() const override
Definition: payoffs.cpp:27
base option class
Definition: option.hpp:36
Abstract base class for option payoffs.
Definition: payoff.hpp:36
Payoff with strike expressed as percentage
Definition: payoffs.hpp:119
Real operator()(Real price) const override
Definition: payoffs.cpp:110
void accept(AcyclicVisitor &) override
Definition: payoffs.cpp:121
PercentageStrikePayoff(Option::Type type, Real moneyness)
Definition: payoffs.hpp:121
std::string name() const override
Definition: payoffs.hpp:126
Plain-vanilla payoff.
Definition: payoffs.hpp:105
Real operator()(Real price) const override
Definition: payoffs.cpp:91
PlainVanillaPayoff(Option::Type type, Real strike)
Definition: payoffs.hpp:107
void accept(AcyclicVisitor &) override
Definition: payoffs.cpp:102
std::string name() const override
Definition: payoffs.hpp:112
Intermediate class for payoffs based on a fixed strike.
Definition: payoffs.hpp:90
std::string description() const override
Definition: payoffs.cpp:76
StrikedTypePayoff(Option::Type type, Real strike)
Definition: payoffs.hpp:98
Binary supershare and superfund payoffs.
Definition: payoffs.hpp:207
Real operator()(Real price) const override
Definition: payoffs.cpp:197
void accept(AcyclicVisitor &) override
Definition: payoffs.cpp:201
Real secondStrike() const
Definition: payoffs.hpp:226
std::string name() const override
Definition: payoffs.hpp:222
SuperFundPayoff(Real strike, Real secondStrike)
Definition: payoffs.hpp:209
Binary supershare payoff.
Definition: payoffs.hpp:232
SuperSharePayoff(Real strike, Real secondStrike, Real cashPayoff)
Definition: payoffs.hpp:234
Real operator()(Real price) const override
Definition: payoffs.cpp:214
std::string description() const override
Definition: payoffs.cpp:208
void accept(AcyclicVisitor &) override
Definition: payoffs.cpp:218
Real secondStrike() const
Definition: payoffs.hpp:251
std::string name() const override
Definition: payoffs.hpp:246
Intermediate class for put/call payoffs.
Definition: payoffs.hpp:49
TypePayoff(Option::Type type)
Definition: payoffs.hpp:57
std::string description() const override
Definition: payoffs.cpp:49
Option::Type type_
Definition: payoffs.hpp:58
Option::Type optionType() const
Definition: payoffs.hpp:51
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
Base option class.
Option payoff classes.