QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
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:
91 class arguments;
92 class engine;
93 Swaption(ext::shared_ptr<FixedVsFloatingSwap> swap,
94 const ext::shared_ptr<Exercise>& exercise,
97 //! \name Observer interface
98 //@{
99 void deepUpdate() override;
100 //@}
101 //! \name Instrument interface
102 //@{
103 bool isExpired() const override;
104 void setupArguments(PricingEngine::arguments*) const override;
105 //@}
106 //! \name Inspectors
107 //@{
110 return settlementMethod_;
111 }
112 Swap::Type type() const { return swap_->type(); }
113 const ext::shared_ptr<FixedVsFloatingSwap>& underlying() const {
114 return swap_;
115 }
116 //@}
117 //! implied volatility
119 Real price,
120 const Handle<YieldTermStructure>& discountCurve,
121 Volatility guess,
122 Real accuracy = 1.0e-4,
123 Natural maxEvaluations = 100,
124 Volatility minVol = 1.0e-7,
125 Volatility maxVol = 4.0,
127 Real displacement = 0.0,
128 PriceType priceType = Spot) const;
129 private:
130 // arguments
131 ext::shared_ptr<FixedVsFloatingSwap> swap_;
132 //Handle<YieldTermStructure> termStructure_;
135 // until we remove underlyingSwap();
136 ext::shared_ptr<VanillaSwap> vanilla_;
137 };
138
139 //! %Arguments for swaption calculation
141 public Option::arguments {
142 public:
143 arguments() = default;
144 ext::shared_ptr<FixedVsFloatingSwap> swap;
147 void validate() const override;
148 };
149
150 //! base class for swaption engines
152 : public GenericEngine<Swaption::arguments, Swaption::results> {};
153
154}
155
156#endif
Arguments for simple swap calculation
Abstract base forward class.
Definition: forward.hpp:66
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:141
ext::shared_ptr< FixedVsFloatingSwap > swap
Definition: swaption.hpp:144
Settlement::Method settlementMethod
Definition: swaption.hpp:146
Settlement::Type settlementType
Definition: swaption.hpp:145
void validate() const override
Definition: swaption.cpp:175
base class for swaption engines
Definition: swaption.hpp:152
Swaption class
Definition: swaption.hpp:88
void setupArguments(PricingEngine::arguments *) const override
Definition: swaption.cpp:162
Settlement::Type settlementType() const
Definition: swaption.hpp:108
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
Swap::Type type() const
Definition: swaption.hpp:112
const ext::shared_ptr< FixedVsFloatingSwap > & underlying() const
Definition: swaption.hpp:113
ext::shared_ptr< FixedVsFloatingSwap > swap_
Definition: swaption.hpp:131
Settlement::Method settlementMethod_
Definition: swaption.hpp:134
ext::shared_ptr< VanillaSwap > vanilla_
Definition: swaption.hpp:136
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, PriceType priceType=Spot) const
implied volatility
Definition: swaption.cpp:182
Settlement::Method settlementMethod() const
Definition: swaption.hpp:109
Settlement::Type settlementType_
Definition: swaption.hpp:133
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:37
PriceType
Price types.
Definition: prices.hpp:35
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)
void swap(Array &v, Array &w) noexcept
Definition: array.hpp:891
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:207
Simple fixed-rate vs Libor swap.
volatility types
Interest-rate term structure.