QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
svismilesection.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/sviinterpolation.hpp>
21#include <ql/experimental/volatility/svismilesection.hpp>
22#include <utility>
23
24namespace QuantLib {
25
26 SviSmileSection::SviSmileSection(Time timeToExpiry, Rate forward, std::vector<Real> sviParams)
27 : SmileSection(timeToExpiry, DayCounter()), forward_(forward), params_(std::move(sviParams)) {
28 init();
29 }
30
32 Rate forward,
33 std::vector<Real> sviParams,
34 const DayCounter& dc)
35 : SmileSection(d, dc, Date()), forward_(forward), params_(std::move(sviParams)) {
36 init();
37 }
38
40 QL_REQUIRE(exerciseTime() > 0.0, "svi expects a strictly positive expiry time");
41 QL_REQUIRE(params_.size() == 5,
42 "svi expects 5 parameters (a,b,sigma,rho,m) but ("
43 << params_.size() << ") given");
45 exerciseTime());
46}
47
49
50 Real k = std::log(std::max(strike, 1E-6) / forward_);
51 Real totalVariance = detail::sviTotalVariance(params_[0], params_[1], params_[2],
52 params_[3], params_[4],k);
53 return std::sqrt(std::max(0.0, totalVariance / exerciseTime()));
54
55}
56} // namespace QuantLib
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
interest rate volatility smile section
virtual Time exerciseTime() const
SviSmileSection(Time timeToExpiry, Rate forward, std::vector< Real > sviParameters)
std::vector< Real > params_
Volatility volatilityImpl(Rate strike) const override
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
void checkSviParameters(const Real a, const Real b, const Real sigma, const Real rho, const Real m, const Time tte)
Real sviTotalVariance(const Real a, const Real b, const Real sigma, const Real rho, const Real m, const Real k)
Definition: any.hpp:35
STL namespace.