/src/quantlib/ql/experimental/processes/extouwithjumpsprocess.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) 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 | | |
20 | | /*! \file expouwithjumpsprocess.cpp |
21 | | \brief Ornstein Uhlenbeck process plus exp jumps (Kluge Model) |
22 | | */ |
23 | | |
24 | | #include <ql/experimental/processes/extendedornsteinuhlenbeckprocess.hpp> |
25 | | #include <ql/experimental/processes/extouwithjumpsprocess.hpp> |
26 | | #include <utility> |
27 | | |
28 | | namespace QuantLib { |
29 | | |
30 | | ExtOUWithJumpsProcess::ExtOUWithJumpsProcess( |
31 | | ext::shared_ptr<ExtendedOrnsteinUhlenbeckProcess> process, |
32 | | Real Y0, |
33 | | Real beta, |
34 | | Real jumpIntensity, |
35 | | Real eta) |
36 | 0 | : Y0_(Y0), beta_(beta), jumpIntensity_(jumpIntensity), eta_(eta), |
37 | 0 | ouProcess_(std::move(process)) { |
38 | 0 | QL_REQUIRE(ouProcess_, "null Ornstein/Uhlenbeck process"); |
39 | 0 | } |
40 | | |
41 | 0 | Size ExtOUWithJumpsProcess::size() const { |
42 | 0 | return 2; |
43 | 0 | } |
44 | 0 | Size ExtOUWithJumpsProcess::factors() const { |
45 | 0 | return 3; |
46 | 0 | } |
47 | | ext::shared_ptr<ExtendedOrnsteinUhlenbeckProcess> |
48 | 0 | ExtOUWithJumpsProcess::getExtendedOrnsteinUhlenbeckProcess() const { |
49 | 0 | return ouProcess_; |
50 | 0 | } |
51 | 0 | Real ExtOUWithJumpsProcess::beta() const { |
52 | 0 | return beta_; |
53 | 0 | } |
54 | 0 | Real ExtOUWithJumpsProcess::jumpIntensity() const { |
55 | 0 | return jumpIntensity_; |
56 | 0 | } |
57 | 0 | Real ExtOUWithJumpsProcess::eta() const { |
58 | 0 | return eta_; |
59 | 0 | } |
60 | | |
61 | 0 | Array ExtOUWithJumpsProcess::initialValues() const { |
62 | 0 | return { |
63 | 0 | ouProcess_->x0(), |
64 | 0 | Y0_ |
65 | 0 | }; |
66 | 0 | } |
67 | | |
68 | 0 | Array ExtOUWithJumpsProcess::drift(Time t, const Array& x) const { |
69 | 0 | return { |
70 | 0 | ouProcess_->drift(t, x[0]), |
71 | 0 | -beta_*x[1] |
72 | 0 | }; |
73 | 0 | } |
74 | | |
75 | 0 | Matrix ExtOUWithJumpsProcess::diffusion(Time t, const Array& x) const { |
76 | 0 | Matrix retVal(2, 2, 0.0); |
77 | 0 | retVal[0][0] = ouProcess_->diffusion(t, x[0]); |
78 | | |
79 | 0 | return retVal; |
80 | 0 | } |
81 | | |
82 | | Array ExtOUWithJumpsProcess::evolve( |
83 | 0 | Time t0, const Array& x0, Time dt, const Array& dw) const { |
84 | | |
85 | 0 | Array retVal(2); |
86 | 0 | retVal[0] = ouProcess_->evolve(t0, x0[0], dt, dw[0]); |
87 | 0 | retVal[1] = x0[1]*std::exp(-beta_*dt); |
88 | | |
89 | 0 | const Real u1 = std::max(QL_EPSILON, std::min(cumNormalDist_(dw[1]), |
90 | 0 | 1.0-QL_EPSILON)); |
91 | |
|
92 | 0 | const Time interarrival = -1.0/jumpIntensity_*std::log(u1); |
93 | 0 | if (interarrival < dt) { |
94 | 0 | const Real u2 = std::max(QL_EPSILON, std::min(cumNormalDist_(dw[2]), |
95 | 0 | 1.0-QL_EPSILON)); |
96 | 0 | const Real jumpSize = -1.0/eta_*std::log(u2); |
97 | 0 | retVal[1] += jumpSize; |
98 | 0 | } |
99 | 0 | return retVal; |
100 | 0 | } |
101 | | } |