QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
swaptionvolstructure.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) 2002, 2003 RiskMap srl
5 Copyright (C) 2003, 2004, 2005, 2006 StatPro Italia srl
6 Copyright (C) 2006, 2008 Ferdinando Ametrano
7 Copyright (C) 2015 Peter Caspers
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 swaptionvolstructure.hpp
24 \brief Swaption volatility structure
25*/
26
27#ifndef quantlib_swaption_volatility_structure_hpp
28#define quantlib_swaption_volatility_structure_hpp
29
32
33namespace QuantLib {
34
35 class SmileSection;
36
37 //! %Swaption-volatility structure
38 /*! This abstract class defines the interface of concrete swaption
39 volatility structures which will be derived from this one.
40 */
42 public:
43 /*! \name Constructors
44 See the TermStructure documentation for issues regarding
45 constructors.
46 */
47 //@{
48 /*! \warning term structures initialized by means of this
49 constructor must manage their own reference date
50 by overriding the referenceDate() method.
51 */
53 const DayCounter& dc = DayCounter());
54 //! initialize with a fixed reference date
56 const Calendar& calendar,
58 const DayCounter& dc = DayCounter());
59 //! calculate the reference date based on the global evaluation date
61 const Calendar&,
63 const DayCounter& dc = DayCounter());
64 //@}
65 ~SwaptionVolatilityStructure() override = default;
66 //! \name Volatility, variance and smile
67 //@{
68 //! returns the volatility for a given option tenor and swap tenor
69 Volatility volatility(const Period& optionTenor,
70 const Period& swapTenor,
71 Rate strike,
72 bool extrapolate = false) const;
73 //! returns the volatility for a given option date and swap tenor
74 Volatility volatility(const Date& optionDate,
75 const Period& swapTenor,
76 Rate strike,
77 bool extrapolate = false) const;
78 //! returns the volatility for a given option time and swap tenor
79 Volatility volatility(Time optionTime,
80 const Period& swapTenor,
81 Rate strike,
82 bool extrapolate = false) const;
83 //! returns the volatility for a given option tenor and swap length
84 Volatility volatility(const Period& optionTenor,
86 Rate strike,
87 bool extrapolate = false) const;
88 //! returns the volatility for a given option date and swap length
89 Volatility volatility(const Date& optionDate,
91 Rate strike,
92 bool extrapolate = false) const;
93 //! returns the volatility for a given option time and swap length
94 Volatility volatility(Time optionTime,
96 Rate strike,
97 bool extrapolate = false) const;
98
99 //! returns the Black variance for a given option tenor and swap tenor
100 Real blackVariance(const Period& optionTenor,
101 const Period& swapTenor,
102 Rate strike,
103 bool extrapolate = false) const;
104 //! returns the Black variance for a given option date and swap tenor
105 Real blackVariance(const Date& optionDate,
106 const Period& swapTenor,
107 Rate strike,
108 bool extrapolate = false) const;
109 //! returns the Black variance for a given option time and swap tenor
110 Real blackVariance(Time optionTime,
111 const Period& swapTenor,
112 Rate strike,
113 bool extrapolate = false) const;
114 //! returns the Black variance for a given option tenor and swap length
115 Real blackVariance(const Period& optionTenor,
117 Rate strike,
118 bool extrapolate = false) const;
119 //! returns the Black variance for a given option date and swap length
120 Real blackVariance(const Date& optionDate,
122 Rate strike,
123 bool extrapolate = false) const;
124 //! returns the Black variance for a given option time and swap length
125 Real blackVariance(Time optionTime,
127 Rate strike,
128 bool extrapolate = false) const;
129
130 //! returns the shift for a given option tenor and swap tenor
131 Real shift(const Period& optionTenor,
132 const Period& swapTenor,
133 bool extrapolate = false) const;
134 //! returns the shift for a given option date and swap tenor
135 Real shift(const Date& optionDate,
136 const Period& swapTenor,
137 bool extrapolate = false) const;
138 //! returns the shift for a given option time and swap tenor
139 Real shift(Time optionTime,
140 const Period& swapTenor,
141 bool extrapolate = false) const;
142 //! returns the shift for a given option tenor and swap length
143 Real shift(const Period& optionTenor,
145 bool extrapolate = false) const;
146 //! returns the shift for a given option date and swap length
147 Real shift(const Date& optionDate,
149 bool extrapolate = false) const;
150 //! returns the shift for a given option time and swap length
151 Real shift(Time optionTime,
153 bool extrapolate = false) const;
154
155 //! returns the smile for a given option tenor and swap tenor
156 ext::shared_ptr<SmileSection> smileSection(const Period& optionTenor,
157 const Period& swapTenor,
158 bool extr = false) const;
159 //! returns the smile for a given option date and swap tenor
160 ext::shared_ptr<SmileSection> smileSection(const Date& optionDate,
161 const Period& swapTenor,
162 bool extr = false) const;
163 //! returns the smile for a given option time and swap tenor
164 ext::shared_ptr<SmileSection> smileSection(Time optionTime,
165 const Period& swapTenor,
166 bool extr = false) const;
167 //! returns the smile for a given option tenor and swap length
168 ext::shared_ptr<SmileSection> smileSection(const Period& optionTenor,
170 bool extr = false) const;
171 //! returns the smile for a given option date and swap length
172 ext::shared_ptr<SmileSection> smileSection(const Date& optionDate,
174 bool extr = false) const;
175 //! returns the smile for a given option time and swap length
176 ext::shared_ptr<SmileSection> smileSection(Time optionTime,
178 bool extr = false) const;
179 //@}
180 //! \name Limits
181 //@{
182 //! the largest length for which the term structure can return vols
183 virtual const Period& maxSwapTenor() const = 0;
184 //! the largest swapLength for which the term structure can return vols
185 Time maxSwapLength() const;
186 //@}
187 //@{
188 //! volatility type
190 return ShiftedLognormal;
191 }
192 //@}
193 //! implements the conversion between swap tenor and swap (time) length
194 Time swapLength(const Period& swapTenor) const;
195 //! implements the conversion between swap dates and swap (time) length
196 Time swapLength(const Date& start,
197 const Date& end) const;
198 protected:
199 virtual ext::shared_ptr<SmileSection> smileSectionImpl(
200 const Date& optionDate,
201 const Period& swapTenor) const;
202 virtual ext::shared_ptr<SmileSection> smileSectionImpl(
203 Time optionTime,
204 Time swapLength) const = 0;
205 virtual Volatility volatilityImpl(const Date& optionDate,
206 const Period& swapTenor,
207 Rate strike) const;
208 virtual Volatility volatilityImpl(Time optionTime,
210 Rate strike) const = 0;
211 virtual Real shiftImpl(const Date &optionDate,
212 const Period &swapTenor) const;
213 virtual Real shiftImpl(Time optionTime, Time swapLength) const;
214 void checkSwapTenor(const Period& swapTenor,
215 bool extrapolate) const;
217 bool extrapolate) const;
218 };
219
220 // inline definitions
221
222 // 1. methods with Period-denominated exercise convert Period to Date and then
223 // use the equivalent Date-denominated exercise methods
224 inline Volatility
226 const Period& swapTenor,
227 Rate strike,
228 bool extrapolate) const {
229 Date optionDate = optionDateFromTenor(optionTenor);
230 return volatility(optionDate, swapTenor, strike, extrapolate);
231 }
232
233 inline Volatility
235 Time swapLength,
236 Rate strike,
237 bool extrapolate) const {
238 Date optionDate = optionDateFromTenor(optionTenor);
239 return volatility(optionDate, swapLength, strike, extrapolate);
240 }
241
242 inline
244 const Period& swapTenor,
245 Rate strike,
246 bool extrapolate) const {
247 Date optionDate = optionDateFromTenor(optionTenor);
248 return blackVariance(optionDate, swapTenor, strike, extrapolate);
249 }
250
251 inline
253 Time swapLength,
254 Rate strike,
255 bool extrapolate) const {
256 Date optionDate = optionDateFromTenor(optionTenor);
257 return blackVariance(optionDate, swapLength, strike, extrapolate);
258 }
259
260 inline
262 const Period& swapTenor,
263 bool extrapolate) const {
264 Date optionDate = optionDateFromTenor(optionTenor);
265 return shift(optionDate, swapTenor, extrapolate);
266 }
267
268 inline
270 Time swapLength,
271 bool extrapolate) const {
272 Date optionDate = optionDateFromTenor(optionTenor);
273 return shift(optionDate, swapLength, extrapolate);
274 }
275
276 inline ext::shared_ptr<SmileSection>
278 const Period& swapTenor,
279 bool extrapolate) const {
280 Date optionDate = optionDateFromTenor(optionTenor);
281 return smileSection(optionDate, swapTenor, extrapolate);
282 }
283
284 // 2. blackVariance methods rely on volatility methods
285 inline
287 const Period& swapTenor,
288 Rate strike,
289 bool extrapolate) const {
290 Volatility v = volatility(optionDate, swapTenor, strike, extrapolate);
291 Time optionTime = timeFromReference(optionDate);
292 return v*v*optionTime;
293 }
294
295 inline
297 const Period& swapTenor,
298 Rate strike,
299 bool extrapolate) const {
300 Volatility v = volatility(optionTime, swapTenor, strike, extrapolate);
301 return v*v*optionTime;
302 }
303
304 inline
306 Time swapLength,
307 Rate strike,
308 bool extrapolate) const {
309 Volatility v = volatility(optionDate, swapLength, strike, extrapolate);
310 Time optionTime = timeFromReference(optionDate);
311 return v*v*optionTime;
312 }
313
314 inline
316 Time swapLength,
317 Rate strike,
318 bool extrapolate) const {
319 Volatility v = volatility(optionTime, swapLength, strike, extrapolate);
320 return v*v*optionTime;
321 }
322
323 // 3. relying on xxxImpl methods
324 inline Volatility
326 const Period& swapTenor,
327 Rate strike,
328 bool extrapolate) const {
329 checkSwapTenor(swapTenor, extrapolate);
330 checkRange(optionDate, extrapolate);
331 checkStrike(strike, extrapolate);
332 return volatilityImpl(optionDate, swapTenor, strike);
333 }
334
335 inline Volatility
337 Time swapLength,
338 Rate strike,
339 bool extrapolate) const {
340 checkSwapTenor(swapLength, extrapolate);
341 checkRange(optionDate, extrapolate);
342 checkStrike(strike, extrapolate);
343 Time optionTime = timeFromReference(optionDate);
344 return volatilityImpl(optionTime, swapLength, strike);
345 }
346
347 inline Volatility
349 const Period& swapTenor,
350 Rate strike,
351 bool extrapolate) const {
352 checkSwapTenor(swapTenor, extrapolate);
353 checkRange(optionTime, extrapolate);
354 checkStrike(strike, extrapolate);
355 Time length = swapLength(swapTenor);
356 return volatilityImpl(optionTime, length, strike);
357 }
358
359 inline Volatility
361 Time swapLength,
362 Rate strike,
363 bool extrapolate) const {
364 checkSwapTenor(swapLength, extrapolate);
365 checkRange(optionTime, extrapolate);
366 checkStrike(strike, extrapolate);
367 return volatilityImpl(optionTime, swapLength, strike);
368 }
369
370 inline Real
372 const Period& swapTenor,
373 bool extrapolate) const {
374 checkSwapTenor(swapTenor, extrapolate);
375 checkRange(optionDate, extrapolate);
376 return shiftImpl(optionDate, swapTenor);
377 }
378
379 inline Real
381 Time swapLength,
382 bool extrapolate) const {
383 checkSwapTenor(swapLength, extrapolate);
384 checkRange(optionDate, extrapolate);
385 Time optionTime = timeFromReference(optionDate);
386 return shiftImpl(optionTime, swapLength);
387 }
388
389 inline Real
391 const Period& swapTenor,
392 bool extrapolate) const {
393 checkSwapTenor(swapTenor, extrapolate);
394 checkRange(optionTime, extrapolate);
395 Time length = swapLength(swapTenor);
396 return shiftImpl(optionTime, length);
397 }
398
399 inline Real
401 Time swapLength,
402 bool extrapolate) const {
403 checkSwapTenor(swapLength, extrapolate);
404 checkRange(optionTime, extrapolate);
405 return shiftImpl(optionTime, swapLength);
406 }
407
408 inline ext::shared_ptr<SmileSection>
410 const Period& swapTenor,
411 bool extrapolate) const {
412 checkSwapTenor(swapTenor, extrapolate);
413 checkRange(optionDate, extrapolate);
414 return smileSectionImpl(optionDate, swapTenor);
415 }
416
417 inline ext::shared_ptr<SmileSection>
419 const Period& swapTenor,
420 bool extrapolate) const {
421 checkSwapTenor(swapTenor, extrapolate);
422 checkRange(optionTime, extrapolate);
423 return smileSection(optionTime, swapLength(swapTenor));
424 }
425
426 inline ext::shared_ptr<SmileSection>
428 Time swapLength,
429 bool extrapolate) const {
430 checkSwapTenor(swapLength, extrapolate);
431 Date optionDate = optionDateFromTenor(optionTenor);
432 checkRange(optionDate, extrapolate);
433 return smileSection(optionDate, swapLength);
434 }
435
436 inline ext::shared_ptr<SmileSection>
438 Time swapLength,
439 bool extrapolate) const {
440 checkSwapTenor(swapLength, extrapolate);
441 checkRange(optionDate, extrapolate);
442 return smileSection(timeFromReference(optionDate), swapLength);
443 }
444
445 inline ext::shared_ptr<SmileSection>
447 Time swapLength,
448 bool extrapolate) const {
449 checkSwapTenor(swapLength, extrapolate);
450 checkRange(optionTime, extrapolate);
451 return smileSectionImpl(optionTime, swapLength);
452 }
453
454 // 4. default implementation of Date-based xxxImpl methods
455 // relying on the equivalent Time-based methods
456 inline ext::shared_ptr<SmileSection>
458 const Period& swapT) const {
459 return smileSectionImpl(timeFromReference(optionDate),
460 swapLength(swapT));
461 }
462
463 inline Volatility
465 const Period& swapTenor,
466 Rate strike) const {
467 return volatilityImpl(timeFromReference(optionDate),
468 swapLength(swapTenor),
469 strike);
470 }
471
472 inline Real
474 const Period &swapTenor) const {
475 return shiftImpl(timeFromReference(optionDate), swapLength(swapTenor));
476 }
477
481 "shift parameter only makes sense for lognormal volatilities");
482 return 0.0;
483 }
484
486 return swapLength(maxSwapTenor());
487 }
488
489}
490
491#endif
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
ext::shared_ptr< SmileSection > smileSection(const Period &optionTenor, const Period &swapTenor, bool extr=false) const
returns the smile for a given option tenor and swap tenor
virtual const Period & maxSwapTenor() const =0
the largest length for which the term structure can return vols
void checkSwapTenor(const Period &swapTenor, bool extrapolate) const
virtual Real shiftImpl(const Date &optionDate, const Period &swapTenor) const
virtual ext::shared_ptr< SmileSection > smileSectionImpl(Time optionTime, Time swapLength) const =0
virtual ext::shared_ptr< SmileSection > smileSectionImpl(const Date &optionDate, const Period &swapTenor) const
virtual Volatility volatilityImpl(Time optionTime, Time swapLength, Rate strike) const =0
Real shift(const Period &optionTenor, const Period &swapTenor, bool extrapolate=false) const
returns the shift for a given option tenor and swap tenor
Real blackVariance(const Period &optionTenor, const Period &swapTenor, Rate strike, bool extrapolate=false) const
returns the Black variance for a given option tenor and swap tenor
Time swapLength(const Period &swapTenor) const
implements the conversion between swap tenor and swap (time) length
Volatility volatility(const Period &optionTenor, const Period &swapTenor, Rate strike, bool extrapolate=false) const
returns the volatility for a given option tenor and swap tenor
~SwaptionVolatilityStructure() override=default
virtual VolatilityType volatilityType() const
volatility type
virtual Volatility volatilityImpl(const Date &optionDate, const Period &swapTenor, Rate strike) const
Time maxSwapLength() const
the largest swapLength for which the term structure can return vols
virtual Natural settlementDays() const
the settlementDays used for reference date calculation
virtual const Date & referenceDate() const
the date at which discount = 1.0 and/or variance = 0.0
virtual Calendar calendar() const
the calendar used for reference and/or option date calculation
Time timeFromReference(const Date &date) const
date/time conversion
void checkRange(const Date &d, bool extrapolate) const
date-range check
Volatility term structure.
void checkStrike(Rate strike, bool extrapolate) const
strike-range check
Date optionDateFromTenor(const Period &) const
period/date conversion
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
BusinessDayConvention
Business Day conventions.
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
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
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
ext::shared_ptr< BlackVolTermStructure > v
volatility types
Volatility term structure.