/src/quantlib/ql/experimental/volatility/svismilesection.cpp
Line | Count | Source |
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 | | <https://www.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 | | |
24 | | namespace QuantLib { |
25 | | |
26 | | SviSmileSection::SviSmileSection(Time timeToExpiry, Rate forward, std::vector<Real> sviParams) |
27 | 0 | : SmileSection(timeToExpiry, DayCounter()), forward_(forward), params_(std::move(sviParams)) { |
28 | 0 | init(); |
29 | 0 | } Unexecuted instantiation: QuantLib::SviSmileSection::SviSmileSection(double, double, std::__1::vector<double, std::__1::allocator<double> >) Unexecuted instantiation: QuantLib::SviSmileSection::SviSmileSection(double, double, std::__1::vector<double, std::__1::allocator<double> >) |
30 | | |
31 | | SviSmileSection::SviSmileSection(const Date& d, |
32 | | Rate forward, |
33 | | std::vector<Real> sviParams, |
34 | | const DayCounter& dc) |
35 | 0 | : SmileSection(d, dc, Date()), forward_(forward), params_(std::move(sviParams)) { |
36 | 0 | init(); |
37 | 0 | } Unexecuted instantiation: QuantLib::SviSmileSection::SviSmileSection(QuantLib::Date const&, double, std::__1::vector<double, std::__1::allocator<double> >, QuantLib::DayCounter const&) Unexecuted instantiation: QuantLib::SviSmileSection::SviSmileSection(QuantLib::Date const&, double, std::__1::vector<double, std::__1::allocator<double> >, QuantLib::DayCounter const&) |
38 | | |
39 | 0 | void SviSmileSection::init() { |
40 | 0 | QL_REQUIRE(exerciseTime() > 0.0, "svi expects a strictly positive expiry time"); |
41 | 0 | QL_REQUIRE(params_.size() == 5, |
42 | 0 | "svi expects 5 parameters (a,b,sigma,rho,m) but (" |
43 | 0 | << params_.size() << ") given"); |
44 | 0 | detail::checkSviParameters(params_[0], params_[1], params_[2], params_[3], params_[4], |
45 | 0 | exerciseTime()); |
46 | 0 | } |
47 | | |
48 | 0 | Volatility SviSmileSection::volatilityImpl(Rate strike) const { |
49 | |
|
50 | 0 | Real k = std::log(std::max(strike, 1E-6) / forward_); |
51 | 0 | Real totalVariance = detail::sviTotalVariance(params_[0], params_[1], params_[2], |
52 | 0 | params_[3], params_[4],k); |
53 | 0 | return std::sqrt(std::max(0.0, totalVariance / exerciseTime())); |
54 | |
|
55 | 0 | } |
56 | | } // namespace QuantLib |