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) 2013, 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/*! \file smilesection.hpp
22 \brief Smile section base class
23*/
24
25#ifndef quantlib_smile_section_hpp
26#define quantlib_smile_section_hpp
27
28#include <ql/patterns/observable.hpp>
29#include <ql/time/daycounter.hpp>
30#include <ql/utilities/null.hpp>
31#include <ql/option.hpp>
32#include <ql/termstructures/volatility/volatilitytype.hpp>
33
34namespace QuantLib {
35
36 //! interest rate volatility smile section
37 /*! This abstract class provides volatility smile section interface */
38 class SmileSection : public virtual Observable,
39 public virtual Observer {
40 public:
41 SmileSection(const Date& d,
42 DayCounter dc = DayCounter(),
43 const Date& referenceDate = Date(),
44 VolatilityType type = ShiftedLognormal,
45 Rate shift = 0.0);
46 SmileSection(Time exerciseTime,
47 DayCounter dc = DayCounter(),
48 VolatilityType type = ShiftedLognormal,
49 Rate shift = 0.0);
50 SmileSection() = default;
51
52 ~SmileSection() override = default;
53
54 void update() override;
55 virtual Real minStrike() const = 0;
56 virtual Real maxStrike() const = 0;
57 Real variance(Rate strike) const;
58 Volatility volatility(Rate strike) const;
59 virtual Real atmLevel() const = 0;
60 virtual const Date& exerciseDate() const { return exerciseDate_; }
61 virtual VolatilityType volatilityType() const {
62 return volatilityType_;
63 }
64 virtual Rate shift() const { return shift_; }
65 virtual const Date& referenceDate() const;
66 virtual Time exerciseTime() const { return exerciseTime_; }
67 virtual const DayCounter& dayCounter() const { return dc_; }
68 virtual Real optionPrice(Rate strike,
69 Option::Type type = Option::Call,
70 Real discount=1.0) const;
71 virtual Real digitalOptionPrice(Rate strike,
72 Option::Type type = Option::Call,
73 Real discount=1.0,
74 Real gap=1.0e-5) const;
75 virtual Real vega(Rate strike,
76 Real discount=1.0) const;
77 virtual Real density(Rate strike,
78 Real discount=1.0,
79 Real gap=1.0E-4) const;
80 Volatility volatility(Rate strike, VolatilityType type, Real shift=0.0) const;
81 protected:
82 virtual void initializeExerciseTime() const;
83 virtual Real varianceImpl(Rate strike) const;
84 virtual Volatility volatilityImpl(Rate strike) const = 0;
85 private:
86 bool isFloating_;
87 mutable Date referenceDate_;
88 Date exerciseDate_;
89 DayCounter dc_;
90 mutable Time exerciseTime_;
91 VolatilityType volatilityType_;
92 Rate shift_;
93 };
94
95
96 // inline definitions
97
98 inline Real SmileSection::variance(Rate strike) const {
99 return varianceImpl(strike);
100 }
101
102 inline Volatility SmileSection::volatility(Rate strike) const {
103 return volatilityImpl(strike);
104 }
105
106 inline const Date& SmileSection::referenceDate() const {
107 QL_REQUIRE(referenceDate_!=Date(),
108 "referenceDate not available for this instance");
109 return referenceDate_;
110 }
111
112 inline Real SmileSection::varianceImpl(Rate strike) const {
113 Volatility v = volatilityImpl(strike);
114 return v*v*exerciseTime();
115 }
116
117}
118
119#endif
120

source code of quantlib/ql/termstructures/volatility/smilesection.hpp