Coverage Report

Created: 2025-12-08 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/experimental/volatility/sabrvolsurface.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2007 Ferdinando Ametrano
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
 <https://www.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
20
/*! \file sabrvolsurface.hpp
21
    \brief SABR volatility (smile) surface
22
*/
23
24
#ifndef quantlib_sabr_vol_surface_hpp
25
#define quantlib_sabr_vol_surface_hpp
26
27
#include <ql/experimental/volatility/interestratevolsurface.hpp>
28
#include <ql/experimental/volatility/blackatmvolcurve.hpp>
29
#include <ql/quote.hpp>
30
#include <ql/termstructures/volatility/sabrinterpolatedsmilesection.hpp>
31
#include <array>
32
33
namespace QuantLib {
34
35
36
    //! SABR volatility (smile) surface
37
    /*! blah blah
38
    */
39
    class SabrVolSurface : public InterestRateVolSurface {
40
      public:
41
        SabrVolSurface(const ext::shared_ptr<InterestRateIndex>&,
42
                       Handle<BlackAtmVolCurve>,
43
                       const std::vector<Period>& optionTenors,
44
                       std::vector<Spread> atmRateSpreads,
45
                       std::vector<std::vector<Handle<Quote> > > volSpreads);
46
        //@}
47
        // All virtual methods of base classes must be forwarded
48
        //! \name TermStructure interface
49
        //@{
50
        DayCounter dayCounter() const override;
51
        Date maxDate() const override;
52
        Time maxTime() const override;
53
        const Date& referenceDate() const override;
54
        Calendar calendar() const override;
55
        Natural settlementDays() const override;
56
        //@}
57
        //! \name VolatilityTermStructure interface
58
        //@{
59
        Real minStrike() const override;
60
        Real maxStrike() const override;
61
        //@}
62
        const Handle<BlackAtmVolCurve>& atmCurve() const;
63
        //! \name Visitability
64
        //@{
65
        void accept(AcyclicVisitor&) override;
66
        //@}
67
        std::vector<Volatility> volatilitySpreads(const Period&) const;
68
        std::vector<Volatility> volatilitySpreads(const Date&) const;
69
      protected:
70
        std::array<Real, 4> sabrGuesses(const Date&) const;
71
      public:
72
        //@}
73
        //! \name BlackVolSurface interface
74
        //@{
75
        ext::shared_ptr<SmileSection> smileSectionImpl(Time) const override;
76
        //@}
77
      protected:
78
        //@}
79
        //! \name LazyObject interface
80
        //@{
81
        void performCalculations () const;
82
        void update() override;
83
        //@}
84
      private:
85
        void registerWithMarketData();
86
        void checkInputs() const;
87
        void updateSabrGuesses(const Date& d, std::array<Real, 4> newGuesses) const;
88
        Handle<BlackAtmVolCurve> atmCurve_;
89
        std::vector<Period> optionTenors_;
90
        std::vector<Time> optionTimes_;
91
        std::vector<Date> optionDates_;
92
        std::vector<Spread> atmRateSpreads_;
93
        std::vector<std::vector<Handle<Quote> > > volSpreads_;
94
        //
95
        bool isAlphaFixed_;
96
        bool isBetaFixed_;
97
        bool isNuFixed_;
98
        bool isRhoFixed_;
99
        bool vegaWeighted_;
100
        //
101
        mutable std::vector<std::array<Real,4>> sabrGuesses_;
102
    };
103
104
    // inline
105
106
0
    inline DayCounter SabrVolSurface::dayCounter() const {
107
0
        return atmCurve_->dayCounter();
108
0
    }
109
110
0
    inline Date SabrVolSurface::maxDate() const {
111
0
        return atmCurve_->maxDate();
112
0
    }
113
114
0
    inline Time SabrVolSurface::maxTime() const {
115
0
        return atmCurve_->maxTime();
116
0
    }
117
118
0
    inline const Date& SabrVolSurface::referenceDate() const {
119
0
        return atmCurve_->referenceDate();
120
0
    }
121
122
0
    inline Calendar SabrVolSurface::calendar() const {
123
0
        return atmCurve_->calendar();
124
0
    }
125
126
0
    inline Natural SabrVolSurface::settlementDays() const {
127
0
        return atmCurve_->settlementDays();
128
0
    }
129
130
0
    inline Real SabrVolSurface::minStrike() const {
131
0
        return QL_MIN_REAL;
132
0
    }
133
134
0
    inline Real SabrVolSurface::maxStrike() const {
135
0
        return QL_MAX_REAL;
136
0
    }
137
138
0
    inline const Handle<BlackAtmVolCurve>& SabrVolSurface::atmCurve() const {
139
0
        return atmCurve_;
140
0
    }
141
142
    inline std::vector<Volatility>
143
0
    SabrVolSurface::volatilitySpreads(const Period& p) const {
144
0
        return volatilitySpreads(optionDateFromTenor(p));
145
0
    }
146
}
147
148
#endif