QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
kinterpolatedyoyoptionletvolatilitysurface.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2009 Chris Kenyon
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
24#ifndef quantlib_k_interpolated_yoy_optionlet_volatility_surface_hpp
25#define quantlib_k_interpolated_yoy_optionlet_volatility_surface_hpp
26
27#include <ql/experimental/inflation/yoyoptionletstripper.hpp>
28#include <utility>
29
30namespace QuantLib {
31
33
45 template<class Interpolator1D>
48 public:
53 const Calendar&,
55 const DayCounter& dc,
56 const Period& lag,
57 const ext::shared_ptr<YoYCapFloorTermPriceSurface>& capFloorPrices,
58 ext::shared_ptr<YoYInflationCapFloorEngine> pricer,
59 ext::shared_ptr<YoYOptionletStripper> yoyOptionletStripper,
60 Real slope,
61 const Interpolator1D& interpolator = Interpolator1D(),
63 Real displacement = 0.0);
64
65 Real minStrike() const override;
66 Real maxStrike() const override;
67 Date maxDate() const override;
68 std::pair<std::vector<Rate>, std::vector<Volatility> > Dslice(
69 const Date &d) const;
70
71 protected:
72 virtual Volatility volatilityImpl(const Date &d,
73 Rate strike) const;
74 Volatility volatilityImpl(Time length, Rate strike) const override;
75 virtual void performCalculations() const;
76
77 ext::shared_ptr<YoYCapFloorTermPriceSurface> capFloorPrices_;
78 ext::shared_ptr<YoYInflationCapFloorEngine> yoyInflationCouponPricer_;
79 ext::shared_ptr<YoYOptionletStripper> yoyOptionletStripper_;
80
82 mutable Real slope_;
83 mutable bool lastDateisSet_ = false;
84 mutable Date lastDate_;
86 mutable std::pair<std::vector<Rate>, std::vector<Volatility> > slice_;
87 private:
88 void updateSlice(const Date &d) const;
89 };
90
91
92 // template definitions
93
94 template <class Interpolator1D>
97 const Natural settlementDays,
98 const Calendar& cal,
99 const BusinessDayConvention bdc,
100 const DayCounter& dc,
101 const Period& lag,
102 const ext::shared_ptr<YoYCapFloorTermPriceSurface>& capFloorPrices,
103 ext::shared_ptr<YoYInflationCapFloorEngine> pricer,
104 ext::shared_ptr<YoYOptionletStripper> yoyOptionletStripper,
105 const Real slope,
106 const Interpolator1D& interpolator,
107 VolatilityType volType,
108 Real displacement)
109 : YoYOptionletVolatilitySurface(settlementDays,
110 cal,
111 bdc,
112 dc,
113 lag,
114 capFloorPrices->yoyIndex()->frequency(),
115 capFloorPrices->yoyIndex()->interpolated(),
116 volType,
117 displacement),
118 capFloorPrices_(capFloorPrices), yoyInflationCouponPricer_(std::move(pricer)),
119 yoyOptionletStripper_(std::move(yoyOptionletStripper)), factory1D_(interpolator),
120 slope_(slope) {
122 }
123
124
125 template<class Interpolator1D>
127 maxDate() const {
128 Size n = capFloorPrices_->maturities().size();
129 return referenceDate()+capFloorPrices_->maturities()[n-1];
130 }
131
132
133 template<class Interpolator1D>
135 minStrike() const {
136 return capFloorPrices_->strikes().front();
137 }
138
139
140 template<class Interpolator1D>
142 maxStrike() const {
143 return capFloorPrices_->strikes().back();
144 }
145
146
147 template<class Interpolator1D>
149 performCalculations() const {
150
151 // slope is the assumption on the initial caplet volatility change
152 yoyOptionletStripper_->initialize(capFloorPrices_,
153 yoyInflationCouponPricer_,
154 slope_);
155 }
156
157
158 template<class Interpolator1D>
160 volatilityImpl(const Date &d, Rate strike) const {
161 updateSlice(d);
162 if (this->allowsExtrapolation()) {
163 this->tempKinterpolation_.enableExtrapolation();
164 }
165 return tempKinterpolation_(strike);
166 }
167
168
169 template<class Interpolator1D>
170 std::pair<std::vector<Rate>, std::vector<Volatility> >
172 Dslice(const Date &d) const {
173 updateSlice(d);
174 return slice_;
175 }
176
177
178 template<class Interpolator1D>
180 volatilityImpl(Time length, Rate strike) const {
181
182 auto years = (Natural)floor(length);
183 auto days = (Natural)floor((length - years) * 365.0);
184 Date d = referenceDate() + Period(years, Years) + Period(days, Days);
185
186 return this->volatilityImpl(d, strike);
187 }
188
189 template<class Interpolator1D>
191 updateSlice(const Date &d) const {
192
193 if (!lastDateisSet_ || d != lastDate_ ) {
194 slice_ = yoyOptionletStripper_->slice(d);
195
196 tempKinterpolation_ =
197 factory1D_.interpolate( slice_.first.begin(),
198 slice_.first.end(),
199 slice_.second.begin() );
200 lastDateisSet_ = true;
201 lastDate_ = d;
202 }
203 }
204
205}
206
207#endif
208
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
base class for 1-D interpolations.
virtual Volatility volatilityImpl(const Date &d, Rate strike) const
Real minStrike() const override
the minimum strike for which the term structure can return vols
KInterpolatedYoYOptionletVolatilitySurface(Natural settlementDays, const Calendar &, BusinessDayConvention bdc, const DayCounter &dc, const Period &lag, const ext::shared_ptr< YoYCapFloorTermPriceSurface > &capFloorPrices, ext::shared_ptr< YoYInflationCapFloorEngine > pricer, ext::shared_ptr< YoYOptionletStripper > yoyOptionletStripper, Real slope, const Interpolator1D &interpolator=Interpolator1D(), VolatilityType volType=ShiftedLognormal, Real displacement=0.0)
Date maxDate() const override
the latest date for which the curve can return values
std::pair< std::vector< Rate >, std::vector< Volatility > > slice_
std::pair< std::vector< Rate >, std::vector< Volatility > > Dslice(const Date &d) const
Real maxStrike() const override
the maximum strike for which the term structure can return vols
virtual Natural settlementDays() const
the settlementDays used for reference date calculation
virtual Real displacement() const
Returns the displacement for lognormal volatilities.
BusinessDayConvention
Business Day conventions.
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
Real years(const Period &p)
Definition: period.cpp:279
Real days(const Period &p)
Definition: period.cpp:330
STL namespace.