QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
swaptionvolcube.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2006 Ferdinando Ametrano
5 Copyright (C) 2015 Peter Caspers
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
25#ifndef quantlib_swaption_volatility_cube_h
26#define quantlib_swaption_volatility_cube_h
27
28#include <ql/termstructures/volatility/swaption/swaptionvoldiscrete.hpp>
29#include <ql/termstructures/volatility/smilesection.hpp>
30
31namespace QuantLib {
32
33 class SwapIndex;
34 class Quote;
35
37
41 public:
43 const std::vector<Period>& optionTenors,
44 const std::vector<Period>& swapTenors,
45 const std::vector<Spread>& strikeSpreads,
46 std::vector<std::vector<Handle<Quote> > > volSpreads,
47 ext::shared_ptr<SwapIndex> swapIndexBase,
48 ext::shared_ptr<SwapIndex> shortSwapIndexBase,
51
52 DayCounter dayCounter() const override { return atmVol_->dayCounter(); }
53 Date maxDate() const override { return atmVol_->maxDate(); }
54 Time maxTime() const override { return atmVol_->maxTime(); }
55 const Date& referenceDate() const override { return atmVol_->referenceDate(); }
56 Calendar calendar() const override { return atmVol_->calendar(); }
57 Natural settlementDays() const override { return atmVol_->settlementDays(); }
59
60 Rate minStrike() const override { return -QL_MAX_REAL; }
61 Rate maxStrike() const override { return QL_MAX_REAL; }
63
65 const Period& maxSwapTenor() const override { return atmVol_->maxSwapTenor(); }
67
69 Rate atmStrike(const Date& optionDate,
70 const Period& swapTenor) const;
71 Rate atmStrike(const Period& optionTenor,
72 const Period& swapTenor) const {
73 Date optionDate = optionDateFromTenor(optionTenor);
74 return atmStrike(optionDate, swapTenor);
75 }
77 const std::vector<Spread>& strikeSpreads() const { return strikeSpreads_; }
78 const std::vector<std::vector<Handle<Quote> > >& volSpreads() const { return volSpreads_; }
79 ext::shared_ptr<SwapIndex> swapIndexBase() const { return swapIndexBase_; }
80 ext::shared_ptr<SwapIndex> shortSwapIndexBase() const { return shortSwapIndexBase_; }
83
85 void performCalculations() const override {
86 QL_REQUIRE(nStrikes_ >= requiredNumberOfStrikes(),
87 "too few strikes (" << nStrikes_
88 << ") required are at least "
91 }
93 VolatilityType volatilityType() const override;
94
95 protected:
97 virtual Size requiredNumberOfStrikes() const { return 2; }
98 Volatility volatilityImpl(Time optionTime, Time swapLength, Rate strike) const override;
100 volatilityImpl(const Date& optionDate, const Period& swapTenor, Rate strike) const override;
101 Real shiftImpl(Time optionTime, Time swapLength) const override;
104 std::vector<Spread> strikeSpreads_;
105 mutable std::vector<Rate> localStrikes_;
106 mutable std::vector<Volatility> localSmile_;
107 std::vector<std::vector<Handle<Quote> > > volSpreads_;
108 ext::shared_ptr<SwapIndex> swapIndexBase_, shortSwapIndexBase_;
110 };
111
112 // inline
113
115 return atmVol_->volatilityType();
116 }
117
119 Time optionTime,
120 Time swapLength,
121 Rate strike) const {
122 return smileSectionImpl(optionTime, swapLength)->volatility(strike);
123 }
124
126 const Date& optionDate,
127 const Period& swapTenor,
128 Rate strike) const {
129 return smileSectionImpl(optionDate, swapTenor)->volatility(strike);
130 }
131
133 Time swapLength) const {
134 return atmVol_->shift(optionTime, swapLength);
135 }
136}
137
138#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
swaption-volatility cube
Rate atmStrike(const Date &optionDate, const Period &swapTenor) const
void performCalculations() const override
Calendar calendar() const override
the calendar used for reference and/or option date calculation
Volatility volatilityImpl(Time optionTime, Time swapLength, Rate strike) const override
ext::shared_ptr< SwapIndex > swapIndexBase_
std::vector< Spread > strikeSpreads_
Rate maxStrike() const override
the maximum strike for which the term structure can return vols
Rate minStrike() const override
the minimum strike for which the term structure can return vols
Handle< SwaptionVolatilityStructure > atmVol() const
const std::vector< std::vector< Handle< Quote > > > & volSpreads() const
Handle< SwaptionVolatilityStructure > atmVol_
const Date & referenceDate() const override
the date at which discount = 1.0 and/or variance = 0.0
Real shiftImpl(Time optionTime, Time swapLength) const override
ext::shared_ptr< SwapIndex > shortSwapIndexBase_
std::vector< Volatility > localSmile_
VolatilityType volatilityType() const override
volatility type
ext::shared_ptr< SwapIndex > shortSwapIndexBase() const
Natural settlementDays() const override
the settlementDays used for reference date calculation
DayCounter dayCounter() const override
the day counter used for date/time conversion
Date maxDate() const override
the latest date for which the curve can return values
virtual Size requiredNumberOfStrikes() const
std::vector< std::vector< Handle< Quote > > > volSpreads_
ext::shared_ptr< SwapIndex > swapIndexBase() const
Rate atmStrike(const Period &optionTenor, const Period &swapTenor) const
const Period & maxSwapTenor() const override
the largest length for which the term structure can return vols
Time maxTime() const override
the latest time for which the curve can return values
const std::vector< Spread > & strikeSpreads() const
const std::vector< Period > & swapTenors() const
const std::vector< Period > & optionTenors() const
virtual ext::shared_ptr< SmileSection > smileSectionImpl(const Date &optionDate, const Period &swapTenor) const
Time swapLength(const Period &swapTenor) const
implements the conversion between swap tenor and swap (time) length
Date optionDateFromTenor(const Period &) const
period/date conversion
#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
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
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35