QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
sviinterpolatedsmilesection.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2014 Peter Caspers
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
20#include <ql/experimental/volatility/sviinterpolatedsmilesection.hpp>
21#include <ql/quotes/simplequote.hpp>
22#include <ql/settings.hpp>
23#include <utility>
24
25namespace QuantLib {
26
28 const Date& optionDate,
29 Handle<Quote> forward,
30 const std::vector<Rate>& strikes,
31 bool hasFloatingStrikes,
32 Handle<Quote> atmVolatility,
33 const std::vector<Handle<Quote> >& volHandles,
34 Real a,
35 Real b,
36 Real sigma,
37 Real rho,
38 Real m,
39 bool isAFixed,
40 bool isBFixed,
41 bool isSigmaFixed,
42 bool isRhoFixed,
43 bool isMFixed,
44 bool vegaWeighted,
45 ext::shared_ptr<EndCriteria> endCriteria,
46 ext::shared_ptr<OptimizationMethod> method,
47 const DayCounter& dc)
48 : SmileSection(optionDate, dc), forward_(std::move(forward)),
49 atmVolatility_(std::move(atmVolatility)), volHandles_(volHandles), strikes_(strikes),
50 actualStrikes_(strikes), hasFloatingStrikes_(hasFloatingStrikes), vols_(volHandles.size()),
51 a_(a), b_(b), sigma_(sigma), rho_(rho), m_(m), isAFixed_(isAFixed), isBFixed_(isBFixed),
52 isSigmaFixed_(isSigmaFixed), isRhoFixed_(isRhoFixed), isMFixed_(isMFixed),
53 vegaWeighted_(vegaWeighted), endCriteria_(std::move(endCriteria)),
54 method_(std::move(method)) {
55
58 for (auto& volHandle : volHandles_)
59 LazyObject::registerWith(volHandle);
60 }
61
63 const Date& optionDate,
64 const Rate& forward,
65 const std::vector<Rate>& strikes,
66 bool hasFloatingStrikes,
67 const Volatility& atmVolatility,
68 const std::vector<Volatility>& volHandles,
69 Real a,
70 Real b,
71 Real sigma,
72 Real rho,
73 Real m,
74 bool isAFixed,
75 bool isBFixed,
76 bool isSigmaFixed,
77 bool isRhoFixed,
78 bool isMFixed,
79 bool vegaWeighted,
80 ext::shared_ptr<EndCriteria> endCriteria,
81 ext::shared_ptr<OptimizationMethod> method,
82 const DayCounter& dc)
83 : SmileSection(optionDate, dc),
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()), a_(a), b_(b),
88 sigma_(sigma), rho_(rho), m_(m), isAFixed_(isAFixed), isBFixed_(isBFixed),
89 isSigmaFixed_(isSigmaFixed), isRhoFixed_(isRhoFixed), isMFixed_(isMFixed),
90 vegaWeighted_(vegaWeighted), endCriteria_(std::move(endCriteria)),
91 method_(std::move(method)) {
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<SviInterpolation> tmp(new SviInterpolation(
99 actualStrikes_.begin(), actualStrikes_.end(), vols_.begin(),
104}
105
107 forwardValue_ = forward_->value();
108 vols_.clear();
109 actualStrikes_.clear();
110 // we populate the volatilities, skipping the invalid ones
111 for (Size i = 0; i < volHandles_.size(); ++i) {
112 if (volHandles_[i]->isValid()) {
114 actualStrikes_.push_back(forwardValue_ + strikes_[i]);
115 vols_.push_back(atmVolatility_->value() +
116 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 sviInterpolation_->update();
127}
128
130 calculate();
131 Real v = (*sviInterpolation_)(strike, true);
132 return v * v * exerciseTime();
133}
134}
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
market element returning a stored value
Definition: simplequote.hpp:33
interest rate volatility smile section
virtual Time exerciseTime() const
ext::shared_ptr< SviInterpolation > sviInterpolation_
const ext::shared_ptr< EndCriteria > endCriteria_
SviInterpolatedSmileSection(const Date &optionDate, Handle< Quote > forward, const std::vector< Rate > &strikes, bool hasFloatingStrikes, Handle< Quote > atmVolatility, const std::vector< Handle< Quote > > &volHandles, Real a, Real b, Real sigma, Real rho, Real m, bool aIsFixed, bool bIsFixed, bool sigmaIsFixed, bool rhoIsFixed, bool mIsFixed, 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
void createInterpolation() const
Creates the mutable SviInterpolation.
std::vector< Rate > actualStrikes_
Only strikes corresponding to valid market data.
const ext::shared_ptr< OptimizationMethod > method_
Svi smile interpolation between discrete volatility points.
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
Definition: any.hpp:35
void swap(Array &v, Array &w) noexcept
Definition: array.hpp:903
STL namespace.