Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
capfloortermvolsurface.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file capfloortermvolsurface.hpp
20 \brief Cap/floor smile volatility surface
21*/
22
23#ifndef quantext_cap_floor_term_vol_surface_hpp
24#define quantext_cap_floor_term_vol_surface_hpp
25
26#include <ql/math/interpolations/interpolation2d.hpp>
27#include <ql/patterns/lazyobject.hpp>
28#include <ql/quote.hpp>
29#include <ql/termstructures/volatility/capfloor/capfloortermvolatilitystructure.hpp>
30#include <ql/time/daycounters/actual365fixed.hpp>
31#include <vector>
32
33namespace QuantExt {
34using namespace QuantLib;
35
36//! Cap/floor term-volatility surface
37/*! This is a base class and defines the interface of capfloor term
38 surface which will be derived from this one.
39*/
40class CapFloorTermVolSurface : public LazyObject, public CapFloorTermVolatilityStructure {
41public:
42 //! default constructor
43 CapFloorTermVolSurface(QuantLib::BusinessDayConvention bdc,
44 const QuantLib::DayCounter& dc = QuantLib::DayCounter(),
45 std::vector<QuantLib::Period> optionTenors = {},
46 std::vector<QuantLib::Rate> strikes = {})
47 : CapFloorTermVolatilityStructure(bdc, dc), optionTenors_(optionTenors), strikes_(strikes) {};
48
49 //! initialize with a fixed reference date
50 CapFloorTermVolSurface(const QuantLib::Date& referenceDate,
51 const QuantLib::Calendar& cal,
52 BusinessDayConvention bdc,
53 const DayCounter& dc = QuantLib::DayCounter(),
54 std::vector<QuantLib::Period> optionTenors = {},
55 std::vector<QuantLib::Rate> strikes = {})
56 : CapFloorTermVolatilityStructure(referenceDate, cal, bdc, dc), optionTenors_(optionTenors), strikes_(strikes) {};
57
58 //! calculate the reference date based on the global evaluation date
59 CapFloorTermVolSurface(QuantLib::Natural settlementDays,
60 const QuantLib::Calendar& cal,
61 QuantLib::BusinessDayConvention bdc,
62 const QuantLib::DayCounter& dc = QuantLib::DayCounter(),
63 std::vector<QuantLib::Period> optionTenors = {},
64 std::vector<QuantLib::Rate> strikes = {})
65 : CapFloorTermVolatilityStructure(settlementDays, cal, bdc, dc), optionTenors_(optionTenors), strikes_(strikes) {};
66
67 const std::vector<QuantLib::Period>& optionTenors() const { return optionTenors_; }
68 const std::vector<QuantLib::Rate>& strikes() const { return strikes_; }
69
70 //! \name LazyObject interface
71 //@{
72 void update() override {
73 CapFloorTermVolatilityStructure::update();
74 LazyObject::update();
75 }
76 void performCalculations() const override {};
77 //@}
78
79protected:
80 std::vector<QuantLib::Period> optionTenors_;
81 std::vector<QuantLib::Rate> strikes_;
82};
83
84//! Cap/floor smile volatility surface
85/*! This class provides the volatility for a given cap/floor interpolating
86 a volatility surface whose elements are the market term volatilities
87 of a set of caps/floors with given length and given strike.
88
89 This is a copy of the QL CapFloorTermVolSurface but gives the option to use
90 BiLinear instead of BiCubic Spline interpolation.
91 Default is BiCubic Spline for backwards compatibility with QuantLib
92*/
94public:
96
97 //! floating reference date, floating market data
98 CapFloorTermVolSurfaceExact(Natural settlementDays, const Calendar& calendar, BusinessDayConvention bdc,
99 const std::vector<Period>& optionTenors, const std::vector<Rate>& strikes,
100 const std::vector<std::vector<Handle<Quote> > >&, const DayCounter& dc = Actual365Fixed(),
102 //! fixed reference date, floating market data
103 CapFloorTermVolSurfaceExact(const Date& settlementDate, const Calendar& calendar, BusinessDayConvention bdc,
104 const std::vector<Period>& optionTenors, const std::vector<Rate>& strikes,
105 const std::vector<std::vector<Handle<Quote> > >&, const DayCounter& dc = Actual365Fixed(),
107 //! fixed reference date, fixed market data
108 CapFloorTermVolSurfaceExact(const Date& settlementDate, const Calendar& calendar, BusinessDayConvention bdc,
109 const std::vector<Period>& optionTenors, const std::vector<Rate>& strikes,
110 const Matrix& volatilities, const DayCounter& dc = Actual365Fixed(),
112 //! floating reference date, fixed market data
113 CapFloorTermVolSurfaceExact(Natural settlementDays, const Calendar& calendar, BusinessDayConvention bdc,
114 const std::vector<Period>& optionTenors, const std::vector<Rate>& strikes,
115 const Matrix& volatilities, const DayCounter& dc = Actual365Fixed(),
117 //! \name TermStructure interface
118 //@{
119 Date maxDate() const override;
120 //@}
121 //! \name VolatilityTermStructure interface
122 //@{
123 Real minStrike() const override;
124 Real maxStrike() const override;
125 //@}
126 //! \name LazyObject interface
127 //@{
128 void update() override;
129 void performCalculations() const override;
130 //@}
131 //! \name some inspectors
132 //@{
133 const std::vector<Date>& optionDates() const;
134 const std::vector<Time>& optionTimes() const;
136 //@}
137protected:
138 Volatility volatilityImpl(Time t, Rate strike) const override;
139
140private:
141 void checkInputs() const;
144 void interpolate();
145
147 mutable std::vector<Date> optionDates_;
148 mutable std::vector<Time> optionTimes_;
150
152
153 std::vector<std::vector<Handle<Quote> > > volHandles_;
154 mutable Matrix vols_;
155
156 // make it not mutable if possible
158 mutable Interpolation2D interpolation_;
159};
160
161//! In order to convert CapFloorTermVolSurface::InterpolationMethod to string
162std::ostream& operator<<(std::ostream& out, CapFloorTermVolSurfaceExact::InterpolationMethod method);
163
164// inline definitions
165
167 calculate();
168 return optionDateFromTenor(optionTenors_.back());
169}
170
171inline Real CapFloorTermVolSurfaceExact::minStrike() const { return strikes_.front(); }
172
173inline Real CapFloorTermVolSurfaceExact::maxStrike() const { return strikes_.back(); }
174
175inline Volatility CapFloorTermVolSurfaceExact::volatilityImpl(Time t, Rate strike) const {
176 calculate();
177 return interpolation_(strike, t, true);
178}
179
180inline const std::vector<Date>& CapFloorTermVolSurfaceExact::optionDates() const {
181 // what if quotes are not available?
182 calculate();
183 return optionDates_;
184}
185
186inline const std::vector<Time>& CapFloorTermVolSurfaceExact::optionTimes() const {
187 // what if quotes are not available?
188 calculate();
189 return optionTimes_;
190}
191
194}
195
196} // namespace QuantExt
197
198#endif
Cap/floor smile volatility surface.
CapFloorTermVolSurfaceExact(const Date &settlementDate, const Calendar &calendar, BusinessDayConvention bdc, const std::vector< Period > &optionTenors, const std::vector< Rate > &strikes, const Matrix &volatilities, const DayCounter &dc=Actual365Fixed(), InterpolationMethod interpolationMethod=BicubicSpline)
fixed reference date, fixed market data
std::vector< std::vector< Handle< Quote > > > volHandles_
InterpolationMethod interpolationMethod() const
const std::vector< Time > & optionTimes() const
CapFloorTermVolSurfaceExact(Natural settlementDays, const Calendar &calendar, BusinessDayConvention bdc, const std::vector< Period > &optionTenors, const std::vector< Rate > &strikes, const std::vector< std::vector< Handle< Quote > > > &, const DayCounter &dc=Actual365Fixed(), InterpolationMethod interpolationMethod=BicubicSpline)
floating reference date, floating market data
CapFloorTermVolSurfaceExact(Natural settlementDays, const Calendar &calendar, BusinessDayConvention bdc, const std::vector< Period > &optionTenors, const std::vector< Rate > &strikes, const Matrix &volatilities, const DayCounter &dc=Actual365Fixed(), InterpolationMethod interpolationMethod=BicubicSpline)
floating reference date, fixed market data
const std::vector< Date > & optionDates() const
CapFloorTermVolSurfaceExact(const Date &settlementDate, const Calendar &calendar, BusinessDayConvention bdc, const std::vector< Period > &optionTenors, const std::vector< Rate > &strikes, const std::vector< std::vector< Handle< Quote > > > &, const DayCounter &dc=Actual365Fixed(), InterpolationMethod interpolationMethod=BicubicSpline)
fixed reference date, floating market data
Volatility volatilityImpl(Time t, Rate strike) const override
Cap/floor term-volatility surface.
CapFloorTermVolSurface(QuantLib::Natural settlementDays, const QuantLib::Calendar &cal, QuantLib::BusinessDayConvention bdc, const QuantLib::DayCounter &dc=QuantLib::DayCounter(), std::vector< QuantLib::Period > optionTenors={}, std::vector< QuantLib::Rate > strikes={})
calculate the reference date based on the global evaluation date
const std::vector< QuantLib::Period > & optionTenors() const
const std::vector< QuantLib::Rate > & strikes() const
std::vector< QuantLib::Rate > strikes_
CapFloorTermVolSurface(QuantLib::BusinessDayConvention bdc, const QuantLib::DayCounter &dc=QuantLib::DayCounter(), std::vector< QuantLib::Period > optionTenors={}, std::vector< QuantLib::Rate > strikes={})
default constructor
CapFloorTermVolSurface(const QuantLib::Date &referenceDate, const QuantLib::Calendar &cal, BusinessDayConvention bdc, const DayCounter &dc=QuantLib::DayCounter(), std::vector< QuantLib::Period > optionTenors={}, std::vector< QuantLib::Rate > strikes={})
initialize with a fixed reference date
std::vector< QuantLib::Period > optionTenors_
std::ostream & operator<<(std::ostream &out, EquityReturnType t)