QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
digitalcoupon.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) 2007 Cristina Duminuco
5 Copyright (C) 2007 Giorgio Facchinetti
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21/*! \file digitalcoupon.hpp
22 \brief Floating-rate coupon with digital call/put option
23*/
24
25#ifndef quantlib_digital_coupon_hpp
26#define quantlib_digital_coupon_hpp
27
31#include <ql/position.hpp>
32#include <ql/utilities/null.hpp>
33
34namespace QuantLib {
35
36 //! Digital-payoff coupon
37 /*! Implementation of a floating-rate coupon with digital call/put option.
38 Payoffs:
39 - Coupon with cash-or-nothing Digital Call
40 rate + csi * payoffRate * Heaviside(rate-strike)
41 - Coupon with cash-or-nothing Digital Put
42 rate + csi * payoffRate * Heaviside(strike-rate)
43 where csi=+1 or csi=-1.
44 - Coupon with asset-or-nothing Digital Call
45 rate + csi * rate * Heaviside(rate-strike)
46 - Coupon with asset-or-nothing Digital Put
47 rate + csi * rate * Heaviside(strike-rate)
48 where csi=+1 or csi=-1. If nakedOption is true, the rate in the
49 payoffs is set to zero.
50 The evaluation of the coupon is made using the call/put spread
51 replication method.
52 */
53 /*! \ingroup instruments
54
55 \test
56 - the correctness of the returned value in case of Asset-or-nothing
57 embedded option is tested by pricing the digital option with
58 Cox-Rubinstein formula.
59 - the correctness of the returned value in case of deep-in-the-money
60 Asset-or-nothing embedded option is tested vs the expected values of
61 coupon and option.
62 - the correctness of the returned value in case of deep-out-of-the-money
63 Asset-or-nothing embedded option is tested vs the expected values of
64 coupon and option.
65 - the correctness of the returned value in case of Cash-or-nothing
66 embedded option is tested by pricing the digital option with
67 Reiner-Rubinstein formula.
68 - the correctness of the returned value in case of deep-in-the-money
69 Cash-or-nothing embedded option is tested vs the expected values of
70 coupon and option.
71 - the correctness of the returned value in case of deep-out-of-the-money
72 Cash-or-nothing embedded option is tested vs the expected values of
73 coupon and option.
74 - the correctness of the returned value is tested checking the correctness
75 of the call-put parity relation.
76 - the correctness of the returned value is tested by the relationship
77 between prices in case of different replication types.
78 */
80 public:
81 //! \name Constructors
82 //@{
83 //! general constructor
84 DigitalCoupon(const ext::shared_ptr<FloatingRateCoupon>& underlying,
86 Position::Type callPosition = Position::Long,
87 bool isCallITMIncluded = false,
90 Position::Type putPosition = Position::Long,
91 bool isPutITMIncluded = false,
93 ext::shared_ptr<DigitalReplication> replication = {},
94 bool nakedOption = false);
95
96 //@}
97 //! \name Obverver interface
98 //@{
99 void deepUpdate() override;
100 //@}
101 //! \name LazyObject interface
102 //@{
103 void performCalculations() const override;
104 //@}
105 //! \name Coupon interface
106 //@{
107 Rate rate() const override;
108 Rate convexityAdjustment() const override;
109 //@}
110 //@}
111 //! \name Digital inspectors
112 //@{
113 Rate callStrike() const;
114 Rate putStrike() const;
115 Rate callDigitalPayoff() const;
116 Rate putDigitalPayoff() const;
117 bool hasPut() const { return hasPutStrike_; }
118 bool hasCall() const {return hasCallStrike_; }
119 bool hasCollar() const {return (hasCallStrike_ && hasPutStrike_); }
120 bool isLongPut() const { return (putCsi_==1.); }
121 bool isLongCall() const { return (callCsi_==1.); }
122 ext::shared_ptr<FloatingRateCoupon> underlying() const { return underlying_; }
123 /*! Returns the call option rate
124 (multiplied by: nominal*accrualperiod*discount is the NPV of the option)
125 */
126 Rate callOptionRate() const;
127 /*! Returns the put option rate
128 (multiplied by: nominal*accrualperiod*discount is the NPV of the option)
129 */
130 Rate putOptionRate() const;
131 //@}
132 //! \name Visitability
133 //@{
134 void accept(AcyclicVisitor&) override;
135
136 void setPricer(const ext::shared_ptr<FloatingRateCouponPricer>& pricer) override {
137 if (pricer_ != nullptr)
139 pricer_ = pricer;
140 if (pricer_ != nullptr)
142 update();
143 underlying_->setPricer(pricer);
144 }
145
146 protected:
147 //! \name Data members
148 //@{
149 //!
150 ext::shared_ptr<FloatingRateCoupon> underlying_;
151 //! strike rate for the the call option
153 //! strike rate for the the put option
155 //! multiplicative factor of call payoff
157 //! multiplicative factor of put payoff
159 //! inclusion flag og the call payoff if the call option ends at-the-money
161 //! inclusion flag og the put payoff if the put option ends at-the-money
163 //! digital call option type: if true, cash-or-nothing, if false asset-or-nothing
165 //! digital put option type: if true, cash-or-nothing, if false asset-or-nothing
167 //! digital call option payoff rate, if any
169 //! digital put option payoff rate, if any
171 //! the left and right gaps applied in payoff replication for call
173 //! the left and right gaps applied in payoff replication for put
175 //!
176 bool hasPutStrike_ = false, hasCallStrike_ = false;
177 //! Type of replication
179 //! underlying excluded from the payoff
181
182 //@}
183 private:
184 Rate callPayoff() const;
185 Rate putPayoff() const;
186
187 };
188
189}
190
191#endif
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
Digital-payoff coupon.
Real callLeftEps_
the left and right gaps applied in payoff replication for call
void performCalculations() const override
Rate putDigitalPayoff_
digital put option payoff rate, if any
ext::shared_ptr< FloatingRateCoupon > underlying() const
void deepUpdate() override
bool isPutCashOrNothing_
digital put option type: if true, cash-or-nothing, if false asset-or-nothing
ext::shared_ptr< FloatingRateCoupon > underlying_
Rate rate() const override
accrued rate
bool isCallATMIncluded_
inclusion flag og the call payoff if the call option ends at-the-money
void accept(AcyclicVisitor &) override
bool isPutATMIncluded_
inclusion flag og the put payoff if the put option ends at-the-money
bool nakedOption_
underlying excluded from the payoff
Rate callStrike_
strike rate for the the call option
void setPricer(const ext::shared_ptr< FloatingRateCouponPricer > &pricer) override
bool isCallCashOrNothing_
digital call option type: if true, cash-or-nothing, if false asset-or-nothing
Real callCsi_
multiplicative factor of call payoff
Replication::Type replicationType_
Type of replication.
Rate callDigitalPayoff() const
Rate putStrike_
strike rate for the the put option
Rate callDigitalPayoff_
digital call option payoff rate, if any
Real putLeftEps_
the left and right gaps applied in payoff replication for put
Rate convexityAdjustment() const override
convexity adjustment
Real putCsi_
multiplicative factor of put payoff
base floating-rate coupon class
ext::shared_ptr< FloatingRateCouponPricer > pricer_
ext::shared_ptr< FloatingRateCouponPricer > pricer() const
void update() override
Definition: lazyobject.hpp:188
template class providing a null value for a given type.
Definition: null.hpp:76
Size unregisterWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:245
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
Coupon pricers.
Coupon paying a variable index-based rate.
QL_REAL Real
real number
Definition: types.hpp:50
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
null values
Short or long position.
Sub, Central, or Super replication.