Coverage Report

Created: 2026-01-25 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/experimental/volatility/blackvolsurface.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2002, 2003 Ferdinando Ametrano
5
 Copyright (C) 2003, 2004, 2005, 2006 StatPro Italia srl
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
 <https://www.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 blackvolsurface.hpp
22
    \brief Black volatility (smile) surface
23
*/
24
25
#ifndef quantlib_black_vol_surface_hpp
26
#define quantlib_black_vol_surface_hpp
27
28
#include <ql/experimental/volatility/blackatmvolcurve.hpp>
29
30
namespace QuantLib {
31
32
    class SmileSection;
33
34
    //! Black volatility (smile) surface
35
    /*! This abstract class defines the interface of concrete
36
        Black volatility (smile) surface which will
37
        be derived from this one.
38
39
        Volatilities are assumed to be expressed on an annual basis.
40
41
    */
42
    class BlackVolSurface : public BlackAtmVolCurve {
43
      public:
44
        /*! \name Constructors
45
            See the TermStructure documentation for issues regarding
46
            constructors.
47
        */
48
        //@{
49
        //! default constructor
50
        /*! \warning term structures initialized by means of this
51
                     constructor must manage their own reference date
52
                     by overriding the referenceDate() method.
53
        */
54
        BlackVolSurface(BusinessDayConvention bdc = Following,
55
                        const DayCounter& dc = DayCounter());
56
        //! initialize with a fixed reference date
57
        BlackVolSurface(const Date& referenceDate,
58
                        const Calendar& cal = Calendar(),
59
                        BusinessDayConvention bdc = Following,
60
                        const DayCounter& dc = DayCounter());
61
        //! calculate the reference date based on the global evaluation date
62
        BlackVolSurface(Natural settlementDays,
63
                        const Calendar&,
64
                        BusinessDayConvention bdc = Following,
65
                        const DayCounter& dc = DayCounter());
66
        //@}
67
        //! \name Black spot volatility
68
        //@{
69
        //! returns the smile for a given option tenor
70
        ext::shared_ptr<SmileSection> smileSection(const Period&,
71
                                                     bool extrapolate) const;
72
        //! returns the smile for a given option date
73
        ext::shared_ptr<SmileSection> smileSection(const Date&,
74
                                                     bool extrapolate) const;
75
        //! returns the smile for a given option time
76
        ext::shared_ptr<SmileSection> smileSection(Time,
77
                                                     bool extrapolate) const;
78
        //@}
79
        //! \name Visitability
80
        //@{
81
        void accept(AcyclicVisitor&) override;
82
        //@}
83
      protected:
84
        //! \name BlackAtmVolCurve interface
85
        //@{
86
        //! spot at-the-money variance calculation
87
        Real atmVarianceImpl(Time t) const override;
88
        //! spot at-the-money volatility calculation
89
        Volatility atmVolImpl(Time t) const override;
90
        //@}
91
        /*! \name Calculations
92
93
            This method must be implemented in derived classes to perform
94
            the actual volatility calculations. When it is called,
95
            time check has already been performed; therefore, it must
96
            assume that time-extrapolation is allowed.
97
        */
98
        //@{
99
        virtual ext::shared_ptr<SmileSection> smileSectionImpl(Time) const=0;
100
        //@}
101
    };
102
103
    // inline definitions
104
105
    inline ext::shared_ptr<SmileSection>
106
    BlackVolSurface::smileSection(const Period& p,
107
0
                                  bool extrapolate) const {
108
0
        return smileSection(optionDateFromTenor(p), extrapolate);
109
0
    }
110
111
    inline ext::shared_ptr<SmileSection>
112
    BlackVolSurface::smileSection(const Date& d,
113
0
                                  bool extrapolate) const {
114
0
        return smileSection(timeFromReference(d), extrapolate);
115
0
    }
116
117
    inline ext::shared_ptr<SmileSection>
118
    BlackVolSurface::smileSection(Time t,
119
0
                                  bool extrapolate) const {
120
0
        checkRange(t, extrapolate);
121
0
        return smileSectionImpl(t);
122
0
    }
123
124
}
125
126
#endif