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>
33#include <ql/instruments/vanillaswap.hpp>
34#include <ql/termstructures/yieldtermstructure.hpp>
35#include <ql/termstructures/volatility/volatilitytype.hpp>
36
37namespace QuantLib {
38
39 //! %settlement information
40 struct Settlement {
41 enum Type { Physical, Cash };
42 enum Method {
43 PhysicalOTC,
44 PhysicalCleared,
45 CollateralizedCashPrice,
46 ParYieldCurve
47 };
48 //! check consistency of settlement type and method
49 static void checkTypeAndMethodConsistency(Settlement::Type,
50 Settlement::Method);
51 };
52
53 std::ostream& operator<<(std::ostream& out,
54 Settlement::Type type);
55
56 std::ostream& operator<<(std::ostream& out,
57 Settlement::Method method);
58
59 //! %Swaption class
60 /*! \ingroup instruments
61
62 \test
63 - the correctness of the returned value is tested by checking
64 that the price of a payer (resp. receiver) swaption
65 decreases (resp. increases) with the strike.
66 - the correctness of the returned value is tested by checking
67 that the price of a payer (resp. receiver) swaption
68 increases (resp. decreases) with the spread.
69 - the correctness of the returned value is tested by checking
70 it against that of a swaption on a swap with no spread and a
71 correspondingly adjusted fixed rate.
72 - the correctness of the returned value is tested by checking
73 it against a known good value.
74 - the correctness of the returned value of cash settled swaptions
75 is tested by checking the modified annuity against a value
76 calculated without using the Swaption class.
77
78
79 \todo add greeks and explicit exercise lag
80 */
81 class Swaption : public Option {
82 public:
83 class arguments;
84 class engine;
85 Swaption(ext::shared_ptr<VanillaSwap> swap,
86 const ext::shared_ptr<Exercise>& exercise,
87 Settlement::Type delivery = Settlement::Physical,
88 Settlement::Method settlementMethod = Settlement::PhysicalOTC);
89 //! \name Observer interface
90 //@{
91 void deepUpdate() override;
92 //@}
93 //! \name Instrument interface
94 //@{
95 bool isExpired() const override;
96 void setupArguments(PricingEngine::arguments*) const override;
97 //@}
98 //! \name Inspectors
99 //@{
100 Settlement::Type settlementType() const { return settlementType_; }
101 Settlement::Method settlementMethod() const {
102 return settlementMethod_;
103 }
104 Swap::Type type() const { return swap_->type(); }
105 const ext::shared_ptr<VanillaSwap>& underlyingSwap() const {
106 return swap_;
107 }
108 //@}
109 //! implied volatility
110 Volatility impliedVolatility(
111 Real price,
112 const Handle<YieldTermStructure>& discountCurve,
113 Volatility guess,
114 Real accuracy = 1.0e-4,
115 Natural maxEvaluations = 100,
116 Volatility minVol = 1.0e-7,
117 Volatility maxVol = 4.0,
118 VolatilityType type = ShiftedLognormal,
119 Real displacement = 0.0) const;
120 private:
121 // arguments
122 ext::shared_ptr<VanillaSwap> swap_;
123 //Handle<YieldTermStructure> termStructure_;
124 Settlement::Type settlementType_;
125 Settlement::Method settlementMethod_;
126 };
127
128 //! %Arguments for swaption calculation
129 class Swaption::arguments : public VanillaSwap::arguments,
130 public Option::arguments {
131 public:
132 arguments() = default;
133 ext::shared_ptr<VanillaSwap> swap;
134 Settlement::Type settlementType = Settlement::Physical;
135 Settlement::Method settlementMethod;
136 void validate() const override;
137 };
138
139 //! base class for swaption engines
140 class Swaption::engine
141 : public GenericEngine<Swaption::arguments, Swaption::results> {};
142
143}
144
145#endif
146

source code of quantlib/ql/instruments/swaption.hpp