Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
kinterpolatedyoyoptionletvolatilitysurface.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2009 Chris Kenyon
3
4 This file is part of QuantLib, a free-software/open-source library
5 for financial quantitative analysts and developers - http://quantlib.org/
6
7 QuantLib is free software: you can redistribute it and/or modify it
8 under the terms of the QuantLib license. You should have received a
9 copy of the license along with this program; if not, please email
10 <quantlib-dev@lists.sf.net>. The license is also available online at
11 <http://quantlib.org/license.shtml>.
12
13 This program is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the license for more details.
16*/
17
18/*! \file kinterpolatedyoyoptionletvolatilitysurface.hpp
19 \brief fixed version of ql class (see patch 1,2,3 in the comments below)
20*/
21
22/*
23 Copyright (C) 2016 Quaternion Risk Management Ltd
24
25 This file is part of ORE, a free-software/open-source library
26 for transparent pricing and risk analysis - http://opensourcerisk.org
27
28 ORE is free software: you can redistribute it and/or modify it
29 under the terms of the Modified BSD License. You should have received a
30 copy of the license along with this program.
31 The license is also available online at <http://opensourcerisk.org>
32
33 This program is distributed on the basis that it will form a useful
34 contribution to risk analytics and model standardisation, but WITHOUT
35 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
36 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
37*/
38
39#pragma once
40
41#include <ql/experimental/inflation/yoyoptionletstripper.hpp>
42
43namespace QuantExt {
44 using namespace QuantLib;
45
46 //! K-interpolated YoY optionlet volatility
47 /*! The stripper provides curves in the T direction along each K.
48 We don't know whether this is interpolating or fitting in the
49 T direction. Our K direction interpolations are not model
50 fitting.
51
52 An alternative design would be a
53 FittedYoYOptionletVolatilitySurface taking a model, e.g. SABR
54 in the interest rate world. This could use the same stripping
55 in the T direction along each K.
56
57 \bug Tests currently fail.
58 */
59 template<class Interpolator1D>
62 public:
63 //! \name Constructor
64 //! calculate the reference date based on the global evaluation date
66 const Natural settlementDays,
67 const Calendar&,
68 const BusinessDayConvention bdc,
69 const DayCounter& dc,
70 const Period& lag,
71 const ext::shared_ptr<YoYCapFloorTermPriceSurface>& capFloorPrices,
72 const ext::shared_ptr<QuantLib::YoYInflationCapFloorEngine>& pricer,
73 const ext::shared_ptr<YoYOptionletStripper>& yoyOptionletStripper,
74 const Real slope,
75 const Interpolator1D& interpolator = Interpolator1D(),
76 VolatilityType volType = ShiftedLognormal,
77 Real displacement = 0.0);
78
79 virtual Real minStrike() const override;
80 virtual Real maxStrike() const override;
81 virtual Date maxDate() const override;
82 std::pair<std::vector<Rate>, std::vector<Volatility> > Dslice(
83 const Date &d) const;
84
85 protected:
86 virtual Volatility volatilityImpl(const Date &d,
87 Rate strike) const;
88 virtual Volatility volatilityImpl(Time length,
89 Rate strike) const override;
90 virtual void performCalculations() const;
91
92 ext::shared_ptr<YoYCapFloorTermPriceSurface> capFloorPrices_;
93 ext::shared_ptr<QuantLib::YoYInflationCapFloorEngine> yoyInflationCouponPricer_;
94 ext::shared_ptr<YoYOptionletStripper> yoyOptionletStripper_;
95
96 mutable Interpolator1D factory1D_;
97 mutable Real slope_;
98 mutable bool lastDateisSet_;
99 mutable Date lastDate_;
100 mutable Interpolation tempKinterpolation_;
101 mutable std::pair<std::vector<Rate>, std::vector<Volatility> > slice_;
102 private:
103 void updateSlice(const Date &d) const;
104 };
105
106
107 // template definitions
108
109 template<class Interpolator1D>
112 const Natural settlementDays,
113 const Calendar& cal,
114 const BusinessDayConvention bdc,
115 const DayCounter& dc,
116 const Period &lag,
117 const ext::shared_ptr<YoYCapFloorTermPriceSurface> &capFloorPrices,
118 const ext::shared_ptr<QuantLib::YoYInflationCapFloorEngine> &pricer,
119 const ext::shared_ptr<YoYOptionletStripper> &yoyOptionletStripper,
120 const Real slope,
121 const Interpolator1D &interpolator,
122 VolatilityType volType,
123 Real displacement)
124 : YoYOptionletVolatilitySurface(settlementDays, cal, bdc, dc, lag,
125 capFloorPrices->yoyIndex()->frequency(),
126 capFloorPrices->yoyIndex()->interpolated(),
127 volType, displacement),
128 capFloorPrices_(capFloorPrices), yoyInflationCouponPricer_(pricer),
129 yoyOptionletStripper_(yoyOptionletStripper),
130 factory1D_(interpolator), slope_(slope), lastDateisSet_(false) {
132 }
133
134
135 template<class Interpolator1D>
137 maxDate() const {
138 Size n = capFloorPrices_->maturities().size();
139 return referenceDate()+capFloorPrices_->maturities()[n-1];
140 }
141
142
143 template<class Interpolator1D>
145 minStrike() const {
146 return capFloorPrices_->strikes().front();
147 }
148
149
150 template<class Interpolator1D>
152 maxStrike() const {
153 return capFloorPrices_->strikes().back();
154 }
155
156
157 template<class Interpolator1D>
159 performCalculations() const {
160
161 // slope is the assumption on the initial caplet volatility change
162 yoyOptionletStripper_->initialize(capFloorPrices_,
163 yoyInflationCouponPricer_,
164 slope_);
165 }
166
167
168 template<class Interpolator1D>
170 volatilityImpl(const Date &d, Rate strike) const {
171 updateSlice(d);
172 // patch 1 for QL class:
173 // extrapolation on interpolator (if enabled in this class)
174 if (this->allowsExtrapolation()) {
175 this->tempKinterpolation_.enableExtrapolation();
176 }
177 return tempKinterpolation_(strike);
178 }
179
180
181 template<class Interpolator1D>
182 std::pair<std::vector<Rate>, std::vector<Volatility> >
184 Dslice(const Date &d) const {
185 updateSlice(d);
186 return slice_;
187 }
188
189
190 template<class Interpolator1D>
192 volatilityImpl(Time length, Rate strike) const {
193
194 Natural years = (Natural)floor(length);
195 Natural days = (Natural)floor((length - years) * 365.0);
196 Date d = referenceDate() + Period(years, Years) + Period(days, Days);
197
198 return this->volatilityImpl(d, strike);
199 }
200
201 template<class Interpolator1D>
203 updateSlice(const Date &d) const {
204
205 if (!lastDateisSet_ || d != lastDate_ ) {
206 // patch 2 for QL class:
207 // add observation lag, this is subtracted again in the stripper
208 Date d_eff = d + capFloorPrices_->observationLag();
209 // patch 3 for QL class:
210 // flat extrapolation in date direction, if extrapolation is enabled
211 if (this->allowsExtrapolation())
212 d_eff = std::min(d_eff, maxDate());
213 slice_ = yoyOptionletStripper_->slice(d_eff);
214
215 tempKinterpolation_ =
216 factory1D_.interpolate( slice_.first.begin(),
217 slice_.first.end(),
218 slice_.second.begin() );
219 lastDateisSet_ = true;
220 lastDate_ = d;
221 }
222 }
223
224}
225
virtual Volatility volatilityImpl(const Date &d, Rate strike) const
ext::shared_ptr< QuantLib::YoYInflationCapFloorEngine > yoyInflationCouponPricer_
KInterpolatedYoYOptionletVolatilitySurface(const Natural settlementDays, const Calendar &, const BusinessDayConvention bdc, const DayCounter &dc, const Period &lag, const ext::shared_ptr< YoYCapFloorTermPriceSurface > &capFloorPrices, const ext::shared_ptr< QuantLib::YoYInflationCapFloorEngine > &pricer, const ext::shared_ptr< YoYOptionletStripper > &yoyOptionletStripper, const Real slope, const Interpolator1D &interpolator=Interpolator1D(), VolatilityType volType=ShiftedLognormal, Real displacement=0.0)
std::pair< std::vector< Rate >, std::vector< Volatility > > slice_
std::pair< std::vector< Rate >, std::vector< Volatility > > Dslice(const Date &d) const