1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 3 /* 4 Copyright (C) 2001, 2002, 2003 Sadruddin Rejeb 5 Copyright (C) 2003 Ferdinando Ametrano 6 Copyright (C) 2004, 2005, 2006, 2007, 2009 StatPro Italia srl 7 Copyright (C) 2015 Peter Caspers 8 9 This file is part of QuantLib, a free-software/open-source library 10 for financial quantitative analysts and developers - http://quantlib.org/ 11 12 QuantLib is free software: you can redistribute it and/or modify it 13 under the terms of the QuantLib license. You should have received a 14 copy of the license along with this program; if not, please email 15 <quantlib-dev@lists.sf.net>. The license is also available online at 16 <http://quantlib.org/license.shtml>. 17 18 This program is distributed in the hope that it will be useful, but WITHOUT 19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 20 FOR A PARTICULAR PURPOSE. See the license for more details. 21 */ 22 23 /*! \file blackscholesprocess.hpp 24 \brief Black-Scholes processes 25 */ 26 27 #ifndef quantlib_black_scholes_process_hpp 28 #define quantlib_black_scholes_process_hpp 29 30 #include <ql/stochasticprocess.hpp> 31 #include <ql/processes/eulerdiscretization.hpp> 32 #include <ql/termstructures/yieldtermstructure.hpp> 33 #include <ql/termstructures/volatility/equityfx/blackvoltermstructure.hpp> 34 #include <ql/termstructures/volatility/equityfx/localvoltermstructure.hpp> 35 #include <ql/quote.hpp> 36 37 namespace QuantLib { 38 39 class LocalConstantVol; 40 class LocalVolCurve; 41 42 //! Generalized Black-Scholes stochastic process 43 /*! This class describes the stochastic process \f$ S \f$ governed by 44 \f[ 45 d\ln S(t) = (r(t) - q(t) - \frac{\sigma(t, S)^2}{2}) dt 46 + \sigma dW_t. 47 \f] 48 49 \warning while the interface is expressed in terms of \f$ S \f$, 50 the internal calculations work on \f$ ln S \f$. 51 52 \ingroup processes 53 */ 54 class GeneralizedBlackScholesProcess : public StochasticProcess1D { 55 public: 56 GeneralizedBlackScholesProcess( 57 const Handle<Quote>& x0, 58 const Handle<YieldTermStructure>& dividendTS, 59 const Handle<YieldTermStructure>& riskFreeTS, 60 const Handle<BlackVolTermStructure>& blackVolTS, 61 const ext::shared_ptr<discretization>& d = 62 ext::shared_ptr<discretization>(new EulerDiscretization), 63 bool forceDiscretization = false); 64 65 GeneralizedBlackScholesProcess( 66 const Handle<Quote>& x0, 67 const Handle<YieldTermStructure>& dividendTS, 68 const Handle<YieldTermStructure>& riskFreeTS, 69 const Handle<BlackVolTermStructure>& blackVolTS, 70 const Handle<LocalVolTermStructure>& localVolTS); 71 72 //! \name StochasticProcess1D interface 73 //@{ 74 Real x0() const; 75 /*! \todo revise extrapolation */ 76 Real drift(Time t, Real x) const; 77 /*! \todo revise extrapolation */ 78 Real diffusion(Time t, Real x) const; 79 Real apply(Real x0, Real dx) const; 80 /*! \warning in general raises a "not implemented" exception. 81 It should be rewritten to return the expectation E(S) 82 of the process, not exp(E(log S)). 83 */ 84 Real expectation(Time t0, Real x0, Time dt) const; 85 Real stdDeviation(Time t0, Real x0, Time dt) const; 86 Real variance(Time t0, Real x0, Time dt) const; 87 Real evolve(Time t0, Real x0, Time dt, Real dw) const; 88 //@} 89 Time time(const Date&) const; 90 //! \name Observer interface 91 //@{ 92 void update(); 93 //@} 94 //! \name Inspectors 95 //@{ 96 const Handle<Quote>& stateVariable() const; 97 const Handle<YieldTermStructure>& dividendYield() const; 98 const Handle<YieldTermStructure>& riskFreeRate() const; 99 const Handle<BlackVolTermStructure>& blackVolatility() const; 100 const Handle<LocalVolTermStructure>& localVolatility() const; 101 //@} 102 private: 103 Handle<Quote> x0_; 104 Handle<YieldTermStructure> riskFreeRate_, dividendYield_; 105 Handle<BlackVolTermStructure> blackVolatility_; 106 Handle<LocalVolTermStructure> externalLocalVolTS_; 107 bool forceDiscretization_; 108 bool hasExternalLocalVol_; 109 mutable RelinkableHandle<LocalVolTermStructure> localVolatility_; 110 mutable bool updated_, isStrikeIndependent_; 111 }; 112 113 //! Black-Scholes (1973) stochastic process 114 /*! This class describes the stochastic process \f$ S \f$ for a stock 115 given by 116 \f[ 117 d\ln S(t) = (r(t) - \frac{\sigma(t, S)^2}{2}) dt + \sigma dW_t. 118 \f] 119 120 \warning while the interface is expressed in terms of \f$ S \f$, 121 the internal calculations work on \f$ ln S \f$. 122 123 \ingroup processes 124 */ 125 class BlackScholesProcess : public GeneralizedBlackScholesProcess { 126 public: 127 BlackScholesProcess( 128 const Handle<Quote>& x0, 129 const Handle<YieldTermStructure>& riskFreeTS, 130 const Handle<BlackVolTermStructure>& blackVolTS, 131 const ext::shared_ptr<discretization>& d = 132 ext::shared_ptr<discretization>(new EulerDiscretization), 133 bool forceDiscretization = false); 134 }; 135 136 //! Merton (1973) extension to the Black-Scholes stochastic process 137 /*! This class describes the stochastic process ln(S) for a stock or 138 stock index paying a continuous dividend yield given by 139 \f[ 140 d\ln S(t, S) = (r(t) - q(t) - \frac{\sigma(t, S)^2}{2}) dt 141 + \sigma dW_t. 142 \f] 143 144 \ingroup processes 145 */ 146 class BlackScholesMertonProcess : public GeneralizedBlackScholesProcess { 147 public: 148 BlackScholesMertonProcess( 149 const Handle<Quote>& x0, 150 const Handle<YieldTermStructure>& dividendTS, 151 const Handle<YieldTermStructure>& riskFreeTS, 152 const Handle<BlackVolTermStructure>& blackVolTS, 153 const ext::shared_ptr<discretization>& d = 154 ext::shared_ptr<discretization>(new EulerDiscretization), 155 bool forceDiscretization = false); 156 }; 157 158 //! Black (1976) stochastic process 159 /*! This class describes the stochastic process \f$ S \f$ for a 160 forward or futures contract given by 161 \f[ 162 d\ln S(t) = -\frac{\sigma(t, S)^2}{2} dt + \sigma dW_t. 163 \f] 164 165 \warning while the interface is expressed in terms of \f$ S \f$, 166 the internal calculations work on \f$ ln S \f$. 167 168 \ingroup processes 169 */ 170 class BlackProcess : public GeneralizedBlackScholesProcess { 171 public: 172 BlackProcess( 173 const Handle<Quote>& x0, 174 const Handle<YieldTermStructure>& riskFreeTS, 175 const Handle<BlackVolTermStructure>& blackVolTS, 176 const ext::shared_ptr<discretization>& d = 177 ext::shared_ptr<discretization>(new EulerDiscretization), 178 bool forceDiscretization = false); 179 }; 180 181 //! Garman-Kohlhagen (1983) stochastic process 182 /*! This class describes the stochastic process \f$ S \f$ for an exchange 183 rate given by 184 \f[ 185 d\ln S(t) = (r(t) - r_f(t) - \frac{\sigma(t, S)^2}{2}) dt 186 + \sigma dW_t. 187 \f] 188 189 \warning while the interface is expressed in terms of \f$ S \f$, 190 the internal calculations work on \f$ ln S \f$. 191 192 \ingroup processes 193 */ 194 class GarmanKohlagenProcess : public GeneralizedBlackScholesProcess { 195 public: 196 GarmanKohlagenProcess( 197 const Handle<Quote>& x0, 198 const Handle<YieldTermStructure>& foreignRiskFreeTS, 199 const Handle<YieldTermStructure>& domesticRiskFreeTS, 200 const Handle<BlackVolTermStructure>& blackVolTS, 201 const ext::shared_ptr<discretization>& d = 202 ext::shared_ptr<discretization>(new EulerDiscretization), 203 bool forceDiscretization = false); 204 }; 205 206 } 207 208 209 #endif 210