QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
smilesection.hpp
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) 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
30#include <ql/utilities/null.hpp>
31#include <ql/option.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,
43 const Date& referenceDate = Date(),
45 Rate shift = 0.0);
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_; }
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,
70 Real discount=1.0) const;
71 virtual Real digitalOptionPrice(Rate strike,
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:
93 };
94
95
96 // inline definitions
97
98 inline Real SmileSection::variance(Rate strike) const {
99 return varianceImpl(strike);
100 }
101
103 return volatilityImpl(strike);
104 }
105
106 inline const Date& SmileSection::referenceDate() const {
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
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Object that notifies its changes to a set of observers.
Definition: observable.hpp:62
Object that gets notified when a given observable changes.
Definition: observable.hpp:116
interest rate volatility smile section
virtual Real digitalOptionPrice(Rate strike, Option::Type type=Option::Call, Real discount=1.0, Real gap=1.0e-5) const
virtual Real varianceImpl(Rate strike) const
virtual const DayCounter & dayCounter() const
virtual Real minStrike() const =0
virtual const Date & referenceDate() const
void update() override
Real variance(Rate strike) const
virtual Time exerciseTime() const
Volatility volatility(Rate strike) const
~SmileSection() override=default
virtual Real vega(Rate strike, Real discount=1.0) const
virtual Volatility volatilityImpl(Rate strike) const =0
virtual VolatilityType volatilityType() const
virtual Real atmLevel() const =0
virtual Real density(Rate strike, Real discount=1.0, Real gap=1.0E-4) const
virtual void initializeExerciseTime() const
virtual const Date & exerciseDate() const
virtual Rate shift() const
virtual Real optionPrice(Rate strike, Option::Type type=Option::Call, Real discount=1.0) const
virtual Real maxStrike() const =0
VolatilityType volatilityType_
day counter class
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Date d
LinearInterpolation variance
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
null values
observer/observable pattern
Base option class.
ext::shared_ptr< BlackVolTermStructure > v
volatility types