/src/quantlib/ql/termstructures/volatility/sabrsmilesection.cpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2006 Mario Pucci |
5 | | Copyright (C) 2015 Peter Caspers |
6 | | |
7 | | This file is part of QuantLib, a free-software/open-source library |
8 | | for financial quantitative analysts and developers - http://quantlib.org/ |
9 | | |
10 | | QuantLib is free software: you can redistribute it and/or modify it |
11 | | under the terms of the QuantLib license. You should have received a |
12 | | copy of the license along with this program; if not, please email |
13 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
14 | | <https://www.quantlib.org/license.shtml>. |
15 | | |
16 | | This program is distributed in the hope that it will be useful, but WITHOUT |
17 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
18 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
19 | | */ |
20 | | |
21 | | #include <ql/termstructures/volatility/sabrsmilesection.hpp> |
22 | | #include <ql/termstructures/volatility/sabr.hpp> |
23 | | #include <ql/utilities/dataformatters.hpp> |
24 | | |
25 | | namespace QuantLib { |
26 | | |
27 | | SabrSmileSection::SabrSmileSection(Time timeToExpiry, |
28 | | Rate forward, |
29 | | const std::vector<Real>& sabrParams, |
30 | | const Real shift, |
31 | | VolatilityType volatilityType) |
32 | 0 | : SmileSection(timeToExpiry,DayCounter(), |
33 | 0 | volatilityType,shift), |
34 | 0 | forward_(forward), shift_(shift) { |
35 | 0 | initialise(sabrParams); |
36 | 0 | } Unexecuted instantiation: QuantLib::SabrSmileSection::SabrSmileSection(double, double, std::__1::vector<double, std::__1::allocator<double> > const&, double, QuantLib::VolatilityType) Unexecuted instantiation: QuantLib::SabrSmileSection::SabrSmileSection(double, double, std::__1::vector<double, std::__1::allocator<double> > const&, double, QuantLib::VolatilityType) |
37 | | |
38 | | SabrSmileSection::SabrSmileSection(const Date& d, |
39 | | Rate forward, |
40 | | const std::vector<Real>& sabrParams, |
41 | | const Date& referenceDate, |
42 | | const DayCounter& dc, |
43 | | const Real shift, |
44 | | VolatilityType volatilityType) |
45 | 0 | : SmileSection(d, dc, referenceDate, volatilityType, shift), |
46 | 0 | forward_(forward), shift_(shift) { |
47 | 0 | initialise(sabrParams); |
48 | 0 | } Unexecuted instantiation: QuantLib::SabrSmileSection::SabrSmileSection(QuantLib::Date const&, double, std::__1::vector<double, std::__1::allocator<double> > const&, QuantLib::Date const&, QuantLib::DayCounter const&, double, QuantLib::VolatilityType) Unexecuted instantiation: QuantLib::SabrSmileSection::SabrSmileSection(QuantLib::Date const&, double, std::__1::vector<double, std::__1::allocator<double> > const&, QuantLib::Date const&, QuantLib::DayCounter const&, double, QuantLib::VolatilityType) |
49 | | |
50 | 0 | void SabrSmileSection::initialise(const std::vector<Real>& sabrParams) { |
51 | |
|
52 | 0 | alpha_ = sabrParams[0]; |
53 | 0 | beta_ = sabrParams[1]; |
54 | 0 | nu_ = sabrParams[2]; |
55 | 0 | rho_ = sabrParams[3]; |
56 | |
|
57 | 0 | QL_REQUIRE(forward_ + shift_ > 0.0, |
58 | 0 | "at the money forward rate + shift must be " |
59 | 0 | "positive: " |
60 | 0 | << io::rate(forward_) << " with shift " |
61 | 0 | << io::rate(shift_) << " not allowed"); |
62 | 0 | validateSabrParameters(alpha_, beta_, nu_, rho_); |
63 | 0 | } |
64 | | |
65 | 0 | Real SabrSmileSection::varianceImpl(Rate strike) const { |
66 | 0 | strike = std::max(0.00001 - shift(),strike); |
67 | 0 | Volatility vol = unsafeShiftedSabrVolatility( |
68 | 0 | strike, forward_, exerciseTime(), alpha_, beta_, nu_, rho_, shift_, volatilityType()); |
69 | 0 | return vol * vol * exerciseTime(); |
70 | 0 | } |
71 | | |
72 | 0 | Real SabrSmileSection::volatilityImpl(Rate strike) const { |
73 | 0 | strike = std::max(0.00001 - shift(),strike); |
74 | 0 | return unsafeShiftedSabrVolatility(strike, forward_, exerciseTime(), |
75 | 0 | alpha_, beta_, nu_, rho_, shift_, volatilityType()); |
76 | 0 | } |
77 | | } |