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
25namespace 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 : HestonProcess(riskFreeRate, dividendYield,
35 s0, v0, kappa, theta, sigma, rho, d),
36 lambda_(lambda), delta_(delta), nu_(nu),
37 m_(std::exp(x: nu+0.5*delta*delta)-1) {
38 }
39
40 Array BatesProcess::drift(Time t, const Array& x) const {
41 Array retVal = HestonProcess::drift(t, x);
42 retVal[0] -= lambda_*m_;
43 return retVal;
44 }
45
46 Array BatesProcess::evolve(Time t0, const Array& x0,
47 Time dt, const Array& dw) const {
48
49 const Size hestonFactors = HestonProcess::factors();
50
51 Real p = cumNormalDist_(dw[hestonFactors]);
52 if (p<0.0)
53 p = 0.0;
54 else if (p >= 1.0)
55 p = 1.0-QL_EPSILON;
56
57 const Real n = InverseCumulativePoisson(lambda_*dt)(p);
58 Array retVal = HestonProcess::evolve(t0, x0, dt, dw);
59 retVal[0] *=
60 std::exp(x: -lambda_*m_*dt + nu_*n+delta_*std::sqrt(x: n)*dw[hestonFactors+1]);
61
62 return retVal;
63 }
64
65 Size BatesProcess::factors() const {
66 return HestonProcess::factors() + 2;
67 }
68
69 Real BatesProcess::lambda() const {
70 return lambda_;
71 }
72
73 Real BatesProcess::nu() const {
74 return nu_;
75 }
76
77 Real BatesProcess::delta() const {
78 return delta_;
79 }
80}
81

source code of quantlib/ql/processes/batesprocess.cpp

Morty Proxy This is a proxified and sanitized view of the page, visit original site.