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 <http://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
25namespace QuantLib {
26
27 SabrSmileSection::SabrSmileSection(Time timeToExpiry,
28 Rate forward,
29 const std::vector<Real>& sabrParams,
30 const Real shift,
31 VolatilityType volatilityType)
32 : SmileSection(timeToExpiry,DayCounter(),
33 volatilityType,shift),
34 forward_(forward), shift_(shift) {
35 initialise(sabrParameters: sabrParams);
36 }
37
38 SabrSmileSection::SabrSmileSection(const Date& d,
39 Rate forward,
40 const std::vector<Real>& sabrParams,
41 const DayCounter& dc,
42 const Real shift,
43 VolatilityType volatilityType)
44 : SmileSection(d, dc, Date(), volatilityType, shift),
45 forward_(forward), shift_(shift) {
46 initialise(sabrParameters: sabrParams);
47 }
48
49 SabrSmileSection::SabrSmileSection(const Date& d,
50 Rate forward,
51 const std::vector<Real>& sabrParams,
52 const Date& referenceDate,
53 const DayCounter& dc,
54 const Real shift,
55 VolatilityType volatilityType)
56 : SmileSection(d, dc, referenceDate, volatilityType, shift),
57 forward_(forward), shift_(shift) {
58 initialise(sabrParameters: sabrParams);
59 }
60
61 void SabrSmileSection::initialise(const std::vector<Real>& sabrParams) {
62
63 alpha_ = sabrParams[0];
64 beta_ = sabrParams[1];
65 nu_ = sabrParams[2];
66 rho_ = sabrParams[3];
67
68 QL_REQUIRE(forward_ + shift_ > 0.0,
69 "at the money forward rate + shift must be "
70 "positive: "
71 << io::rate(forward_) << " with shift "
72 << io::rate(shift_) << " not allowed");
73 validateSabrParameters(alpha: alpha_, beta: beta_, nu: nu_, rho: rho_);
74 }
75
76 Real SabrSmileSection::varianceImpl(Rate strike) const {
77 strike = std::max(a: 0.00001 - shift(),b: strike);
78 Volatility vol = unsafeShiftedSabrVolatility(
79 strike, forward: forward_, expiryTime: exerciseTime(), alpha: alpha_, beta: beta_, nu: nu_, rho: rho_, shift: shift_, volatilityType: volatilityType());
80 return vol * vol * exerciseTime();
81 }
82
83 Real SabrSmileSection::volatilityImpl(Rate strike) const {
84 strike = std::max(a: 0.00001 - shift(),b: strike);
85 return unsafeShiftedSabrVolatility(strike, forward: forward_, expiryTime: exerciseTime(),
86 alpha: alpha_, beta: beta_, nu: nu_, rho: rho_, shift: shift_, volatilityType: volatilityType());
87 }
88}
89

source code of quantlib/ql/termstructures/volatility/sabrsmilesection.cpp