QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
swaptionvolmatrix.hpp
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
27#ifndef quantlib_swaption_volatility_matrix_hpp
28#define quantlib_swaption_volatility_matrix_hpp
29
30#include <ql/termstructures/volatility/swaption/swaptionvoldiscrete.hpp>
31#include <ql/math/interpolations/interpolation2d.hpp>
32#include <ql/math/matrix.hpp>
33#include <vector>
34
35namespace QuantLib {
36
37 class Quote;
38
40
52 public:
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> >());
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> >());
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());
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());
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
118
119 void performCalculations() const override;
121
123 Date maxDate() const override;
125
127 Rate minStrike() const override;
128 Rate maxStrike() const override;
130
132 const Period& maxSwapTenor() const override;
134
136
137 std::pair<Size,Size> locate(const Date& optionDate,
138 const Period& swapTenor) const {
139 return locate(timeFromReference(optionDate),
140 swapLength(swapTenor));
141 }
143 std::pair<Size,Size> locate(Time optionTime,
144 Time swapLength) const {
145 return std::make_pair(interpolation_.locateY(optionTime),
147 }
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
Definition: any.hpp:35