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

lballabio / QuantLib / 18902330216

29 Oct 2025 08:56AM UTC coverage: 74.321% (+0.4%) from 73.914%
18902330216

Pull #2344

github

web-flow
Merge a8095fd90 into d823f4ecb
Pull Request #2344: add multicurve bootstrap

100 of 104 new or added lines in 8 files covered. (96.15%)

216 existing lines in 13 files now uncovered.

57073 of 76793 relevant lines covered (74.32%)

8779123.65 hits per line

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

83.33
/ql/pricingengines/blackcalculator.hpp
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2

3
/*
4
 Copyright (C) 2003, 2004, 2005, 2006 Ferdinando Ametrano
5
 Copyright (C) 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 blackcalculator.hpp
22
    \brief Black-formula calculator class
23
*/
24

25
#ifndef quantlib_blackcalculator_hpp
26
#define quantlib_blackcalculator_hpp
27

28
#include <ql/instruments/payoffs.hpp>
29

30
namespace QuantLib {
31

32
    //! Black 1976 calculator class
33
    class BlackCalculator {
34
      private:
35
        class Calculator;
36
      public:
37
        BlackCalculator(const ext::shared_ptr<StrikedTypePayoff>& payoff,
38
                        Real forward,
39
                        Real stdDev,
40
                        Real discount = 1.0);
41
        BlackCalculator(Option::Type optionType,
42
                        Real strike,
43
                        Real forward,
44
                        Real stdDev,
45
                        Real discount = 1.0);
46
        virtual ~BlackCalculator() = default;
6,302,046✔
47

48
        Real value() const;
49

50
        /*! Sensitivity to change in the underlying forward price. */
51
        Real deltaForward() const;
52
        /*! Sensitivity to change in the underlying spot price. */
53
        virtual Real delta(Real spot) const;
54

55
        /*! Sensitivity in percent to a percent change in the
56
            underlying forward price. */
57
        Real elasticityForward() const;
58
        /*! Sensitivity in percent to a percent change in the
59
            underlying spot price. */
60
        virtual Real elasticity(Real spot) const;
61

62
        /*! Second order derivative with respect to change in the
63
            underlying forward price. */
64
        Real gammaForward() const;
65
        /*! Second order derivative with respect to change in the
66
            underlying spot price. */
67
        virtual Real gamma(Real spot) const;
68

69
        /*! Sensitivity to time to maturity. */
70
        virtual Real theta(Real spot,
71
                           Time maturity) const;
72
        /*! Sensitivity to time to maturity per day,
73
            assuming 365 day per year. */
74
        virtual Real thetaPerDay(Real spot,
75
                                 Time maturity) const;
76

77
        /*! Sensitivity to volatility. */
78
        Real vega(Time maturity) const;
79

80
        /*! Sensitivity to discounting rate. */
81
        Real rho(Time maturity) const;
82

83
        /*! Sensitivity to dividend/growth rate. */
84
        Real dividendRho(Time maturity) const;
85

86
        /*! Probability of being in the money in the bond martingale
87
            measure, i.e. N(d2).
88
            It is a risk-neutral probability, not the real world one.
89
        */
90
        Real itmCashProbability() const;
91

92
        /*! Probability of being in the money in the asset martingale
93
            measure, i.e. N(d1).
94
            It is a risk-neutral probability, not the real world one.
95
        */
96
        Real itmAssetProbability() const;
97

98
        /*! Sensitivity to strike. */
99
        Real strikeSensitivity() const;
100

101
        /*! gamma w.r.t. strike. */
102
        Real strikeGamma() const;
103

104
        /*! Sensitivity of vega to spot (Vanna) */
105
        Real vanna(Real spot, Time maturity) const;
106

107
        /*! Sensitivity of vega to volatility (Volga) */
108
        Real volga(Time maturity) const;
109

110
        Real alpha() const;
111
        Real beta() const;
112
        
113
      protected:
114
        void initialize(const ext::shared_ptr<StrikedTypePayoff>& p);
115
        
116
        Real strike_, forward_, stdDev_, discount_, variance_;
117
        Real d1_, d2_;
118
        Real alpha_, beta_, DalphaDd1_, DbetaDd2_;
119
        Real n_d1_, cum_d1_, n_d2_, cum_d2_;
120
        Real x_, DxDs_, DxDstrike_;
121
    };
122

123
    // inline
UNCOV
124
    inline Real BlackCalculator::thetaPerDay(Real spot,
×
125
                                             Time maturity) const {
126
        return theta(spot, maturity)/365.0;
570,935✔
127
    }
128

129
    inline Real BlackCalculator::itmCashProbability() const {
130
        return cum_d2_;
528,898✔
131
    }
132

133
    inline Real BlackCalculator::itmAssetProbability() const {
134
        return cum_d1_;
1✔
135
    }
136

137
    inline Real BlackCalculator::alpha() const {
138
        return alpha_;
139
    }
140

141
    inline Real BlackCalculator::beta() const {
142
        return beta_;
24,949✔
143
    }
144

145
}
146

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

© 2025 Coveralls, Inc