QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
noarbsabrsmilesection.cpp
Go to the documentation of this file.
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 <http://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
23#include <utility>
24
25
26namespace QuantLib {
27
29 Rate forward,
30 std::vector<Real> sabrParams,
31 Real shift,
32 VolatilityType volatilityType)
33 : SmileSection(timeToExpiry, DayCounter(), volatilityType), forward_(forward), params_(std::move(sabrParams)),
34 shift_(shift) {
35 init();
36 }
37
39 const Date& d, Rate forward, std::vector<Real> sabrParams, const DayCounter& dc, Real shift, VolatilityType volatilityType)
40 : SmileSection(d, dc, Date(), volatilityType), forward_(forward), params_(std::move(sabrParams)),
41 shift_(shift) {
42 init();
43 }
44
46 QL_REQUIRE(params_.size() >= 4,
47 "sabr expects 4 parameters (alpha,beta,nu,rho) but ("
48 << params_.size() << ") given");
49 QL_REQUIRE(forward_ > 0.0, "forward (" << forward_ << ") must be positive");
51 shift_ == 0.0,
52 "shift (" << shift_
53 << ") must be zero, other shifts are not implemented yet");
54 model_ =
55 ext::make_shared<NoArbSabrModel>(exerciseTime(), forward_, params_[0],
56 params_[1], params_[2], params_[3]);
57}
58
60 Real discount) const {
61 Real call = model_->optionPrice(strike);
62 return discount *
63 (type == Option::Call ? call : call - (forward_ - strike));
64}
65
67 Real discount, Real) const {
68 Real call = model_->digitalOptionPrice(strike);
69 return discount * (type == Option::Call ? call : 1.0 - call);
70}
71
73 return discount * model_->density(strike);
74}
75
77
78 Real impliedVol = 0.0;
79 try {
80 Option::Type type;
81 if (strike >= forward_)
82 type = Option::Call;
83 else
84 type = Option::Put;
85 impliedVol =
87 optionPrice(strike, type, 1.0), 1.0) /
88 std::sqrt(exerciseTime());
89 } catch (...) {
90 }
91 if (impliedVol == 0.0)
92 // fall back on Hagan 2002 expansion
93 impliedVol =
96
97 return impliedVol;
98}
99} // namespace QuantLib
Black formula.
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Real density(Rate strike, Real discount=1.0, Real gap=1.0E-4) const override
ext::shared_ptr< NoArbSabrModel > model_
NoArbSabrSmileSection(Time timeToExpiry, Rate forward, std::vector< Real > sabrParameters, Real shift=0.0, VolatilityType volatilityType=VolatilityType::ShiftedLognormal)
Real digitalOptionPrice(Rate strike, Option::Type type=Option::Call, Real discount=1.0, Real gap=1.0e-5) const override
Real optionPrice(Rate strike, Option::Type type=Option::Call, Real discount=1.0) const override
Volatility volatilityImpl(Rate strike) const override
interest rate volatility smile section
virtual Time exerciseTime() const
virtual VolatilityType volatilityType() const
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Date d
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
Real unsafeSabrVolatility(Rate strike, Rate forward, Time expiryTime, Real alpha, Real beta, Real nu, Real rho, VolatilityType volatilityType)
Definition: sabr.cpp:130
Real blackFormulaImpliedStdDev(Option::Type optionType, Real strike, Real forward, Real blackPrice, Real discount, Real displacement, Real guess, Real accuracy, Natural maxIterations)
STL namespace.
no arbitrage sabr smile section
SABR functions.