QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
batesprocess.cpp
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 {
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,
34 : HestonProcess(riskFreeRate, dividendYield,
35 s0, v0, kappa, theta, sigma, rho, d),
36 lambda_(lambda), delta_(delta), nu_(nu),
37 m_(std::exp(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
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(-lambda_*m_*dt + nu_*n+delta_*std::sqrt(n)*dw[hestonFactors+1]);
61
62 return retVal;
63 }
64
66 return HestonProcess::factors() + 2;
67 }
68
70 return lambda_;
71 }
72
74 return nu_;
75 }
76
78 return delta_;
79 }
80}
1-D array used in linear algebra.
Definition: array.hpp:52
Array drift(Time t, const Array &x) const override
returns the drift part of the equation, i.e.,
Array evolve(Time t0, const Array &x0, Time dt, const Array &dw) const override
Size factors() const override
returns the number of independent factors of the process
BatesProcess(const Handle< YieldTermStructure > &riskFreeRate, const Handle< YieldTermStructure > &dividendYield, const Handle< Quote > &s0, Real v0, Real kappa, Real theta, Real sigma, Real rho, Real lambda, Real nu, Real delta, HestonProcess::Discretization d=HestonProcess::FullTruncation)
const CumulativeNormalDistribution cumNormalDist_
Shared handle to an observable.
Definition: handle.hpp:41
Square-root stochastic-volatility Heston process.
Array drift(Time t, const Array &x) const override
returns the drift part of the equation, i.e.,
Array evolve(Time t0, const Array &x0, Time dt, const Array &dw) const override
Size factors() const override
returns the number of independent factors of the process
Inverse cumulative Poisson distribution function.
#define QL_EPSILON
Definition: qldefines.hpp:178
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
STL namespace.