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 
25 namespace QuantLib {
26 
SabrSmileSection(Time timeToExpiry,Rate forward,const std::vector<Real> & sabrParams,const Real shift)27     SabrSmileSection::SabrSmileSection(Time timeToExpiry,
28                                        Rate forward,
29                                        const std::vector<Real>& sabrParams,
30                                        const Real shift)
31         : SmileSection(timeToExpiry,DayCounter(),
32                        ShiftedLognormal,shift),
33           forward_(forward), shift_(shift) {
34         initialise(sabrParams);
35     }
36 
SabrSmileSection(const Date & d,Rate forward,const std::vector<Real> & sabrParams,const DayCounter & dc,const Real shift)37     SabrSmileSection::SabrSmileSection(const Date& d,
38                                        Rate forward,
39                                        const std::vector<Real>& sabrParams,
40                                        const DayCounter& dc,
41                                        const Real shift)
42         : SmileSection(d, dc,Date(),ShiftedLognormal,shift),
43           forward_(forward), shift_(shift) {
44         initialise(sabrParams);
45      }
46 
initialise(const std::vector<Real> & sabrParams)47     void SabrSmileSection::initialise(const std::vector<Real>& sabrParams) {
48 
49         alpha_ = sabrParams[0];
50         beta_ = sabrParams[1];
51         nu_ = sabrParams[2];
52         rho_ = sabrParams[3];
53 
54         QL_REQUIRE(forward_ + shift_ > 0.0,
55                    "at the money forward rate + shift must be "
56                    "positive: "
57                        << io::rate(forward_) << " with shift "
58                        << io::rate(shift_) << " not allowed");
59         validateSabrParameters(alpha_, beta_, nu_, rho_);
60     }
61 
varianceImpl(Rate strike) const62      Real SabrSmileSection::varianceImpl(Rate strike) const {
63         strike = std::max(0.00001 - shift(),strike);
64         Volatility vol = unsafeShiftedSabrVolatility(
65             strike, forward_, exerciseTime(), alpha_, beta_, nu_, rho_, shift_);
66         return vol * vol * exerciseTime();
67      }
68 
volatilityImpl(Rate strike) const69      Real SabrSmileSection::volatilityImpl(Rate strike) const {
70         strike = std::max(0.00001 - shift(),strike);
71         return unsafeShiftedSabrVolatility(strike, forward_, exerciseTime(),
72                                            alpha_, beta_, nu_, rho_, shift_);
73      }
74 }
75