QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
extendedblackscholesprocess.cpp
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) 2008 Frank Hövermann
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 <http://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
21
22namespace QuantLib {
23
25 const Handle<Quote>& x0,
26 const Handle<YieldTermStructure>& dividendTS,
27 const Handle<YieldTermStructure>& riskFreeTS,
28 const Handle<BlackVolTermStructure>& blackVolTS,
29 const ext::shared_ptr<discretization>& d,
30 Discretization evolDisc)
31 : GeneralizedBlackScholesProcess(x0,dividendTS,riskFreeTS,blackVolTS,d),
32 discretization_(evolDisc) {}
33
35 Real sigma = diffusion(t,x);
36 // we could be more anticipatory if we know the right dt
37 // for which the drift will be used
38 Time t1 = t + 0.0001;
39 return riskFreeRate()->forwardRate(t,t1,Continuous,NoFrequency,true).rate()
40 - dividendYield()->forwardRate(t,t1,Continuous,NoFrequency,true).rate()
41 - 0.5 * sigma * sigma;
42 }
43
45 return blackVolatility()->blackVol(t, x, true);
46 }
47
49 Time dt, Real dw) const {
50 Real predictor, sigma0, sigma1;
51 Time t1;
52 Rate rate0, rate1;
53 Real driftterm, diffusionterm, corrector;
54 switch (discretization_) {
55 case Milstein:
56 // Milstein scheme
57 return apply(x0, drift(t0, x0)*dt
58 + 0.5*std::pow(diffusion(t0, x0),2)*(dw*dw-1)*dt
59 + diffusion(t0,x0)*std::sqrt(dt)*dw);
60 break;
61 case Euler:
62 // Usual Euler scheme
63 return apply(expectation(t0,x0,dt), stdDeviation(t0,x0,dt)*dw);
64 break;
66 // Predictor-Corrector scheme with equal weighting
67 predictor =
68 apply(expectation(t0,x0,dt), stdDeviation(t0,x0,dt)*dw);
69 t1 = t0 + 0.0001;
70 sigma0 = diffusion(t0,x0);
71 sigma1 = diffusion(t0+dt,predictor);
72 rate0 =
73 riskFreeRate()->forwardRate(t0,t1,Continuous,NoFrequency,true).rate()
74 - dividendYield()->forwardRate(t0,t1,Continuous,NoFrequency,true).rate()
75 - 0.5*std::pow(sigma0,2);
76 rate1 =
77 riskFreeRate()->forwardRate(t0+dt,t1+dt,Continuous,
78 NoFrequency,true).rate()
79 - dividendYield()->forwardRate(t0+dt,t1+dt,
80 Continuous,NoFrequency,true).rate()
81 - 0.5*std::pow(sigma1,2);
82 driftterm = 0.5*rate1+0.5*rate0;
83 diffusionterm = 0.5*(sigma1+sigma0);
84 corrector =
85 apply(x0,driftterm*dt+diffusionterm*std::sqrt(dt)*dw);
86 return corrector;
87 break;
88 default:
89 QL_FAIL("unknown discretization scheme");
90 }
91 }
92
93}
ExtendedBlackScholesMertonProcess(const Handle< Quote > &x0, const Handle< YieldTermStructure > &dividendTS, const Handle< YieldTermStructure > &riskFreeTS, const Handle< BlackVolTermStructure > &blackVolTS, const ext::shared_ptr< discretization > &d=ext::shared_ptr< discretization >(new EulerDiscretization), Discretization evolDisc=Milstein)
Real diffusion(Time t, Real x) const override
returns the diffusion part of the equation, i.e.
Real evolve(Time t0, Real x0, Time dt, Real dw) const override
Real drift(Time t, Real x) const override
returns the drift part of the equation, i.e.
Generalized Black-Scholes stochastic process.
Real apply(Real x0, Real dx) const override
const Handle< YieldTermStructure > & dividendYield() const
Real stdDeviation(Time t0, Real x0, Time dt) const override
Real expectation(Time t0, Real x0, Time dt) const override
const Handle< BlackVolTermStructure > & blackVolatility() const
Real x0() const override
returns the initial value of the state variable
const Handle< YieldTermStructure > & riskFreeRate() const
Shared handle to an observable.
Definition: handle.hpp:41
const DefaultType & t
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
Date d
experimental Black-Scholes-Merton process
@ NoFrequency
null frequency
Definition: frequency.hpp:37
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real Rate
interest rates
Definition: types.hpp:70
Real sigma
Definition: any.hpp:35