QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
optionletvolatilitystructure.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) 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
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 */
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 */
55 const DayCounter& dc = DayCounter());
56 //! initialize with a fixed reference date
58 const Calendar& cal,
60 const DayCounter& dc = DayCounter());
61 //! calculate the reference date based on the global evaluation date
63 const Calendar&,
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
128 Rate strike,
129 bool extrapolate) const {
130 Date optionDate = optionDateFromTenor(optionTenor);
131 return volatility(optionDate, strike, extrapolate);
132 }
133
134 inline
136 Rate strike,
137 bool extrapolate) const {
138 Date optionDate = optionDateFromTenor(optionTenor);
139 return blackVariance(optionDate, strike, extrapolate);
140 }
141
142 inline ext::shared_ptr<SmileSection>
144 bool extrapolate) const {
145 Date optionDate = optionDateFromTenor(optionTenor);
146 return smileSection(optionDate, extrapolate);
147 }
148
149 // 2. blackVariance methods rely on volatility methods
150 inline
152 Rate strike,
153 bool extrapolate) const {
154 Volatility v = volatility(optionDate, strike, extrapolate);
155 Time t = timeFromReference(optionDate);
156 return v*v*t;
157 }
158
159 inline
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
170 Rate strike,
171 bool extrapolate) const {
172 checkRange(optionDate, extrapolate);
173 checkStrike(strike, extrapolate);
174 return volatilityImpl(optionDate, strike);
175 }
176
177 inline Volatility
179 Rate strike,
180 bool extrapolate) const {
181 checkRange(optionTime, extrapolate);
182 checkStrike(strike, extrapolate);
183 return volatilityImpl(optionTime, strike);
184 }
185
186 inline ext::shared_ptr<SmileSection>
188 bool extrapolate) const {
189 checkRange(optionDate, extrapolate);
190 return smileSectionImpl(optionDate);
191 }
192
193 inline ext::shared_ptr<SmileSection>
195 bool extrapolate) const {
196 checkRange(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>
204 return smileSectionImpl(timeFromReference(optionDate));
205 }
206
207 inline Volatility
209 Rate strike) const {
210 return volatilityImpl(timeFromReference(optionDate), strike);
211 }
212
213 inline VolatilityType
215 return ShiftedLognormal;
216 }
217
219 return 0.0;
220 }
221}
222
223#endif
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Optionlet (caplet/floorlet) volatility structure.
ext::shared_ptr< SmileSection > smileSection(const Period &optionTenor, bool extr=false) const
returns the smile for a given option tenor
Real blackVariance(const Period &optionTenor, Rate strike, bool extrapolate=false) const
returns the Black variance for a given option tenor and strike rate
virtual Volatility volatilityImpl(const Date &optionDate, Rate strike) const
virtual Volatility volatilityImpl(Time optionTime, Rate strike) const =0
implements the actual volatility calculation in derived classes
virtual ext::shared_ptr< SmileSection > smileSectionImpl(const Date &optionDate) const
virtual ext::shared_ptr< SmileSection > smileSectionImpl(Time optionTime) const =0
implements the actual smile calculation in derived classes
~OptionletVolatilityStructure() override=default
Volatility volatility(const Period &optionTenor, Rate strike, bool extrapolate=false) const
returns the volatility for a given option tenor and strike rate
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
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
const DefaultType & t
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
optionlet (caplet/floorlet) volatility stripper
ext::shared_ptr< BlackVolTermStructure > v
volatility types
Volatility term structure.