QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
blackcalculator.hpp
Go to the documentation of this file.
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 <http://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
29
30namespace QuantLib {
31
32 //! Black 1976 calculator class
33 /*! \bug When the variance is null, division by zero occur during
34 the calculation of delta, delta forward, gamma, gamma
35 forward, rho, dividend rho, vega, and strike sensitivity.
36 */
38 private:
39 class Calculator;
40 public:
41 BlackCalculator(const ext::shared_ptr<StrikedTypePayoff>& payoff,
42 Real forward,
43 Real stdDev,
44 Real discount = 1.0);
46 Real strike,
47 Real forward,
48 Real stdDev,
49 Real discount = 1.0);
50 virtual ~BlackCalculator() = default;
51
52 Real value() const;
53
54 /*! Sensitivity to change in the underlying forward price. */
55 Real deltaForward() const;
56 /*! Sensitivity to change in the underlying spot price. */
57 virtual Real delta(Real spot) const;
58
59 /*! Sensitivity in percent to a percent change in the
60 underlying forward price. */
61 Real elasticityForward() const;
62 /*! Sensitivity in percent to a percent change in the
63 underlying spot price. */
64 virtual Real elasticity(Real spot) const;
65
66 /*! Second order derivative with respect to change in the
67 underlying forward price. */
68 Real gammaForward() const;
69 /*! Second order derivative with respect to change in the
70 underlying spot price. */
71 virtual Real gamma(Real spot) const;
72
73 /*! Sensitivity to time to maturity. */
74 virtual Real theta(Real spot,
75 Time maturity) const;
76 /*! Sensitivity to time to maturity per day,
77 assuming 365 day per year. */
78 virtual Real thetaPerDay(Real spot,
79 Time maturity) const;
80
81 /*! Sensitivity to volatility. */
82 Real vega(Time maturity) const;
83
84 /*! Sensitivity to discounting rate. */
85 Real rho(Time maturity) const;
86
87 /*! Sensitivity to dividend/growth rate. */
88 Real dividendRho(Time maturity) const;
89
90 /*! Probability of being in the money in the bond martingale
91 measure, i.e. N(d2).
92 It is a risk-neutral probability, not the real world one.
93 */
95
96 /*! Probability of being in the money in the asset martingale
97 measure, i.e. N(d1).
98 It is a risk-neutral probability, not the real world one.
99 */
101
102 /*! Sensitivity to strike. */
103 Real strikeSensitivity() const;
104
105 /*! gamma w.r.t. strike. */
106 Real strikeGamma() const;
107
108 Real alpha() const;
109 Real beta() const;
110 protected:
111 void initialize(const ext::shared_ptr<StrikedTypePayoff>& p);
117 };
118
119 // inline
121 Time maturity) const {
122 return theta(spot, maturity)/365.0;
123 }
124
126 return cum_d2_;
127 }
128
130 return cum_d1_;
131 }
132
134 return alpha_;
135 }
136
138 return beta_;
139 }
140
141}
142
143#endif
Black 1976 calculator class.
Real dividendRho(Time maturity) const
virtual Real delta(Real spot) const
Real vega(Time maturity) const
void initialize(const ext::shared_ptr< StrikedTypePayoff > &p)
virtual Real gamma(Real spot) const
virtual ~BlackCalculator()=default
virtual Real elasticity(Real spot) const
virtual Real thetaPerDay(Real spot, Time maturity) const
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real theta
Real rho
ext::shared_ptr< QuantLib::Payoff > payoff
Definition: any.hpp:35
Payoffs for various options.