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
28namespace QuantLib {
29
30 ExtOUWithJumpsProcess::ExtOUWithJumpsProcess(
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
41 Size ExtOUWithJumpsProcess::size() const {
42 return 2;
43 }
44 Size ExtOUWithJumpsProcess::factors() const {
45 return 3;
46 }
47 ext::shared_ptr<ExtendedOrnsteinUhlenbeckProcess>
48 ExtOUWithJumpsProcess::getExtendedOrnsteinUhlenbeckProcess() const {
49 return ouProcess_;
50 }
51 Real ExtOUWithJumpsProcess::beta() const {
52 return beta_;
53 }
54 Real ExtOUWithJumpsProcess::jumpIntensity() const {
55 return jumpIntensity_;
56 }
57 Real ExtOUWithJumpsProcess::eta() const {
58 return eta_;
59 }
60
61 Array ExtOUWithJumpsProcess::initialValues() const {
62 return {
63 ouProcess_->x0(),
64 Y0_
65 };
66 }
67
68 Array ExtOUWithJumpsProcess::drift(Time t, const Array& x) const {
69 return {
70 ouProcess_->drift(t, x: x[0]),
71 -beta_*x[1]
72 };
73 }
74
75 Matrix ExtOUWithJumpsProcess::diffusion(Time t, const Array& x) const {
76 Matrix retVal(2, 2, 0.0);
77 retVal[0][0] = ouProcess_->diffusion(t, x: x[0]);
78
79 return retVal;
80 }
81
82 Array ExtOUWithJumpsProcess::evolve(
83 Time t0, const Array& x0, Time dt, const Array& dw) const {
84
85 Array retVal(2);
86 retVal[0] = ouProcess_->evolve(t0, x0: x0[0], dt, dw: dw[0]);
87 retVal[1] = x0[1]*std::exp(x: -beta_*dt);
88
89 const Real u1 = std::max(QL_EPSILON, b: std::min(a: cumNormalDist_(dw[1]),
90 b: 1.0-QL_EPSILON));
91
92 const Time interarrival = -1.0/jumpIntensity_*std::log(x: u1);
93 if (interarrival < dt) {
94 const Real u2 = std::max(QL_EPSILON, b: std::min(a: cumNormalDist_(dw[2]),
95 b: 1.0-QL_EPSILON));
96 const Real jumpSize = -1.0/eta_*std::log(x: u2);
97 retVal[1] += jumpSize;
98 }
99 return retVal;
100 }
101}
102

source code of quantlib/ql/experimental/processes/extouwithjumpsprocess.cpp