/src/quantlib/ql/processes/batesprocess.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2008 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 | | #include <ql/processes/batesprocess.hpp> |
21 | | #include <ql/math/distributions/normaldistribution.hpp> |
22 | | #include <ql/math/distributions/poissondistribution.hpp> |
23 | | |
24 | | |
25 | | namespace QuantLib { |
26 | | BatesProcess::BatesProcess( |
27 | | const Handle<YieldTermStructure>& riskFreeRate, |
28 | | const Handle<YieldTermStructure>& dividendYield, |
29 | | const Handle<Quote>& s0, |
30 | | Real v0, Real kappa, |
31 | | Real theta, Real sigma, Real rho, |
32 | | Real lambda, Real nu, Real delta, |
33 | | HestonProcess::Discretization d) |
34 | 0 | : HestonProcess(riskFreeRate, dividendYield, |
35 | 0 | s0, v0, kappa, theta, sigma, rho, d), |
36 | 0 | lambda_(lambda), delta_(delta), nu_(nu), |
37 | 0 | m_(std::exp(nu+0.5*delta*delta)-1) { |
38 | 0 | } |
39 | | |
40 | 0 | Array BatesProcess::drift(Time t, const Array& x) const { |
41 | 0 | Array retVal = HestonProcess::drift(t, x); |
42 | 0 | retVal[0] -= lambda_*m_; |
43 | 0 | return retVal; |
44 | 0 | } |
45 | | |
46 | | Array BatesProcess::evolve(Time t0, const Array& x0, |
47 | 0 | Time dt, const Array& dw) const { |
48 | |
|
49 | 0 | const Size hestonFactors = HestonProcess::factors(); |
50 | |
|
51 | 0 | Real p = cumNormalDist_(dw[hestonFactors]); |
52 | 0 | if (p<0.0) |
53 | 0 | p = 0.0; |
54 | 0 | else if (p >= 1.0) |
55 | 0 | p = 1.0-QL_EPSILON; |
56 | | |
57 | 0 | const Real n = InverseCumulativePoisson(lambda_*dt)(p); |
58 | 0 | Array retVal = HestonProcess::evolve(t0, x0, dt, dw); |
59 | 0 | retVal[0] *= |
60 | 0 | std::exp(-lambda_*m_*dt + nu_*n+delta_*std::sqrt(n)*dw[hestonFactors+1]); |
61 | |
|
62 | 0 | return retVal; |
63 | 0 | } |
64 | | |
65 | 0 | Size BatesProcess::factors() const { |
66 | 0 | return HestonProcess::factors() + 2; |
67 | 0 | } |
68 | | |
69 | 0 | Real BatesProcess::lambda() const { |
70 | 0 | return lambda_; |
71 | 0 | } |
72 | | |
73 | 0 | Real BatesProcess::nu() const { |
74 | 0 | return nu_; |
75 | 0 | } |
76 | | |
77 | 0 | Real BatesProcess::delta() const { |
78 | 0 | return delta_; |
79 | 0 | } |
80 | | } |