Coverage Report

Created: 2026-02-03 07:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/pricingengines/blackscholescalculator.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2006 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 blackscholescalculator.hpp
21
    \brief Black-Scholes formula calculator class
22
*/
23
24
#ifndef quantlib_blackscholescalculator_hpp
25
#define quantlib_blackscholescalculator_hpp
26
27
#include <ql/pricingengines/blackcalculator.hpp>
28
29
namespace QuantLib {
30
31
    //! Black-Scholes 1973 calculator class
32
    class BlackScholesCalculator : public BlackCalculator {
33
      public:
34
        BlackScholesCalculator(
35
                        const ext::shared_ptr<StrikedTypePayoff>& payoff,
36
                        Real spot,
37
                        DiscountFactor growth,
38
                        Real stdDev,
39
                        DiscountFactor discount);
40
        BlackScholesCalculator(Option::Type optionType,
41
                               Real strike,
42
                               Real spot,
43
                               DiscountFactor growth,
44
                               Real stdDev,
45
                               DiscountFactor discount);
46
        ~BlackScholesCalculator() override = default;
47
        /*! Sensitivity to change in the underlying spot price. */
48
        Real delta() const;
49
        /*! Sensitivity in percent to a percent change in the
50
            underlying spot price. */
51
        Real elasticity() const;
52
        /*! Second order derivative with respect to change in the
53
            underlying spot price. */
54
        Real gamma() const;
55
        /*! Sensitivity to time to maturity. */
56
        Real theta(Time maturity) const;
57
        /*! Sensitivity to time to maturity per day
58
            (assuming 365 day in a year). */
59
        Real thetaPerDay(Time maturity) const;
60
        // also un-hide overloads taking a spot
61
        using BlackCalculator::delta;
62
        using BlackCalculator::elasticity;
63
        using BlackCalculator::gamma;
64
        using BlackCalculator::theta;
65
        using BlackCalculator::thetaPerDay;
66
      protected:
67
        Real spot_;
68
        DiscountFactor growth_;
69
    };
70
71
    // inline
72
0
    inline Real BlackScholesCalculator::delta() const {
73
0
        return BlackCalculator::delta(spot_);
74
0
    }
75
76
0
    inline Real BlackScholesCalculator::elasticity() const {
77
0
        return BlackCalculator::elasticity(spot_);
78
0
    }
79
80
0
    inline Real BlackScholesCalculator::gamma() const {
81
0
        return BlackCalculator::gamma(spot_);
82
0
    }
83
84
0
    inline Real BlackScholesCalculator::theta(Time maturity) const {
85
0
        return BlackCalculator::theta(spot_, maturity);
86
0
    }
87
88
0
    inline Real BlackScholesCalculator::thetaPerDay(Time maturity) const {
89
0
        return BlackCalculator::thetaPerDay(spot_, maturity);
90
0
    }
91
92
}
93
94
#endif