24#ifndef quantlib_zabr_interpolated_smile_section_hpp
25#define quantlib_zabr_interpolated_smile_section_hpp
27#include <ql/experimental/volatility/zabrinterpolation.hpp>
28#include <ql/handle.hpp>
29#include <ql/patterns/lazyobject.hpp>
30#include <ql/quotes/simplequote.hpp>
31#include <ql/termstructures/volatility/smilesection.hpp>
32#include <ql/time/daycounters/actual365fixed.hpp>
37template <
typename Evaluation>
44 const Date& optionDate,
46 const std::vector<Rate>& strikes,
47 bool hasFloatingStrikes,
55 bool isAlphaFixed =
false,
56 bool isBetaFixed =
false,
57 bool isNuFixed =
false,
58 bool isRhoFixed =
false,
59 bool isGammaFixed =
false,
60 bool vegaWeighted =
true,
61 ext::shared_ptr<EndCriteria>
endCriteria = ext::shared_ptr<EndCriteria>(),
62 ext::shared_ptr<OptimizationMethod> method = ext::shared_ptr<OptimizationMethod>(),
66 const Date& optionDate,
68 const std::vector<Rate>& strikes,
69 bool hasFloatingStrikes,
71 const std::vector<Volatility>& vols,
77 bool isAlphaFixed =
false,
78 bool isBetaFixed =
false,
79 bool isNuFixed =
false,
80 bool isRhoFixed =
false,
81 bool isGammaFixed =
false,
82 bool vegaWeighted =
true,
83 ext::shared_ptr<EndCriteria>
endCriteria = ext::shared_ptr<EndCriteria>(),
84 ext::shared_ptr<OptimizationMethod> method = ext::shared_ptr<OptimizationMethod>(),
127 mutable std::vector<Volatility>
vols_;
134 const ext::shared_ptr<OptimizationMethod>
method_;
137template <
typename Evaluation>
143template <
typename Evaluation>
147 return (*zabrInterpolation_)(strike,
true);
150template <
typename Evaluation>
153 return zabrInterpolation_->alpha();
156template <
typename Evaluation>
159 return zabrInterpolation_->beta();
162template <
typename Evaluation>
165 return zabrInterpolation_->nu();
168template <
typename Evaluation>
171 return zabrInterpolation_->rho();
174template <
typename Evaluation>
177 return zabrInterpolation_->rmsError();
180template <
typename Evaluation>
183 return zabrInterpolation_->maxError();
186template <
typename Evaluation>
190 return zabrInterpolation_->endCriteria();
193template <
typename Evaluation>
196 return actualStrikes_.front();
199template <
typename Evaluation>
202 return actualStrikes_.back();
205template <
typename Evaluation>
208 return forwardValue_;
211template <
typename Evaluation>
213 const Date& optionDate,
215 const std::vector<Rate>& strikes,
216 bool hasFloatingStrikes,
230 ext::shared_ptr<EndCriteria> endCriteria,
231 ext::shared_ptr<OptimizationMethod> method,
234 atmVolatility_(
std::move(atmVolatility)), volHandles_(volHandles), strikes_(strikes),
235 actualStrikes_(strikes), hasFloatingStrikes_(hasFloatingStrikes), vols_(volHandles.size()),
236 alpha_(alpha), beta_(beta), nu_(nu), rho_(rho), gamma_(gamma), isAlphaFixed_(isAlphaFixed),
237 isBetaFixed_(isBetaFixed), isNuFixed_(isNuFixed), isRhoFixed_(isRhoFixed),
238 isGammaFixed_(isGammaFixed), vegaWeighted_(vegaWeighted), endCriteria_(
std::move(endCriteria)),
239 method_(
std::move(method)) {
247template <
typename Evaluation>
249 const Date& optionDate,
251 const std::vector<Rate>& strikes,
252 bool hasFloatingStrikes,
254 const std::vector<Volatility>& volHandles,
266 ext::shared_ptr<EndCriteria> endCriteria,
267 ext::shared_ptr<OptimizationMethod> method,
272 volHandles_(volHandles.size()), strikes_(strikes), actualStrikes_(strikes),
273 hasFloatingStrikes_(hasFloatingStrikes), vols_(volHandles.size()), alpha_(alpha), beta_(beta),
274 nu_(nu), rho_(rho), gamma_(gamma), isAlphaFixed_(isAlphaFixed), isBetaFixed_(isBetaFixed),
275 isNuFixed_(isNuFixed), isRhoFixed_(isRhoFixed), isGammaFixed_(isGammaFixed),
276 vegaWeighted_(vegaWeighted), endCriteria_(
std::move(endCriteria)), method_(
std::move(method)) {
280 ext::shared_ptr<Quote>(
new SimpleQuote(volHandles[i])));
283template <
typename Evaluation>
285 ext::shared_ptr<ZabrInterpolation<Evaluation> > tmp(
287 actualStrikes_.begin(), actualStrikes_.end(), vols_.begin(),
288 exerciseTime(), forwardValue_, alpha_, beta_, nu_, rho_, gamma_,
289 isAlphaFixed_, isBetaFixed_, isNuFixed_, isRhoFixed_, isGammaFixed_,
290 vegaWeighted_, endCriteria_, method_));
291 swap(tmp, zabrInterpolation_);
294template <
typename Evaluation>
296 forwardValue_ = forward_->value();
298 actualStrikes_.clear();
300 for (
Size i = 0; i < volHandles_.size(); ++i) {
301 if (volHandles_[i]->isValid()) {
302 if (hasFloatingStrikes_) {
303 actualStrikes_.push_back(forwardValue_ + strikes_[i]);
304 vols_.push_back(atmVolatility_->value() +
305 volHandles_[i]->value());
307 actualStrikes_.push_back(strikes_[i]);
308 vols_.push_back(volHandles_[i]->value());
314 createInterpolation();
315 zabrInterpolation_->update();
318template <
typename Evaluation>
321 Real v = (*zabrInterpolation_)(strike,
true);
322 return v * v * exerciseTime();
Actual/365 (Fixed) day count convention.
Shared handle to an observable.
Framework for calculation on demand and result caching.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
purely virtual base class for market observables
market element returning a stored value
interest rate volatility smile section
Real atmLevel() const override
const Handle< Quote > forward_
Market data.
void performCalculations() const override
const ext::shared_ptr< EndCriteria > endCriteria_
bool isAlphaFixed_
Sabr interpolation settings.
Real minStrike() const override
EndCriteria::Type endCriteria() const
void createInterpolation() const
Creates the mutable SABRInterpolation.
std::vector< Rate > actualStrikes_
Only strikes corresponding to valid market data.
const ext::shared_ptr< OptimizationMethod > method_
ZabrInterpolatedSmileSection(const Date &optionDate, Handle< Quote > forward, const std::vector< Rate > &strikes, bool hasFloatingStrikes, Handle< Quote > atmVolatility, const std::vector< Handle< Quote > > &volHandles, Real alpha, Real beta, Real nu, Real rho, Real gamma, bool isAlphaFixed=false, bool isBetaFixed=false, bool isNuFixed=false, bool isRhoFixed=false, bool isGammaFixed=false, bool vegaWeighted=true, ext::shared_ptr< EndCriteria > endCriteria=ext::shared_ptr< EndCriteria >(), ext::shared_ptr< OptimizationMethod > method=ext::shared_ptr< OptimizationMethod >(), const DayCounter &dc=Actual365Fixed())
all market data are quotes
Real varianceImpl(Rate strike) const override
Real alpha_
Sabr parameters.
ext::shared_ptr< ZabrInterpolation< Evaluation > > zabrInterpolation_
std::vector< Volatility > vols_
std::vector< Rate > strikes_
const Handle< Quote > atmVolatility_
Real maxStrike() const override
std::vector< Handle< Quote > > volHandles_
Volatility volatilityImpl(Rate strike) const override
zabr smile interpolation between discrete volatility points.
Real Volatility
volatility
std::size_t Size
size of a container
void swap(Array &v, Array &w) noexcept