QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
interpolatedsmilesection.hpp
Go to the documentation of this file.
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) 2006 François du Vignaud
6 Copyright (C) 2015 Peter Caspers
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22/*! \file interpolatedsmilesection.hpp
23 \brief Interpolated smile section class
24*/
25
26#ifndef quantlib_interpolated_smile_section_hpp
27#define quantlib_interpolated_smile_section_hpp
28
32#include <ql/termstructure.hpp>
35#include <utility>
36
37namespace QuantLib {
38
39 template<class Interpolator>
41 public LazyObject {
42 public:
44 std::vector<Rate> strikes,
45 const std::vector<Handle<Quote> >& stdDevHandles,
47 const Interpolator& interpolator = Interpolator(),
48 const DayCounter& dc = Actual365Fixed(),
50 Real shift = 0.0);
52 std::vector<Rate> strikes,
53 const std::vector<Real>& stdDevs,
55 const Interpolator& interpolator = Interpolator(),
56 const DayCounter& dc = Actual365Fixed(),
58 Real shift = 0.0);
60 std::vector<Rate> strikes,
61 const std::vector<Handle<Quote> >& stdDevHandles,
63 const DayCounter& dc = Actual365Fixed(),
64 const Interpolator& interpolator = Interpolator(),
65 const Date& referenceDate = Date(),
67 Real shift = 0.0);
69 std::vector<Rate> strikes,
70 const std::vector<Real>& stdDevs,
72 const DayCounter& dc = Actual365Fixed(),
73 const Interpolator& interpolator = Interpolator(),
74 const Date& referenceDate = Date(),
76 Real shift = 0.0);
77
78 void performCalculations() const override;
79 Real varianceImpl(Rate strike) const override;
80 Volatility volatilityImpl(Rate strike) const override;
81 Real minStrike() const override { return strikes_.front(); }
82 Real maxStrike() const override { return strikes_.back(); }
83 Real atmLevel() const override { return atmLevel_->value(); }
84 void update() override;
85
86 private:
88 std::vector<Rate> strikes_;
89 std::vector<Handle<Quote> > stdDevHandles_;
91 mutable std::vector<Volatility> vols_;
93 };
94
95
96 template <class Interpolator>
98 Time timeToExpiry,
99 std::vector<Rate> strikes,
100 const std::vector<Handle<Quote> >& stdDevHandles,
101 Handle<Quote> atmLevel,
102 const Interpolator& interpolator,
103 const DayCounter& dc,
104 const VolatilityType type,
105 const Real shift)
106 : SmileSection(timeToExpiry, dc, type, shift),
107 exerciseTimeSquareRoot_(std::sqrt(exerciseTime())), strikes_(std::move(strikes)),
108 stdDevHandles_(stdDevHandles), atmLevel_(std::move(atmLevel)), vols_(stdDevHandles.size()) {
109 for (auto& stdDevHandle : stdDevHandles_)
110 LazyObject::registerWith(stdDevHandle);
112 // check strikes!!!!!!!!!!!!!!!!!!!!
113 interpolation_ = interpolator.interpolate(strikes_.begin(),
114 strikes_.end(),
115 vols_.begin());
116 }
117
118 template <class Interpolator>
120 Time timeToExpiry,
121 std::vector<Rate> strikes,
122 const std::vector<Real>& stdDevs,
123 Real atmLevel,
124 const Interpolator& interpolator,
125 const DayCounter& dc,
126 const VolatilityType type,
127 const Real shift)
128 : SmileSection(timeToExpiry, dc, type, shift),
129 exerciseTimeSquareRoot_(std::sqrt(exerciseTime())), strikes_(std::move(strikes)),
130 stdDevHandles_(stdDevs.size()), vols_(stdDevs.size()) {
131 // fill dummy handles to allow generic handle-based
132 // computations later on
133 for (Size i=0; i<stdDevs.size(); ++i)
134 stdDevHandles_[i] = Handle<Quote>(ext::shared_ptr<Quote>(new
135 SimpleQuote(stdDevs[i])));
137 (ext::shared_ptr<Quote>(new SimpleQuote(atmLevel)));
138 // check strikes!!!!!!!!!!!!!!!!!!!!
139 interpolation_ = interpolator.interpolate(strikes_.begin(),
140 strikes_.end(),
141 vols_.begin());
142 }
143
144 template <class Interpolator>
146 const Date& d,
147 std::vector<Rate> strikes,
148 const std::vector<Handle<Quote> >& stdDevHandles,
149 Handle<Quote> atmLevel,
150 const DayCounter& dc,
151 const Interpolator& interpolator,
152 const Date& referenceDate,
153 const VolatilityType type,
154 const Real shift)
155 : SmileSection(d, dc, referenceDate, type, shift),
156 exerciseTimeSquareRoot_(std::sqrt(exerciseTime())), strikes_(std::move(strikes)),
157 stdDevHandles_(stdDevHandles), atmLevel_(std::move(atmLevel)), vols_(stdDevHandles.size()) {
158 for (auto& stdDevHandle : stdDevHandles_)
159 LazyObject::registerWith(stdDevHandle);
161 // check strikes!!!!!!!!!!!!!!!!!!!!
162 interpolation_ = interpolator.interpolate(strikes_.begin(),
163 strikes_.end(),
164 vols_.begin());
165 }
166
167 template <class Interpolator>
169 const Date& d,
170 std::vector<Rate> strikes,
171 const std::vector<Real>& stdDevs,
172 Real atmLevel,
173 const DayCounter& dc,
174 const Interpolator& interpolator,
175 const Date& referenceDate,
176 const VolatilityType type,
177 const Real shift)
178 : SmileSection(d, dc, referenceDate, type, shift),
179 exerciseTimeSquareRoot_(std::sqrt(exerciseTime())), strikes_(std::move(strikes)),
180 stdDevHandles_(stdDevs.size()), vols_(stdDevs.size()) {
181 //fill dummy handles to allow generic handle-based
182 // computations later on
183 for (Size i=0; i<stdDevs.size(); ++i)
184 stdDevHandles_[i] = Handle<Quote>(ext::shared_ptr<Quote>(new
185 SimpleQuote(stdDevs[i])));
187 (ext::shared_ptr<Quote>(new SimpleQuote(atmLevel)));
188 // check strikes!!!!!!!!!!!!!!!!!!!!
189 interpolation_ = interpolator.interpolate(strikes_.begin(),
190 strikes_.end(),
191 vols_.begin());
192 }
193
194
195 template <class Interpolator>
197 const {
198 for (Size i=0; i<stdDevHandles_.size(); ++i)
199 vols_[i] = stdDevHandles_[i]->value()/exerciseTimeSquareRoot_;
200 interpolation_.update();
201 }
202
203 #ifndef __DOXYGEN__
204 template <class Interpolator>
206 calculate();
207 Real v = interpolation_(strike, true);
208 return v*v*exerciseTime();
209 }
210
211 template <class Interpolator>
213 calculate();
214 return interpolation_(strike, true);
215 }
216
217 template <class Interpolator>
221 }
222 #endif
223
224}
225
226#endif
Actual/365 (Fixed) day counter.
Actual/365 (Fixed) day count convention.
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Shared handle to an observable.
Definition: handle.hpp:41
InterpolatedSmileSection(Time expiryTime, std::vector< Rate > strikes, const std::vector< Handle< Quote > > &stdDevHandles, Handle< Quote > atmLevel, const Interpolator &interpolator=Interpolator(), const DayCounter &dc=Actual365Fixed(), VolatilityType type=ShiftedLognormal, Real shift=0.0)
std::vector< Handle< Quote > > stdDevHandles_
Volatility volatilityImpl(Rate strike) const override
Real varianceImpl(Rate strike) const override
base class for 1-D interpolations.
Framework for calculation on demand and result caching.
Definition: lazyobject.hpp:35
void update() override
Definition: lazyobject.hpp:188
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
market element returning a stored value
Definition: simplequote.hpp:33
interest rate volatility smile section
virtual const Date & referenceDate() const
void update() override
virtual Rate shift() const
Date d
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
framework for calculation on demand and result caching
linear interpolation between discrete points
Definition: any.hpp:35
STL namespace.
ext::shared_ptr< BlackVolTermStructure > v
simple quote class
Smile section base class.
base class for term structures