Coverage Report

Created: 2026-06-23 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/termstructures/volatility/sabrinterpolatedsmilesection.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2007 Cristina Duminuco
5
 Copyright (C) 2006 François du Vignaud
6
 Copyright (C) 2015 Peter Caspers
7
8
 This file is part of QuantLib, a free-software/open-source library
9
 for financial quantitative analysts and developers - http://quantlib.org/
10
11
 QuantLib is free software: you can redistribute it and/or modify it
12
 under the terms of the QuantLib license.  You should have received a
13
 copy of the license along with this program; if not, please email
14
 <quantlib-dev@lists.sf.net>. The license is also available online at
15
 <https://www.quantlib.org/license.shtml>.
16
17
 This program is distributed in the hope that it will be useful, but WITHOUT
18
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19
 FOR A PARTICULAR PURPOSE.  See the license for more details.
20
*/
21
22
/*! \file sabrinterpolatedsmilesection.hpp
23
    \brief Interpolated smile section class
24
*/
25
26
#ifndef quantlib_sabr_interpolated_smile_section_hpp
27
#define quantlib_sabr_interpolated_smile_section_hpp
28
29
#include <ql/handle.hpp>
30
#include <ql/patterns/lazyobject.hpp>
31
#include <ql/termstructures/volatility/smilesection.hpp>
32
#include <ql/math/interpolations/sabrinterpolation.hpp>
33
#include <ql/time/daycounters/actual365fixed.hpp>
34
35
namespace QuantLib {
36
37
    class Quote;
38
    class SabrInterpolatedSmileSection : public SmileSection,
39
                                         public LazyObject {
40
      public:
41
        //! \name Constructors
42
        //@{
43
        //! all market data are quotes
44
        SabrInterpolatedSmileSection(
45
            const Date& optionDate,
46
            Handle<Quote> forward,
47
            const std::vector<Rate>& strikes,
48
            bool hasFloatingStrikes,
49
            Handle<Quote> atmVolatility,
50
            const std::vector<Handle<Quote> >& volHandles,
51
            Real alpha,
52
            Real beta,
53
            Real nu,
54
            Real rho,
55
            bool isAlphaFixed = false,
56
            bool isBetaFixed = false,
57
            bool isNuFixed = false,
58
            bool isRhoFixed = false,
59
            bool vegaWeighted = true,
60
            ext::shared_ptr<EndCriteria> endCriteria = ext::shared_ptr<EndCriteria>(),
61
            ext::shared_ptr<OptimizationMethod> method = ext::shared_ptr<OptimizationMethod>(),
62
            const DayCounter& dc = Actual365Fixed(),
63
            Real shift = 0.0);
64
        //! no quotes
65
        SabrInterpolatedSmileSection(
66
            const Date& optionDate,
67
            const Rate& forward,
68
            const std::vector<Rate>& strikes,
69
            bool hasFloatingStrikes,
70
            const Volatility& atmVolatility,
71
            const std::vector<Volatility>& vols,
72
            Real alpha,
73
            Real beta,
74
            Real nu,
75
            Real rho,
76
            bool isAlphaFixed = false,
77
            bool isBetaFixed = false,
78
            bool isNuFixed = false,
79
            bool isRhoFixed = false,
80
            bool vegaWeighted = true,
81
            ext::shared_ptr<EndCriteria> endCriteria = ext::shared_ptr<EndCriteria>(),
82
            ext::shared_ptr<OptimizationMethod> method = ext::shared_ptr<OptimizationMethod>(),
83
            const DayCounter& dc = Actual365Fixed(),
84
            Real shift = 0.0);
85
        //@}
86
        //! \name LazyObject interface
87
        //@{
88
        void performCalculations() const override;
89
        void update() override;
90
        //@}
91
        //! \name SmileSection interface
92
        //@{
93
        Real minStrike() const override;
94
        Real maxStrike() const override;
95
        Real atmLevel() const override;
96
        //@}
97
        Real varianceImpl(Rate strike) const override;
98
        Volatility volatilityImpl(Rate strike) const override;
99
        //! \name Inspectors
100
        //@{
101
        Real alpha() const;
102
        Real beta() const;
103
        Real nu() const;
104
        Real rho() const;
105
        Real rmsError() const;
106
        Real maxError() const;
107
        EndCriteria::Type endCriteria() const;
108
        //@}
109
110
      protected:
111
112
        //! Creates the mutable SABRInterpolation
113
        void createInterpolation() const;
114
        mutable ext::shared_ptr<SABRInterpolation> sabrInterpolation_;
115
116
        //! Market data
117
        const Handle<Quote> forward_;
118
        const Handle<Quote> atmVolatility_;
119
        std::vector<Handle<Quote> > volHandles_;
120
        mutable std::vector<Rate> strikes_;
121
        //! Only strikes corresponding to valid market data
122
        mutable std::vector<Rate> actualStrikes_;
123
        bool hasFloatingStrikes_;
124
125
        mutable Real forwardValue_;
126
        mutable std::vector<Volatility> vols_;
127
        //! Sabr parameters
128
        Real alpha_, beta_, nu_, rho_;
129
        //! Sabr interpolation settings
130
        bool isAlphaFixed_, isBetaFixed_, isNuFixed_, isRhoFixed_;
131
        bool vegaWeighted_;
132
        const ext::shared_ptr<EndCriteria> endCriteria_;
133
        const ext::shared_ptr<OptimizationMethod> method_;
134
135
        mutable Date evaluationDate_;
136
    };
137
138
0
    inline void SabrInterpolatedSmileSection::update() {
139
0
        LazyObject::update();
140
0
        SmileSection::update();
141
0
    }
142
143
0
    inline Real SabrInterpolatedSmileSection::volatilityImpl(Rate strike) const {
144
0
        calculate();
145
0
        return (*sabrInterpolation_)(strike, true);
146
0
    }
147
148
0
    inline Real SabrInterpolatedSmileSection::alpha() const {
149
0
        calculate();
150
0
        return sabrInterpolation_->alpha();
151
0
    }
152
153
0
    inline Real SabrInterpolatedSmileSection::beta() const {
154
0
        calculate();
155
0
        return sabrInterpolation_->beta();
156
0
    }
157
158
0
    inline Real SabrInterpolatedSmileSection::nu() const {
159
0
        calculate();
160
0
        return sabrInterpolation_->nu();
161
0
    }
162
163
0
    inline Real SabrInterpolatedSmileSection::rho() const {
164
0
        calculate();
165
0
        return sabrInterpolation_->rho();
166
0
    }
167
168
0
    inline Real SabrInterpolatedSmileSection::rmsError() const {
169
0
        calculate();
170
0
        return sabrInterpolation_->rmsError();
171
0
    }
172
173
0
    inline Real SabrInterpolatedSmileSection::maxError() const {
174
0
        calculate();
175
0
        return sabrInterpolation_->maxError();
176
0
    }
177
178
0
    inline EndCriteria::Type SabrInterpolatedSmileSection::endCriteria() const {
179
0
        calculate();
180
0
        return sabrInterpolation_->endCriteria();
181
0
    }
182
183
0
    inline Real SabrInterpolatedSmileSection::minStrike() const {
184
0
        calculate();
185
0
        return actualStrikes_.front();
186
187
0
    }
188
189
0
    inline Real SabrInterpolatedSmileSection::maxStrike() const {
190
0
        calculate();
191
0
        return actualStrikes_.back();
192
0
    }
193
194
0
    inline Real SabrInterpolatedSmileSection::atmLevel() const {
195
0
        calculate();
196
0
        return forwardValue_;
197
0
    }
198
199
200
}
201
202
#endif