QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
swaptionvolmatrix.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) 2000, 2001, 2002, 2003 RiskMap srl
5 Copyright (C) 2006 François du Vignaud
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 swaptionvolmatrix.hpp
24 \brief Swaption at-the-money volatility matrix
25*/
26
27#ifndef quantlib_swaption_volatility_matrix_hpp
28#define quantlib_swaption_volatility_matrix_hpp
29
32#include <ql/math/matrix.hpp>
33#include <vector>
34
35namespace QuantLib {
36
37 class Quote;
38
39 //! At-the-money swaption-volatility matrix
40 /*! This class provides the at-the-money volatility for a given
41 swaption by interpolating a volatility matrix whose elements
42 are the market volatilities of a set of swaption with given
43 option date and swapLength.
44
45 The volatility matrix <tt>M</tt> must be defined so that:
46 - the number of rows equals the number of option dates;
47 - the number of columns equals the number of swap tenors;
48 - <tt>M[i][j]</tt> contains the volatility corresponding
49 to the <tt>i</tt>-th option and <tt>j</tt>-th tenor.
50 */
52 public:
53 //! floating reference date, floating market data
55 const Calendar& calendar,
57 const std::vector<Period>& optionTenors,
58 const std::vector<Period>& swapTenors,
59 const std::vector<std::vector<Handle<Quote> > >& vols,
61 bool flatExtrapolation = false,
63 const std::vector<std::vector<Real> >& shifts = std::vector<std::vector<Real> >());
64 //! fixed reference date, floating market data
66 const Date& referenceDate,
67 const Calendar& calendar,
69 const std::vector<Period>& optionTenors,
70 const std::vector<Period>& swapTenors,
71 const std::vector<std::vector<Handle<Quote> > >& vols,
73 bool flatExtrapolation = false,
75 const std::vector<std::vector<Real> >& shifts = std::vector<std::vector<Real> >());
76 //! floating reference date, fixed market data
79 const std::vector<Period>& optionTenors,
80 const std::vector<Period>& swapTenors,
81 const Matrix& volatilities,
83 bool flatExtrapolation = false,
85 const Matrix& shifts = Matrix());
86 //! fixed reference date, fixed market data
88 const Calendar& calendar,
90 const std::vector<Period>& optionTenors,
91 const std::vector<Period>& swapTenors,
92 const Matrix& volatilities,
94 bool flatExtrapolation = false,
96 const Matrix& shifts = Matrix());
97 //! fixed reference date and fixed market data, option dates
99 const Calendar& calendar,
101 const std::vector<Date>& optionDates,
102 const std::vector<Period>& swapTenors,
103 const Matrix& volatilities,
104 const DayCounter& dayCounter,
105 bool flatExtrapolation = false,
107 const Matrix& shifts = Matrix());
108
109 // make class non-copyable and non-movable
114
115 ~SwaptionVolatilityMatrix() override = default;
116
117 //! \name LazyObject interface
118 //@{
119 void performCalculations() const override;
120 //@}
121 //! \name TermStructure interface
122 //@{
123 Date maxDate() const override;
124 //@}
125 //! \name VolatilityTermStructure interface
126 //@{
127 Rate minStrike() const override;
128 Rate maxStrike() const override;
129 //@}
130 //! \name SwaptionVolatilityStructure interface
131 //@{
132 const Period& maxSwapTenor() const override;
133 //@}
134 //! \name Other inspectors
135 //@{
136 //! returns the lower indexes of surrounding volatility matrix corners
137 std::pair<Size,Size> locate(const Date& optionDate,
138 const Period& swapTenor) const {
139 return locate(timeFromReference(optionDate),
140 swapLength(swapTenor));
141 }
142 //! returns the lower indexes of surrounding volatility matrix corners
143 std::pair<Size,Size> locate(Time optionTime,
144 Time swapLength) const {
145 return std::make_pair(interpolation_.locateY(optionTime),
147 }
148 //@}
149 VolatilityType volatilityType() const override;
150
151 protected:
152 // defining the following method would break CMS test suite
153 // to be further investigated
154 //ext::shared_ptr<SmileSection> smileSectionImpl(const Date&,
155 // const Period&) const;
156 ext::shared_ptr<SmileSection> smileSectionImpl(Time, Time) const override;
157 Volatility volatilityImpl(Time optionTime, Time swapLength, Rate strike) const override;
158 Real shiftImpl(Time optionTime, Time swapLength) const override;
159
160 private:
161 void checkInputs(Size volRows,
162 Size volsColumns,
163 Size shiftRows,
164 Size shiftsColumns) const;
166 std::vector<std::vector<Handle<Quote> > > volHandles_;
167 std::vector<std::vector<Real> > shiftValues_;
171 };
172
173 // inline definitions
174
176 return optionDates_.back();
177 }
178
180 return -QL_MAX_REAL;
181 }
182
184 return QL_MAX_REAL;
185 }
186
188 return swapTenors_.back();
189 }
190
192 Time swapLength,
193 Rate) const {
194 calculate();
195 return interpolation_(swapLength, optionTime, true);
196 }
197
199 return volatilityType_;
200 }
201
203 Time swapLength) const {
204 calculate();
205 Real tmp = interpolationShifts_(swapLength, optionTime, true);
206 return tmp;
207 }
208} // namespace QuantLib
209
210#endif
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Shared handle to an observable.
Definition: handle.hpp:41
base class for 2-D interpolations.
Size locateY(Real y) const
Size locateX(Real x) const
virtual void calculate() const
Definition: lazyobject.hpp:253
Matrix used in linear algebra.
Definition: matrix.hpp:41
const std::vector< Period > & swapTenors() const
const std::vector< Period > & optionTenors() const
const std::vector< Date > & optionDates() const
At-the-money swaption-volatility matrix.
std::pair< Size, Size > locate(Time optionTime, Time swapLength) const
returns the lower indexes of surrounding volatility matrix corners
Volatility volatilityImpl(Time optionTime, Time swapLength, Rate strike) const override
std::vector< std::vector< Handle< Quote > > > volHandles_
Rate maxStrike() const override
the maximum strike for which the term structure can return vols
~SwaptionVolatilityMatrix() override=default
Rate minStrike() const override
the minimum strike for which the term structure can return vols
ext::shared_ptr< SmileSection > smileSectionImpl(Time, Time) const override
std::pair< Size, Size > locate(const Date &optionDate, const Period &swapTenor) const
returns the lower indexes of surrounding volatility matrix corners
SwaptionVolatilityMatrix(SwaptionVolatilityMatrix &&)=delete
Real shiftImpl(Time optionTime, Time swapLength) const override
SwaptionVolatilityMatrix(const SwaptionVolatilityMatrix &)=delete
VolatilityType volatilityType() const override
volatility type
void checkInputs(Size volRows, Size volsColumns, Size shiftRows, Size shiftsColumns) const
Date maxDate() const override
the latest date for which the curve can return values
std::vector< std::vector< Real > > shiftValues_
SwaptionVolatilityMatrix & operator=(const SwaptionVolatilityMatrix &)=delete
const Period & maxSwapTenor() const override
the largest length for which the term structure can return vols
SwaptionVolatilityMatrix & operator=(SwaptionVolatilityMatrix &&)=delete
Time swapLength(const Period &swapTenor) const
implements the conversion between swap tenor and swap (time) length
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
virtual DayCounter dayCounter() const
the day counter used for date/time conversion
BusinessDayConvention
Business Day conventions.
#define QL_MAX_REAL
Definition: qldefines.hpp:176
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real Volatility
volatility
Definition: types.hpp:78
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
abstract base classes for 2-D interpolations
matrix used in linear algebra.
Definition: any.hpp:35
Discretized swaption volatility.