1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 /*
4  Copyright (C) 2005, 2007, 2009, 2014 Klaus Spanderen
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 
20 /*! \file hestonprocess.hpp
21     \brief Heston stochastic process
22 */
23 
24 #ifndef quantlib_heston_process_hpp
25 #define quantlib_heston_process_hpp
26 
27 #include <ql/stochasticprocess.hpp>
28 #include <ql/termstructures/yieldtermstructure.hpp>
29 #include <ql/quote.hpp>
30 
31 namespace QuantLib {
32 
33     //! Square-root stochastic-volatility Heston process
34     /*! This class describes the square root stochastic volatility
35         process governed by
36         \f[
37         \begin{array}{rcl}
38         dS(t, S)  &=& \mu S dt + \sqrt{v} S dW_1 \\
39         dv(t, S)  &=& \kappa (\theta - v) dt + \sigma \sqrt{v} dW_2 \\
40         dW_1 dW_2 &=& \rho dt
41         \end{array}
42         \f]
43 
44         \ingroup processes
45     */
46     class HestonProcess : public StochasticProcess {
47       public:
48         enum Discretization { PartialTruncation,
49                               FullTruncation,
50                               Reflection,
51                               NonCentralChiSquareVariance,
52                               QuadraticExponential,
53                               QuadraticExponentialMartingale,
54                               BroadieKayaExactSchemeLobatto,
55                               BroadieKayaExactSchemeLaguerre,
56                               BroadieKayaExactSchemeTrapezoidal };
57 
58         HestonProcess(const Handle<YieldTermStructure>& riskFreeRate,
59                       const Handle<YieldTermStructure>& dividendYield,
60                       const Handle<Quote>& s0,
61                       Real v0, Real kappa,
62                       Real theta, Real sigma, Real rho,
63                       Discretization d = QuadraticExponentialMartingale);
64 
65         Size size() const;
66         Size factors() const;
67 
68         Disposable<Array> initialValues() const;
69         Disposable<Array> drift(Time t, const Array& x) const;
70         Disposable<Matrix> diffusion(Time t, const Array& x) const;
71         Disposable<Array> apply(const Array& x0, const Array& dx) const;
72         Disposable<Array> evolve(Time t0, const Array& x0,
73                                  Time dt, const Array& dw) const;
74 
v0() const75         Real v0()    const { return v0_; }
rho() const76         Real rho()   const { return rho_; }
kappa() const77         Real kappa() const { return kappa_; }
theta() const78         Real theta() const { return theta_; }
sigma() const79         Real sigma() const { return sigma_; }
80 
81         const Handle<Quote>& s0() const;
82         const Handle<YieldTermStructure>& dividendYield() const;
83         const Handle<YieldTermStructure>& riskFreeRate() const;
84 
85         Time time(const Date&) const;
86 
87         // probability densitiy function,
88         // semi-analytical solution of the Fokker-Planck equation in x=ln(s)
89         Real pdf(Real x, Real v, Time t, Real eps=1e-3) const;
90 
91       private:
92         Real varianceDistribution(Real v, Real dw, Time dt) const;
93 
94         Handle<YieldTermStructure> riskFreeRate_, dividendYield_;
95         Handle<Quote> s0_;
96         Real v0_, kappa_, theta_, sigma_, rho_;
97         Discretization discretization_;
98     };
99 }
100 #endif
101