1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2002, 2003 RiskMap srl
5 Copyright (C) 2003, 2004, 2005, 2006 StatPro Italia srl
6 Copyright (C) 2015 Peter Caspers
7 Copyright (C) 2015 Michael von den Driesch
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
23/*! \file optionletvolatilitystructure.hpp
24 \brief optionlet (caplet/floorlet) volatility structure
25*/
26
27#ifndef quantlib_optionlet_volatility_structure_hpp
28#define quantlib_optionlet_volatility_structure_hpp
29
30#include <ql/termstructures/voltermstructure.hpp>
31#include <ql/termstructures/volatility/optionlet/optionletstripper.hpp>
32#include <ql/termstructures/volatility/volatilitytype.hpp>
33
34namespace QuantLib {
35
36 class SmileSection;
37
38 //! Optionlet (caplet/floorlet) volatility structure
39 /*! This class is purely abstract and defines the interface of
40 concrete structures which will be derived from this one.
41 */
42 class OptionletVolatilityStructure : public VolatilityTermStructure {
43 public:
44 /*! \name Constructors
45 See the TermStructure documentation for issues regarding
46 constructors.
47 */
48 //@{
49 //! default constructor
50 /*! \warning term structures initialized by means of this
51 constructor must manage their own reference date
52 by overriding the referenceDate() method.
53 */
54 OptionletVolatilityStructure(BusinessDayConvention bdc = Following,
55 const DayCounter& dc = DayCounter());
56 //! initialize with a fixed reference date
57 OptionletVolatilityStructure(const Date& referenceDate,
58 const Calendar& cal,
59 BusinessDayConvention bdc,
60 const DayCounter& dc = DayCounter());
61 //! calculate the reference date based on the global evaluation date
62 OptionletVolatilityStructure(Natural settlementDays,
63 const Calendar&,
64 BusinessDayConvention bdc,
65 const DayCounter& dc = DayCounter());
66 //@}
67 ~OptionletVolatilityStructure() override = default;
68 //! \name Volatility and Variance
69 //@{
70 //! returns the volatility for a given option tenor and strike rate
71 Volatility volatility(const Period& optionTenor,
72 Rate strike,
73 bool extrapolate = false) const;
74 //! returns the volatility for a given option date and strike rate
75 Volatility volatility(const Date& optionDate,
76 Rate strike,
77 bool extrapolate = false) const;
78 //! returns the volatility for a given option time and strike rate
79 Volatility volatility(Time optionTime,
80 Rate strike,
81 bool extrapolate = false) const;
82
83 //! returns the Black variance for a given option tenor and strike rate
84 Real blackVariance(const Period& optionTenor,
85 Rate strike,
86 bool extrapolate = false) const;
87 //! returns the Black variance for a given option date and strike rate
88 Real blackVariance(const Date& optionDate,
89 Rate strike,
90 bool extrapolate = false) const;
91 //! returns the Black variance for a given option time and strike rate
92 Real blackVariance(Time optionTime,
93 Rate strike,
94 bool extrapolate = false) const;
95
96 //! returns the smile for a given option tenor
97 ext::shared_ptr<SmileSection> smileSection(const Period& optionTenor,
98 bool extr = false) const;
99 //! returns the smile for a given option date
100 ext::shared_ptr<SmileSection> smileSection(const Date& optionDate,
101 bool extr = false) const;
102 //! returns the smile for a given option time
103 ext::shared_ptr<SmileSection> smileSection(Time optionTime,
104 bool extr = false) const;
105 //@}
106 virtual VolatilityType volatilityType() const;
107 virtual Real displacement() const;
108
109 protected:
110 virtual ext::shared_ptr<SmileSection> smileSectionImpl(
111 const Date& optionDate) const;
112 //! implements the actual smile calculation in derived classes
113 virtual ext::shared_ptr<SmileSection> smileSectionImpl(
114 Time optionTime) const = 0;
115 virtual Volatility volatilityImpl(const Date& optionDate,
116 Rate strike) const;
117 //! implements the actual volatility calculation in derived classes
118 virtual Volatility volatilityImpl(Time optionTime,
119 Rate strike) const = 0;
120 };
121
122 // inline definitions
123
124 // 1. Period-based methods convert Period to Date and then
125 // use the equivalent Date-based methods
126 inline Volatility
127 OptionletVolatilityStructure::volatility(const Period& optionTenor,
128 Rate strike,
129 bool extrapolate) const {
130 Date optionDate = optionDateFromTenor(p: optionTenor);
131 return volatility(optionDate, strike, extrapolate);
132 }
133
134 inline
135 Real OptionletVolatilityStructure::blackVariance(const Period& optionTenor,
136 Rate strike,
137 bool extrapolate) const {
138 Date optionDate = optionDateFromTenor(p: optionTenor);
139 return blackVariance(optionDate, strike, extrapolate);
140 }
141
142 inline ext::shared_ptr<SmileSection>
143 OptionletVolatilityStructure::smileSection(const Period& optionTenor,
144 bool extrapolate) const {
145 Date optionDate = optionDateFromTenor(p: optionTenor);
146 return smileSection(optionDate, extr: extrapolate);
147 }
148
149 // 2. blackVariance methods rely on volatility methods
150 inline
151 Real OptionletVolatilityStructure::blackVariance(const Date& optionDate,
152 Rate strike,
153 bool extrapolate) const {
154 Volatility v = volatility(optionDate, strike, extrapolate);
155 Time t = timeFromReference(d: optionDate);
156 return v*v*t;
157 }
158
159 inline
160 Real OptionletVolatilityStructure::blackVariance(Time optionTime,
161 Rate strike,
162 bool extrapolate) const {
163 Volatility v = volatility(optionTime, strike, extrapolate);
164 return v*v*optionTime;
165 }
166
167 // 3. relying on xxxImpl methods
168 inline Volatility
169 OptionletVolatilityStructure::volatility(const Date& optionDate,
170 Rate strike,
171 bool extrapolate) const {
172 checkRange(d: optionDate, extrapolate);
173 checkStrike(strike, extrapolate);
174 return volatilityImpl(optionDate, strike);
175 }
176
177 inline Volatility
178 OptionletVolatilityStructure::volatility(Time optionTime,
179 Rate strike,
180 bool extrapolate) const {
181 checkRange(t: optionTime, extrapolate);
182 checkStrike(strike, extrapolate);
183 return volatilityImpl(optionTime, strike);
184 }
185
186 inline ext::shared_ptr<SmileSection>
187 OptionletVolatilityStructure::smileSection(const Date& optionDate,
188 bool extrapolate) const {
189 checkRange(d: optionDate, extrapolate);
190 return smileSectionImpl(optionDate);
191 }
192
193 inline ext::shared_ptr<SmileSection>
194 OptionletVolatilityStructure::smileSection(Time optionTime,
195 bool extrapolate) const {
196 checkRange(t: optionTime, extrapolate);
197 return smileSectionImpl(optionTime);
198 }
199
200 // 4. default implementation of Date-based xxxImpl methods
201 // relying on the equivalent Time-based methods
202 inline ext::shared_ptr<SmileSection>
203 OptionletVolatilityStructure::smileSectionImpl(const Date& optionDate) const {
204 return smileSectionImpl(optionTime: timeFromReference(d: optionDate));
205 }
206
207 inline Volatility
208 OptionletVolatilityStructure::volatilityImpl(const Date& optionDate,
209 Rate strike) const {
210 return volatilityImpl(optionTime: timeFromReference(d: optionDate), strike);
211 }
212
213 inline VolatilityType
214 OptionletVolatilityStructure::volatilityType() const {
215 return ShiftedLognormal;
216 }
217
218 inline Real OptionletVolatilityStructure::displacement() const {
219 return 0.0;
220 }
221}
222
223#endif
224

source code of quantlib/ql/termstructures/volatility/optionlet/optionletvolatilitystructure.hpp