• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lballabio / QuantLib / 27081312717

07 Jun 2026 03:17AM UTC coverage: 74.801% (+0.004%) from 74.797%
27081312717

Pull #2619

github

web-flow
Merge d8f820f5b into 5111c3a14
Pull Request #2619: Use make_shared in volatility-related code

54 of 72 new or added lines in 22 files covered. (75.0%)

1 existing line in 1 file now uncovered.

59143 of 79067 relevant lines covered (74.8%)

8576610.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/ql/termstructures/volatility/sabrinterpolatedsmilesection.cpp
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
#include <ql/quotes/simplequote.hpp>
23
#include <ql/settings.hpp>
24
#include <ql/termstructures/volatility/sabrinterpolatedsmilesection.hpp>
25
#include <utility>
26

27
namespace QuantLib {
28

29
    SabrInterpolatedSmileSection::SabrInterpolatedSmileSection(
×
30
        const Date& optionDate,
31
        Handle<Quote> forward,
32
        const std::vector<Rate>& strikes,
33
        bool hasFloatingStrikes,
34
        Handle<Quote> atmVolatility,
35
        const std::vector<Handle<Quote> >& volHandles,
36
        Real alpha,
37
        Real beta,
38
        Real nu,
39
        Real rho,
40
        bool isAlphaFixed,
41
        bool isBetaFixed,
42
        bool isNuFixed,
43
        bool isRhoFixed,
44
        bool vegaWeighted,
45
        ext::shared_ptr<EndCriteria> endCriteria,
46
        ext::shared_ptr<OptimizationMethod> method,
47
        const DayCounter& dc,
48
        const Real shift)
×
49
    : SmileSection(optionDate, dc, Date(), ShiftedLognormal, shift), forward_(std::move(forward)),
×
50
      atmVolatility_(std::move(atmVolatility)), volHandles_(volHandles), strikes_(strikes),
×
51
      actualStrikes_(strikes), hasFloatingStrikes_(hasFloatingStrikes), vols_(volHandles.size()),
×
52
      alpha_(alpha), beta_(beta), nu_(nu), rho_(rho), isAlphaFixed_(isAlphaFixed),
×
53
      isBetaFixed_(isBetaFixed), isNuFixed_(isNuFixed), isRhoFixed_(isRhoFixed),
×
54
      vegaWeighted_(vegaWeighted), endCriteria_(std::move(endCriteria)), method_(std::move(method)),
×
55
      evaluationDate_(Settings::instance().evaluationDate()) {
×
56

57
        LazyObject::registerWith(forward_);
×
58
        LazyObject::registerWith(atmVolatility_);
×
59
        for (auto& volHandle : volHandles_)
×
60
            LazyObject::registerWith(volHandle);
×
61
    }
×
62

63
    SabrInterpolatedSmileSection::SabrInterpolatedSmileSection(
×
64
        const Date& optionDate,
65
        const Rate& forward,
66
        const std::vector<Rate>& strikes,
67
        bool hasFloatingStrikes,
68
        const Volatility& atmVolatility,
69
        const std::vector<Volatility>& volHandles,
70
        Real alpha,
71
        Real beta,
72
        Real nu,
73
        Real rho,
74
        bool isAlphaFixed,
75
        bool isBetaFixed,
76
        bool isNuFixed,
77
        bool isRhoFixed,
78
        bool vegaWeighted,
79
        ext::shared_ptr<EndCriteria> endCriteria,
80
        ext::shared_ptr<OptimizationMethod> method,
81
        const DayCounter& dc,
82
        const Real shift)
×
83
    : SmileSection(optionDate, dc, Date(), ShiftedLognormal, shift),
×
NEW
84
      forward_(Handle<Quote>(ext::make_shared<SimpleQuote>(forward))),
×
NEW
85
      atmVolatility_(Handle<Quote>(ext::make_shared<SimpleQuote>(atmVolatility))),
×
86
      volHandles_(volHandles.size()), strikes_(strikes), actualStrikes_(strikes),
×
87
      hasFloatingStrikes_(hasFloatingStrikes), vols_(volHandles.size()), alpha_(alpha), beta_(beta),
×
88
      nu_(nu), rho_(rho), isAlphaFixed_(isAlphaFixed), isBetaFixed_(isBetaFixed),
×
89
      isNuFixed_(isNuFixed), isRhoFixed_(isRhoFixed), vegaWeighted_(vegaWeighted),
×
90
      endCriteria_(std::move(endCriteria)), method_(std::move(method)),
91
      evaluationDate_(Settings::instance().evaluationDate()) {
×
92

93
        for (Size i = 0; i < volHandles_.size(); ++i)
×
NEW
94
            volHandles_[i] = Handle<Quote>(ext::make_shared<SimpleQuote>(volHandles[i]));
×
95
    }
×
96

97
    void SabrInterpolatedSmileSection::createInterpolation() const {
×
98
         ext::shared_ptr<SABRInterpolation> tmp = ext::make_shared<SABRInterpolation>(
NEW
99
             actualStrikes_.begin(), actualStrikes_.end(), vols_.begin(),
×
NEW
100
             exerciseTime(), forwardValue_, alpha_, beta_, nu_, rho_,
×
NEW
101
             isAlphaFixed_, isBetaFixed_, isNuFixed_, isRhoFixed_, vegaWeighted_,
×
NEW
102
             endCriteria_, method_, 0.0020, false, 50, shift());
×
103
         swap(tmp, sabrInterpolation_);
104
    }
×
105

106
    void SabrInterpolatedSmileSection::performCalculations() const {
×
107
        forwardValue_ = forward_->value();
×
108
        vols_.clear();
×
109
        actualStrikes_.clear();
×
110
        // we populate the volatilities, skipping the invalid ones
111
        for (Size i=0; i<volHandles_.size(); ++i) {
×
112
            if (volHandles_[i]->isValid()) {
×
113
                if (hasFloatingStrikes_) {
×
114
                    actualStrikes_.push_back(forwardValue_ + strikes_[i]);
×
115
                    vols_.push_back(atmVolatility_->value() + volHandles_[i]->value());
×
116
                } else {
117
                    actualStrikes_.push_back(strikes_[i]);
×
118
                    vols_.push_back(volHandles_[i]->value());
×
119
                }
120
            }
121
        }
122
        // we are recreating the sabrinterpolation object unconditionnaly to
123
        // avoid iterator invalidation
124
        createInterpolation();
×
125
        sabrInterpolation_->update();
×
126
    }
×
127

128
    Real SabrInterpolatedSmileSection::varianceImpl(Real strike) const {
×
129
        calculate();
×
130
        Real v = (*sabrInterpolation_)(strike, true);
×
131
        return v*v*exerciseTime();
×
132
    }
133

134
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc