QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
noarbsabrinterpolatedsmilesection.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/noarbsabrinterpolatedsmilesection.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 alpha,
35 Real beta,
36 Real nu,
37 Real rho,
38 bool isAlphaFixed,
39 bool isBetaFixed,
40 bool isNuFixed,
41 bool isRhoFixed,
42 bool vegaWeighted,
43 ext::shared_ptr<EndCriteria> endCriteria,
44 ext::shared_ptr<OptimizationMethod> method,
45 const DayCounter& dc)
46 : SmileSection(optionDate, dc), forward_(std::move(forward)),
47 atmVolatility_(std::move(atmVolatility)), volHandles_(volHandles), strikes_(strikes),
48 actualStrikes_(strikes), hasFloatingStrikes_(hasFloatingStrikes), vols_(volHandles.size()),
49 alpha_(alpha), beta_(beta), nu_(nu), rho_(rho), isAlphaFixed_(isAlphaFixed),
50 isBetaFixed_(isBetaFixed), isNuFixed_(isNuFixed), isRhoFixed_(isRhoFixed),
51 vegaWeighted_(vegaWeighted), endCriteria_(std::move(endCriteria)),
52 method_(std::move(method)) {
53
56 for (auto& volHandle : volHandles_)
57 LazyObject::registerWith(volHandle);
58 }
59
61 const Date& optionDate,
62 const Rate& forward,
63 const std::vector<Rate>& strikes,
64 bool hasFloatingStrikes,
65 const Volatility& atmVolatility,
66 const std::vector<Volatility>& volHandles,
67 Real alpha,
68 Real beta,
69 Real nu,
70 Real rho,
71 bool isAlphaFixed,
72 bool isBetaFixed,
73 bool isNuFixed,
74 bool isRhoFixed,
75 bool vegaWeighted,
76 ext::shared_ptr<EndCriteria> endCriteria,
77 ext::shared_ptr<OptimizationMethod> method,
78 const DayCounter& dc)
79 : SmileSection(optionDate, dc),
80 forward_(Handle<Quote>(ext::shared_ptr<Quote>(new SimpleQuote(forward)))),
81 atmVolatility_(Handle<Quote>(ext::shared_ptr<Quote>(new SimpleQuote(atmVolatility)))),
82 volHandles_(volHandles.size()), strikes_(strikes), actualStrikes_(strikes),
83 hasFloatingStrikes_(hasFloatingStrikes), vols_(volHandles.size()), alpha_(alpha), beta_(beta),
84 nu_(nu), rho_(rho), isAlphaFixed_(isAlphaFixed), isBetaFixed_(isBetaFixed),
85 isNuFixed_(isNuFixed), isRhoFixed_(isRhoFixed), vegaWeighted_(vegaWeighted),
86 endCriteria_(std::move(endCriteria)), method_(std::move(method)) {
87
88 for (Size i = 0; i < volHandles_.size(); ++i)
89 volHandles_[i] = Handle<Quote>(ext::shared_ptr<Quote>(new SimpleQuote(volHandles[i])));
90 }
91
93 ext::shared_ptr<NoArbSabrInterpolation> tmp(new NoArbSabrInterpolation(
94 actualStrikes_.begin(), actualStrikes_.end(), vols_.begin(),
100 }
101
103 forwardValue_ = forward_->value();
104 vols_.clear();
105 actualStrikes_.clear();
106 // we populate the volatilities, skipping the invalid ones
107 for (Size i=0; i<volHandles_.size(); ++i) {
108 if (volHandles_[i]->isValid()) {
110 actualStrikes_.push_back(forwardValue_ + strikes_[i]);
111 vols_.push_back(atmVolatility_->value() + volHandles_[i]->value());
112 } else {
113 actualStrikes_.push_back(strikes_[i]);
114 vols_.push_back(volHandles_[i]->value());
115 }
116 }
117 }
118 // we are recreating the sabrinterpolation object unconditionnaly to
119 // avoid iterator invalidation
121 noArbSabrInterpolation_->update();
122 }
123
125 calculate();
126 Real v = (*noArbSabrInterpolation_)(strike, true);
127 return v*v*exerciseTime();
128 }
129
130}
131
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
void createInterpolation() const
Creates the mutable SABRInterpolation.
std::vector< Rate > actualStrikes_
Only strikes corresponding to valid market data.
const ext::shared_ptr< OptimizationMethod > method_
NoArbSabrInterpolatedSmileSection(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())
all market data are quotes
ext::shared_ptr< NoArbSabrInterpolation > noArbSabrInterpolation_
no arbitrage sabr smile interpolation between discrete volatility points.
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
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.