QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
sabrsmilesection.cpp
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
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(sabrParams);
36 }
37
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 : SmileSection(d, dc, referenceDate, volatilityType, shift),
46 forward_(forward), shift_(shift) {
47 initialise(sabrParams);
48 }
49
50 void SabrSmileSection::initialise(const std::vector<Real>& sabrParams) {
51
52 alpha_ = sabrParams[0];
53 beta_ = sabrParams[1];
54 nu_ = sabrParams[2];
55 rho_ = sabrParams[3];
56
57 QL_REQUIRE(forward_ + shift_ > 0.0,
58 "at the money forward rate + shift must be "
59 "positive: "
60 << io::rate(forward_) << " with shift "
61 << io::rate(shift_) << " not allowed");
63 }
64
66 strike = std::max(0.00001 - shift(),strike);
69 return vol * vol * exerciseTime();
70 }
71
73 strike = std::max(0.00001 - shift(),strike);
76 }
77}
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
SabrSmileSection(Time timeToExpiry, Rate forward, const std::vector< Real > &sabrParameters, Real shift=0.0, VolatilityType volatilityType=VolatilityType::ShiftedLognormal)
Real varianceImpl(Rate strike) const override
void initialise(const std::vector< Real > &sabrParameters)
Volatility volatilityImpl(Rate strike) const override
interest rate volatility smile section
virtual Time exerciseTime() const
virtual VolatilityType volatilityType() const
virtual Rate shift() const
detail::percent_holder rate(Rate)
output rates and spreads as percentages
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
Definition: any.hpp:35
Real unsafeShiftedSabrVolatility(Rate strike, Rate forward, Time expiryTime, Real alpha, Real beta, Real nu, Real rho, Real shift, VolatilityType volatilityType)
Definition: sabr.cpp:74
void validateSabrParameters(Real alpha, Real beta, Real nu, Real rho)
Definition: sabr.cpp:145