QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
payoffs.hpp
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
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
36 class NullPayoff : public Payoff {
37 public:
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;
45 };
46
47
49 class TypePayoff : public Payoff {
50 public:
51 Option::Type optionType() const { return type_; };
53
54 std::string description() const override;
56 protected:
57 explicit TypePayoff(Option::Type type) : type_(type) {}
59 };
60
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
76 public:
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;
85 };
86
89 //, public StrikedPayoff
90 {
91 public:
93
94 std::string description() const override;
96 Real strike() const { return strike_; };
97 protected:
100 : TypePayoff(type), strike_(strike) {}
102 };
103
106 public:
108 Real strike)
109 : StrikedTypePayoff(type, strike) {}
111
112 std::string name() const override { return "Vanilla"; }
113 Real operator()(Real price) const override;
114 void accept(AcyclicVisitor&) override;
116 };
117
120 public:
122 Real moneyness)
123 : StrikedTypePayoff(type, moneyness) {}
125
126 std::string name() const override { return "PercentageStrike"; }
127 Real operator()(Real price) const override;
128 void accept(AcyclicVisitor&) override;
130 };
131
139 public:
141 Real strike)
142 : StrikedTypePayoff(type, strike) {}
144
145 std::string name() const override { return "AssetOrNothing"; }
146 Real operator()(Real price) const override;
147 void accept(AcyclicVisitor&) override;
149 };
150
153 public:
155 Real strike,
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;
165 Real cashPayoff() const { return cashPayoff_;}
166 protected:
168 };
169
171
179 public:
181 Real strike,
182 Real secondStrike) // a.k.a. payoff strike
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;
191 Real secondStrike() const { return secondStrike_;}
192 protected:
194 };
195
197
199
208 public:
213 QL_REQUIRE(strike>0.0,
214 "strike (" << strike << ") must be "
215 "positive");
216 QL_REQUIRE(secondStrike>strike,
217 "second strike (" << secondStrike << ") must be "
218 "higher than first strike (" << strike << ")");
219 }
221
222 std::string name() const override { return "SuperFund"; }
223 Real operator()(Real price) const override;
224 void accept(AcyclicVisitor&) override;
226 Real secondStrike() const { return secondStrike_;}
227 protected:
229 };
230
233 public:
240 QL_REQUIRE(secondStrike>strike,
241 "second strike (" << secondStrike << ") must be "
242 "higher than first strike (" << strike << ")");}
243
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;
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
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35