QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
callablebondvolstructure.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) 2008 Allen Kuo
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20/*! \file callablebondvolstructure.hpp
21 \brief Callable-bond volatility structure
22*/
23
24#ifndef quantlib_callable_bond_volatility_structure_hpp
25#define quantlib_callable_bond_volatility_structure_hpp
26
27#include <ql/termstructure.hpp>
30
31namespace QuantLib {
32
33 //! Callable-bond volatility structure
34 /*! This class is purely abstract and defines the interface of
35 concrete callable-bond volatility structures which will be
36 derived from this one.
37 */
39 public:
40 /*! \name Constructors
41 See the TermStructure documentation for issues regarding
42 constructors.
43 */
44 //@{
45 //! default constructor
46 /*! \warning term structures initialized by means of this
47 constructor must manage their own reference date
48 by overriding the referenceDate() method.
49 */
52 //! initialize with a fixed reference date
54 const Calendar& calendar = Calendar(),
55 const DayCounter& dc = DayCounter(),
57 //! calculate the reference date based on the global evaluation date
59 const Calendar&,
60 const DayCounter& dc = DayCounter(),
62 //@}
64 //! \name Volatility, variance and smile
65 //@{
66 //! returns the volatility for a given option time and bondLength
67 Volatility volatility(Time optionTime,
68 Time bondLength,
69 Rate strike,
70 bool extrapolate = false) const;
71 //! returns the Black variance for a given option time and bondLength
72 Real blackVariance(Time optionTime,
73 Time bondLength,
74 Rate strike,
75 bool extrapolate = false) const;
76
77 //! returns the volatility for a given option date and bond tenor
78 Volatility volatility(const Date& optionDate,
79 const Period& bondTenor,
80 Rate strike,
81 bool extrapolate = false) const;
82 //! returns the Black variance for a given option date and bond tenor
83 Real blackVariance(const Date& optionDate,
84 const Period& bondTenor,
85 Rate strike,
86 bool extrapolate = false) const;
87 virtual ext::shared_ptr<SmileSection> smileSection(
88 const Date& optionDate,
89 const Period& bondTenor) const {
90 const std::pair<Time, Time> p = convertDates(optionDate, bondTenor);
91 return smileSectionImpl(p.first, p.second);
92 }
93
94 //! returns the volatility for a given option tenor and bond tenor
95 Volatility volatility(const Period& optionTenor,
96 const Period& bondTenor,
97 Rate strike,
98 bool extrapolate = false) const;
99 //! returns the Black variance for a given option tenor and bond tenor
100 Real blackVariance(const Period& optionTenor,
101 const Period& bondTenor,
102 Rate strike,
103 bool extrapolate = false) const;
104 ext::shared_ptr<SmileSection> smileSection(
105 const Period& optionTenor,
106 const Period& bondTenor) const;
107 //@}
108 //! \name Limits
109 //@{
110 //! the largest length for which the term structure can return vols
111 virtual const Period& maxBondTenor() const = 0;
112 //! the largest bondLength for which the term structure can return vols
113 virtual Time maxBondLength() const;
114 //! the minimum strike for which the term structure can return vols
115 virtual Rate minStrike() const = 0;
116 //! the maximum strike for which the term structure can return vols
117 virtual Rate maxStrike() const = 0;
118 //@}
119 //! implements the conversion between dates and times
120 virtual std::pair<Time,Time> convertDates(
121 const Date& optionDate,
122 const Period& bondTenor) const;
123 //! the business day convention used for option date calculation
125 //! implements the conversion between optionTenors and optionDates
126 Date optionDateFromTenor(const Period& optionTenor) const;
127 protected:
128
129 //! return smile section
130 virtual ext::shared_ptr<SmileSection> smileSectionImpl(
131 Time optionTime,
132 Time bondLength) const = 0;
133
134 //! implements the actual volatility calculation in derived classes
135 virtual Volatility volatilityImpl(Time optionTime,
136 Time bondLength,
137 Rate strike) const = 0;
138 virtual Volatility volatilityImpl(const Date& optionDate,
139 const Period& bondTenor,
140 Rate strike) const {
141 const std::pair<Time, Time> p = convertDates(optionDate, bondTenor);
142 return volatilityImpl(p.first, p.second, strike);
143 }
144 void checkRange(Time, Time, Rate strike, bool extrapolate) const;
145 void checkRange(const Date& optionDate,
146 const Period& bondTenor,
147 Rate strike, bool extrapolate) const;
148 private:
150 };
151
152
153 // inline definitions
154
157 return bdc_;
158 }
159
161 const Period& optionTenor) const {
162 return calendar().advance(referenceDate(),
163 optionTenor,
165 }
166
168 Time optionTime,
169 Time bondLength,
170 Rate strike,
171 bool extrapolate) const {
172 checkRange(optionTime, bondLength, strike, extrapolate);
173 return volatilityImpl(optionTime, bondLength, strike);
174 }
175
176
178 Time optionTime,
179 Time bondLength,
180 Rate strike,
181 bool extrapolate) const {
182 checkRange(optionTime, bondLength, strike, extrapolate);
183 Volatility vol = volatilityImpl(optionTime, bondLength, strike);
184 return vol*vol*optionTime;
185 }
186
187
189 const Date& optionDate,
190 const Period& bondTenor,
191 Rate strike,
192 bool extrapolate) const {
193 checkRange(optionDate, bondTenor, strike, extrapolate);
194 return volatilityImpl(optionDate, bondTenor, strike);
195 }
196
198 const Date& optionDate,
199 const Period& bondTenor,
200 Rate strike,
201 bool extrapolate) const {
202 Volatility vol =
203 volatility(optionDate, bondTenor, strike, extrapolate);
204 const std::pair<Time, Time> p = convertDates(optionDate, bondTenor);
205 return vol*vol*p.first;
206 }
207
209 const Period& optionTenor,
210 const Period& bondTenor,
211 Rate strike,
212 bool extrapolate) const {
213 Date optionDate = optionDateFromTenor(optionTenor);
214 return volatility(optionDate, bondTenor, strike, extrapolate);
215 }
216
218 const Period& optionTenor,
219 const Period& bondTenor,
220 Rate strike,
221 bool extrapolate) const {
222 Date optionDate = optionDateFromTenor(optionTenor);
223 Volatility vol =
224 volatility(optionDate, bondTenor, strike, extrapolate);
225 const std::pair<Time, Time> p = convertDates(optionDate, bondTenor);
226 return vol*vol*p.first;
227 }
228
229
230 inline ext::shared_ptr<SmileSection>
232 const Period& optionTenor,
233 const Period& bondTenor) const {
234 Date optionDate = optionDateFromTenor(optionTenor);
235 return smileSection(optionDate, bondTenor);
236 }
237
238
240 Time optionTime, Time bondLength, Rate k, bool extrapolate) const {
241 TermStructure::checkRange(optionTime, extrapolate);
242 QL_REQUIRE(bondLength >= 0.0,
243 "negative bondLength (" << bondLength << ") given");
244 QL_REQUIRE(extrapolate || allowsExtrapolation() ||
245 bondLength <= maxBondLength(),
246 "bondLength (" << bondLength << ") is past max curve bondLength ("
247 << maxBondLength() << ")");
248 QL_REQUIRE(extrapolate || allowsExtrapolation() ||
249 (k >= minStrike() && k <= maxStrike()),
250 "strike (" << k << ") is outside the curve domain ["
251 << minStrike() << "," << maxStrike()<< "]");
252 }
253
254}
255
256#endif
calendar class
Definition: calendar.hpp:61
Date advance(const Date &, Integer n, TimeUnit unit, BusinessDayConvention convention=Following, bool endOfMonth=false) const
Definition: calendar.cpp:130
Date optionDateFromTenor(const Period &optionTenor) const
implements the conversion between optionTenors and optionDates
virtual ext::shared_ptr< SmileSection > smileSection(const Date &optionDate, const Period &bondTenor) const
virtual const Period & maxBondTenor() const =0
the largest length for which the term structure can return vols
virtual Time maxBondLength() const
the largest bondLength for which the term structure can return vols
Real blackVariance(Time optionTime, Time bondLength, Rate strike, bool extrapolate=false) const
returns the Black variance for a given option time and bondLength
virtual Rate maxStrike() const =0
the maximum strike for which the term structure can return vols
virtual Volatility volatilityImpl(const Date &optionDate, const Period &bondTenor, Rate strike) const
virtual std::pair< Time, Time > convertDates(const Date &optionDate, const Period &bondTenor) const
implements the conversion between dates and times
virtual Rate minStrike() const =0
the minimum strike for which the term structure can return vols
virtual ext::shared_ptr< SmileSection > smileSectionImpl(Time optionTime, Time bondLength) const =0
return smile section
void checkRange(Time, Time, Rate strike, bool extrapolate) const
Volatility volatility(Time optionTime, Time bondLength, Rate strike, bool extrapolate=false) const
returns the volatility for a given option time and bondLength
virtual BusinessDayConvention businessDayConvention() const
the business day convention used for option date calculation
virtual Volatility volatilityImpl(Time optionTime, Time bondLength, Rate strike) const =0
implements the actual volatility calculation in derived classes
~CallableBondVolatilityStructure() override=default
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
bool allowsExtrapolation() const
tells whether extrapolation is enabled
Basic term-structure functionality.
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
void checkRange(const Date &d, bool extrapolate) const
date-range check
#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
linear interpolation between discrete points
Definition: any.hpp:35
Smile section base class.
base class for term structures