QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
extouwithjumpsprocess.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2011 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
24#include <ql/experimental/processes/extendedornsteinuhlenbeckprocess.hpp>
25#include <ql/experimental/processes/extouwithjumpsprocess.hpp>
26#include <utility>
27
28namespace QuantLib {
29
31 ext::shared_ptr<ExtendedOrnsteinUhlenbeckProcess> process,
32 Real Y0,
33 Real beta,
34 Real jumpIntensity,
35 Real eta)
36 : Y0_(Y0), beta_(beta), jumpIntensity_(jumpIntensity), eta_(eta),
37 ouProcess_(std::move(process)) {
38 QL_REQUIRE(ouProcess_, "null Ornstein/Uhlenbeck process");
39 }
40
42 return 2;
43 }
45 return 3;
46 }
47 ext::shared_ptr<ExtendedOrnsteinUhlenbeckProcess>
49 return ouProcess_;
50 }
52 return beta_;
53 }
55 return jumpIntensity_;
56 }
58 return eta_;
59 }
60
62 return {
63 ouProcess_->x0(),
64 Y0_
65 };
66 }
67
69 return {
70 ouProcess_->drift(t, x[0]),
71 -beta_*x[1]
72 };
73 }
74
76 Matrix retVal(2, 2, 0.0);
77 retVal[0][0] = ouProcess_->diffusion(t, x[0]);
78
79 return retVal;
80 }
81
83 Time t0, const Array& x0, Time dt, const Array& dw) const {
84
85 Array retVal(2);
86 retVal[0] = ouProcess_->evolve(t0, x0[0], dt, dw[0]);
87 retVal[1] = x0[1]*std::exp(-beta_*dt);
88
89 const Real u1 = std::max(QL_EPSILON, std::min(cumNormalDist_(dw[1]),
90 1.0-QL_EPSILON));
91
92 const Time interarrival = -1.0/jumpIntensity_*std::log(u1);
93 if (interarrival < dt) {
94 const Real u2 = std::max(QL_EPSILON, std::min(cumNormalDist_(dw[2]),
95 1.0-QL_EPSILON));
96 const Real jumpSize = -1.0/eta_*std::log(u2);
97 retVal[1] += jumpSize;
98 }
99 return retVal;
100 }
101}
1-D array used in linear algebra.
Definition: array.hpp:52
const ext::shared_ptr< ExtendedOrnsteinUhlenbeckProcess > ouProcess_
Array drift(Time t, const Array &x) const override
returns the drift part of the equation, i.e.,
Size size() const override
returns the number of dimensions of the stochastic process
Array evolve(Time t0, const Array &x0, Time dt, const Array &dw) const override
ExtOUWithJumpsProcess(ext::shared_ptr< ExtendedOrnsteinUhlenbeckProcess > process, Real Y0, Real beta, Real jumpIntensity, Real eta)
ext::shared_ptr< ExtendedOrnsteinUhlenbeckProcess > getExtendedOrnsteinUhlenbeckProcess() const
Matrix diffusion(Time t, const Array &x) const override
returns the diffusion part of the equation, i.e.
Size factors() const override
returns the number of independent factors of the process
Array initialValues() const override
returns the initial values of the state variables
const CumulativeNormalDistribution cumNormalDist_
Matrix used in linear algebra.
Definition: matrix.hpp:41
#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.