QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
swaption.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) 2001, 2002, 2003 Sadruddin Rejeb
5 Copyright (C) 2006 Cristina Duminuco
6 Copyright (C) 2006 Marco Bianchetti
7 Copyright (C) 2007 StatPro Italia srl
8 Copyright (C) 2014 Ferdinando Ametrano
9 Copyright (C) 2016, 2018 Peter Caspers
10
11 This file is part of QuantLib, a free-software/open-source library
12 for financial quantitative analysts and developers - http://quantlib.org/
13
14 QuantLib is free software: you can redistribute it and/or modify it
15 under the terms of the QuantLib license. You should have received a
16 copy of the license along with this program; if not, please email
17 <quantlib-dev@lists.sf.net>. The license is also available online at
18 <http://quantlib.org/license.shtml>.
19
20 This program is distributed in the hope that it will be useful, but WITHOUT
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. See the license for more details.
23*/
24
25/*! \file swaption.hpp
26 \brief Swaption class
27*/
28
29#ifndef quantlib_instruments_swaption_hpp
30#define quantlib_instruments_swaption_hpp
31
32#include <ql/option.hpp>
37
38namespace QuantLib {
39
40 //! %settlement information
41 struct Settlement {
42 enum Type { Physical, Cash };
43 enum Method {
48 };
49 //! check consistency of settlement type and method
52 };
53
54 std::ostream& operator<<(std::ostream& out,
55 Settlement::Type type);
56
57 std::ostream& operator<<(std::ostream& out,
58 Settlement::Method method);
59
60 //! %Swaption class
61 /*! \ingroup instruments
62
63 \warning it's possible to pass an overnight-indexed swap to
64 the constructor, but the only engine to fully support
65 it is BlackSwaptionEngine; other engines will treat
66 it as a vanilla swap. This is at best a decent
67 proxy, at worst simply wrong. Use with caution.
68
69 \test
70 - the correctness of the returned value is tested by checking
71 that the price of a payer (resp. receiver) swaption
72 decreases (resp. increases) with the strike.
73 - the correctness of the returned value is tested by checking
74 that the price of a payer (resp. receiver) swaption
75 increases (resp. decreases) with the spread.
76 - the correctness of the returned value is tested by checking
77 it against that of a swaption on a swap with no spread and a
78 correspondingly adjusted fixed rate.
79 - the correctness of the returned value is tested by checking
80 it against a known good value.
81 - the correctness of the returned value of cash settled swaptions
82 is tested by checking the modified annuity against a value
83 calculated without using the Swaption class.
84
85
86 \todo add greeks and explicit exercise lag
87 */
88 class Swaption : public Option {
89 public:
90 class arguments;
91 class engine;
92 Swaption(ext::shared_ptr<FixedVsFloatingSwap> swap,
93 const ext::shared_ptr<Exercise>& exercise,
96 //! \name Observer interface
97 //@{
98 void deepUpdate() override;
99 //@}
100 //! \name Instrument interface
101 //@{
102 bool isExpired() const override;
103 void setupArguments(PricingEngine::arguments*) const override;
104 //@}
105 //! \name Inspectors
106 //@{
109 return settlementMethod_;
110 }
111 Swap::Type type() const { return swap_->type(); }
112 const ext::shared_ptr<FixedVsFloatingSwap>& underlying() const {
113 return swap_;
114 }
115 /*! \deprecated Use the Swaption::underlying method instead.
116 Deprecated in version 1.34.
117 */
118 [[deprecated("Use the Swaption::underlying method instead")]]
119 const ext::shared_ptr<VanillaSwap>& underlyingSwap() const {
120 QL_REQUIRE(vanilla_, "underlying is not a vanilla swap");
121 return vanilla_;
122 }
123 //@}
124 //! implied volatility
126 Real price,
127 const Handle<YieldTermStructure>& discountCurve,
128 Volatility guess,
129 Real accuracy = 1.0e-4,
130 Natural maxEvaluations = 100,
131 Volatility minVol = 1.0e-7,
132 Volatility maxVol = 4.0,
134 Real displacement = 0.0) const;
135 private:
136 // arguments
137 ext::shared_ptr<FixedVsFloatingSwap> swap_;
138 //Handle<YieldTermStructure> termStructure_;
141 // until we remove underlyingSwap();
142 ext::shared_ptr<VanillaSwap> vanilla_;
143 };
144
145 //! %Arguments for swaption calculation
147 public Option::arguments {
148 public:
149 arguments() = default;
150 ext::shared_ptr<FixedVsFloatingSwap> swap;
153 void validate() const override;
154 };
155
156 //! base class for swaption engines
158 : public GenericEngine<Swaption::arguments, Swaption::results> {};
159
160}
161
162#endif
Arguments for simple swap calculation
template base class for option pricing engines
Shared handle to an observable.
Definition: handle.hpp:41
basic option arguments
Definition: option.hpp:57
base option class
Definition: option.hpp:36
ext::shared_ptr< Exercise > exercise() const
Definition: option.hpp:46
Arguments for swaption calculation
Definition: swaption.hpp:147
ext::shared_ptr< FixedVsFloatingSwap > swap
Definition: swaption.hpp:150
Settlement::Method settlementMethod
Definition: swaption.hpp:152
Settlement::Type settlementType
Definition: swaption.hpp:151
void validate() const override
Definition: swaption.cpp:175
base class for swaption engines
Definition: swaption.hpp:158
Swaption class
Definition: swaption.hpp:88
void setupArguments(PricingEngine::arguments *) const override
Definition: swaption.cpp:162
Settlement::Type settlementType() const
Definition: swaption.hpp:107
bool isExpired() const override
returns whether the instrument might have value greater than zero.
Definition: swaption.cpp:158
void deepUpdate() override
Definition: swaption.cpp:153
const ext::shared_ptr< VanillaSwap > & underlyingSwap() const
Definition: swaption.hpp:119
Swap::Type type() const
Definition: swaption.hpp:111
const ext::shared_ptr< FixedVsFloatingSwap > & underlying() const
Definition: swaption.hpp:112
ext::shared_ptr< FixedVsFloatingSwap > swap_
Definition: swaption.hpp:137
Settlement::Method settlementMethod_
Definition: swaption.hpp:140
ext::shared_ptr< VanillaSwap > vanilla_
Definition: swaption.hpp:142
Volatility impliedVolatility(Real price, const Handle< YieldTermStructure > &discountCurve, Volatility guess, Real accuracy=1.0e-4, Natural maxEvaluations=100, Volatility minVol=1.0e-7, Volatility maxVol=4.0, VolatilityType type=ShiftedLognormal, Real displacement=0.0) const
implied volatility
Definition: swaption.cpp:182
Settlement::Method settlementMethod() const
Definition: swaption.hpp:108
Settlement::Type settlementType_
Definition: swaption.hpp:139
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Fixed-rate vs floating-rate swap.
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Volatility
volatility
Definition: types.hpp:78
Definition: any.hpp:35
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)
void swap(Array &v, Array &w) noexcept
Definition: array.hpp:903
Base option class.
settlement information
Definition: swaption.hpp:41
static void checkTypeAndMethodConsistency(Settlement::Type, Settlement::Method)
check consistency of settlement type and method
Definition: swaption.cpp:201
Simple fixed-rate vs Libor swap.
volatility types
Interest-rate term structure.