QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
sabrinterpolatedsmilesection.cpp
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) 2007 Cristina Duminuco
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
23#include <ql/settings.hpp>
25#include <utility>
26
27namespace QuantLib {
28
30 const Date& optionDate,
31 Handle<Quote> forward,
32 const std::vector<Rate>& strikes,
33 bool hasFloatingStrikes,
34 Handle<Quote> atmVolatility,
35 const std::vector<Handle<Quote> >& volHandles,
36 Real alpha,
37 Real beta,
38 Real nu,
39 Real rho,
40 bool isAlphaFixed,
41 bool isBetaFixed,
42 bool isNuFixed,
43 bool isRhoFixed,
44 bool vegaWeighted,
45 ext::shared_ptr<EndCriteria> endCriteria,
46 ext::shared_ptr<OptimizationMethod> method,
47 const DayCounter& dc,
48 const Real shift)
49 : SmileSection(optionDate, dc, Date(), ShiftedLognormal, shift), forward_(std::move(forward)),
50 atmVolatility_(std::move(atmVolatility)), volHandles_(volHandles), strikes_(strikes),
51 actualStrikes_(strikes), hasFloatingStrikes_(hasFloatingStrikes), vols_(volHandles.size()),
52 alpha_(alpha), beta_(beta), nu_(nu), rho_(rho), isAlphaFixed_(isAlphaFixed),
53 isBetaFixed_(isBetaFixed), isNuFixed_(isNuFixed), isRhoFixed_(isRhoFixed),
54 vegaWeighted_(vegaWeighted), endCriteria_(std::move(endCriteria)), method_(std::move(method)),
55 evaluationDate_(Settings::instance().evaluationDate()) {
56
59 for (auto& volHandle : volHandles_)
60 LazyObject::registerWith(volHandle);
61 }
62
64 const Date& optionDate,
65 const Rate& forward,
66 const std::vector<Rate>& strikes,
67 bool hasFloatingStrikes,
68 const Volatility& atmVolatility,
69 const std::vector<Volatility>& volHandles,
70 Real alpha,
71 Real beta,
72 Real nu,
73 Real rho,
74 bool isAlphaFixed,
75 bool isBetaFixed,
76 bool isNuFixed,
77 bool isRhoFixed,
78 bool vegaWeighted,
79 ext::shared_ptr<EndCriteria> endCriteria,
80 ext::shared_ptr<OptimizationMethod> method,
81 const DayCounter& dc,
82 const Real shift)
83 : SmileSection(optionDate, dc, Date(), ShiftedLognormal, shift),
84 forward_(Handle<Quote>(ext::shared_ptr<Quote>(new SimpleQuote(forward)))),
85 atmVolatility_(Handle<Quote>(ext::shared_ptr<Quote>(new SimpleQuote(atmVolatility)))),
86 volHandles_(volHandles.size()), strikes_(strikes), actualStrikes_(strikes),
87 hasFloatingStrikes_(hasFloatingStrikes), vols_(volHandles.size()), alpha_(alpha), beta_(beta),
88 nu_(nu), rho_(rho), isAlphaFixed_(isAlphaFixed), isBetaFixed_(isBetaFixed),
89 isNuFixed_(isNuFixed), isRhoFixed_(isRhoFixed), vegaWeighted_(vegaWeighted),
90 endCriteria_(std::move(endCriteria)), method_(std::move(method)),
91 evaluationDate_(Settings::instance().evaluationDate()) {
92
93 for (Size i = 0; i < volHandles_.size(); ++i)
94 volHandles_[i] = Handle<Quote>(ext::shared_ptr<Quote>(new SimpleQuote(volHandles[i])));
95 }
96
98 ext::shared_ptr<SABRInterpolation> tmp(new SABRInterpolation(
99 actualStrikes_.begin(), actualStrikes_.end(), vols_.begin(),
101 alpha_, beta_, nu_, rho_,
103 endCriteria_, method_, 0.0020, false, 50, shift()));
105 }
106
108 forwardValue_ = forward_->value();
109 vols_.clear();
110 actualStrikes_.clear();
111 // we populate the volatilities, skipping the invalid ones
112 for (Size i=0; i<volHandles_.size(); ++i) {
113 if (volHandles_[i]->isValid()) {
115 actualStrikes_.push_back(forwardValue_ + strikes_[i]);
116 vols_.push_back(atmVolatility_->value() + volHandles_[i]->value());
117 } else {
118 actualStrikes_.push_back(strikes_[i]);
119 vols_.push_back(volHandles_[i]->value());
120 }
121 }
122 }
123 // we are recreating the sabrinterpolation object unconditionnaly to
124 // avoid iterator invalidation
126 sabrInterpolation_->update();
127 }
128
130 calculate();
131 Real v = (*sabrInterpolation_)(strike, true);
132 return v*v*exerciseTime();
133 }
134
135}
136
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Shared handle to an observable.
Definition: handle.hpp:41
virtual void calculate() const
Definition: lazyobject.hpp:253
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
purely virtual base class for market observables
Definition: quote.hpp:37
SABR smile interpolation between discrete volatility points.
SabrInterpolatedSmileSection(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, bool isAlphaFixed=false, bool isBetaFixed=false, bool isNuFixed=false, bool isRhoFixed=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(), Real shift=0.0)
all market data are quotes
const ext::shared_ptr< EndCriteria > endCriteria_
ext::shared_ptr< SABRInterpolation > sabrInterpolation_
void createInterpolation() const
Creates the mutable SABRInterpolation.
std::vector< Rate > actualStrikes_
Only strikes corresponding to valid market data.
const ext::shared_ptr< OptimizationMethod > method_
global repository for run-time library settings
Definition: settings.hpp:37
market element returning a stored value
Definition: simplequote.hpp:33
interest rate volatility smile section
virtual Time exerciseTime() const
virtual Rate shift() const
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
Real rho
Definition: any.hpp:35
void swap(Array &v, Array &w) noexcept
Definition: array.hpp:903
STL namespace.
ext::shared_ptr< BlackVolTermStructure > v
Real beta
Definition: sabr.cpp:200
Real nu
Definition: sabr.cpp:200
Real alpha
Definition: sabr.cpp:200
Interpolated smile section class.
global repository for run-time library settings
simple quote class