QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fdmextoujumpop.cpp
Go to the documentation of this file.
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 fdmexpoujumpop.cpp
21 \brief Ornstein Uhlenbeck process plus jumps (Kluge Model)
22*/
23
33
34#if defined(QL_PATCH_MSVC)
35#pragma warning(push)
36#pragma warning(disable:4180)
37#endif
38
39#include <boost/numeric/ublas/vector.hpp>
40#include <boost/numeric/ublas/operation.hpp>
41
42#if defined(QL_PATCH_MSVC)
43#pragma warning(pop)
44#endif
45
46namespace QuantLib {
47
49 const ext::shared_ptr<FdmMesher>& mesher,
50 const ext::shared_ptr<ExtOUWithJumpsProcess>& process,
51 const ext::shared_ptr<YieldTermStructure>& rTS,
52 const FdmBoundaryConditionSet& bcSet,
53 Size integroIntegrationOrder)
54 : mesher_ (mesher),
55 process_(process),
56 rTS_ (rTS),
57 bcSet_ (bcSet),
58 gaussLaguerreIntegration_(integroIntegrationOrder),
59 x_ (mesher->locations(0)),
61 mesher,
62 process->getExtendedOrnsteinUhlenbeckProcess(), rTS, bcSet)),
63 dyMap_ (FirstDerivativeOp(1, mesher)
64 .mult(-process->beta()*mesher->locations(1)))
65 {
66 const Real eta = process_->eta();
67 const Real lambda = process_->jumpIntensity();
68
69 const Array yInt = gaussLaguerreIntegration_.x();
71
72 integroPart_ = SparseMatrix(mesher_->layout()->size(),
73 mesher_->layout()->size());
74
75 Array yLoc(mesher_->layout()->dim()[1]);
76 for (const auto& iter : *mesher_->layout()) {
77 yLoc[iter.coordinates()[1]] = mesher_->location(iter, 1);
78 }
79
80 for (const auto& iter : *mesher_->layout()) {
81 const Size diag = iter.index();
82 integroPart_(diag, diag) -= lambda;
83
84 const Real y = mesher_->location(iter, 1);
85 const Integer yIndex = iter.coordinates()[1];
86
87 for (Size i=0; i < yInt.size(); ++i) {
88 const Real weight = std::exp(-yInt[i])*weights[i];
89
90 const Real ys = y + yInt[i]/eta;
91 const Integer l = (ys > yLoc.back()) ? yLoc.size()-2
92 : std::upper_bound(yLoc.begin(),
93 yLoc.end()-1, ys) - yLoc.begin()-1;
94
95 const Real s = (ys-yLoc[l])/(yLoc[l+1]-yLoc[l]);
96 integroPart_(diag, mesher_->layout()->neighbourhood(iter, 1, l-yIndex))
97 += weight*lambda*(1-s);
98 integroPart_(diag, mesher_->layout()->neighbourhood(iter, 1, l+1-yIndex))
99 += weight*lambda*s;
100 }
101 }
102 }
103
105 return mesher_->layout()->dim().size();;
106 }
107
109 ouOp_->setTime(t1, t2);
110 }
111
113 return ouOp_->apply(r) + dyMap_.apply(r) + integro(r);
114 }
115
117 return integro(r);
118 }
119
121 const Array& r) const {
122 if (direction == 0)
123 return ouOp_->apply_direction(direction, r);
124 else if (direction == 1)
125 return dyMap_.apply(r);
126 else {
127 return Array(r.size(), 0.0);
128 }
129 }
130
132 const Array& r, Real a) const {
133 if (direction == 0) {
134 return ouOp_->solve_splitting(direction, r, a);
135 }
136 else if (direction == 1) {
137 return dyMap_.solve_splitting(r, a, 1.0);
138 }
139 else {
140 return r;
141 }
142 }
143
145 return ouOp_->solve_splitting(0, r, dt);
146 }
147
149 return prod(integroPart_, r);
150 }
151
152 std::vector<SparseMatrix> FdmExtOUJumpOp::toMatrixDecomp() const {
153 QL_REQUIRE(bcSet_.empty(), "boundary conditions are not supported");
154
155 std::vector<SparseMatrix> retVal(1, ouOp_->toMatrixDecomp().front());
156 retVal.push_back(dyMap_.toMatrix());
157 retVal.push_back(integroPart_);
158
159 return retVal;
160 }
161
162}
1-D array used in linear algebra.
Definition: array.hpp:52
const_iterator end() const
Definition: array.hpp:511
Real back() const
Definition: array.hpp:458
Size size() const
dimension of the array
Definition: array.hpp:495
const_iterator begin() const
Definition: array.hpp:503
GaussLaguerreIntegration gaussLaguerreIntegration_
Size size() const override
Array apply_direction(Size direction, const Array &r) const override
Array preconditioner(const Array &r, Real s) const override
std::vector< SparseMatrix > toMatrixDecomp() const override
const TripleBandLinearOp dyMap_
void setTime(Time t1, Time t2) override
Time is required.
const FdmBoundaryConditionSet bcSet_
Array apply_mixed(const Array &r) const override
Array integro(const Array &r) const
FdmExtOUJumpOp(const ext::shared_ptr< FdmMesher > &mesher, const ext::shared_ptr< ExtOUWithJumpsProcess > &process, const ext::shared_ptr< YieldTermStructure > &rTS, const FdmBoundaryConditionSet &bcSet, Size integroIntegrationOrder)
const ext::shared_ptr< ExtOUWithJumpsProcess > process_
const ext::shared_ptr< FdmMesher > mesher_
Array solve_splitting(Size direction, const Array &r, Real s) const override
Array apply(const Array &r) const override
const ext::shared_ptr< FdmExtendedOrnsteinUhlenbeckOp > ouOp_
SparseMatrix toMatrix() const override
Array solve_splitting(const Array &r, Real a, Real b=1.0) const
Array apply(const Array &r) const override
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
extended Ornstein-Uhlenbeck process
Ornstein Uhlenbeck process plus exp jumps (Kluge Model)
const ext::shared_ptr< YieldTermStructure > rTS_
Ornstein Uhlenbeck process plus jumps (Kluge Model)
Ornstein Uhlenbeck process plus jumps (Kluge Model)
memory layout of a fdm linear operator
mesher for a fdm grid
const ext::shared_ptr< FdmMesher > mesher_
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
QL_INTEGER Integer
integer number
Definition: types.hpp:35
std::size_t Size
size of a container
Definition: types.hpp:58
linear interpolation between discrete points
Definition: any.hpp:35
Array prod(const SparseMatrix &A, const Array &x)
boost::numeric::ublas::compressed_matrix< Real > SparseMatrix
OperatorTraits< FdmLinearOp >::bc_set FdmBoundaryConditionSet
ext::shared_ptr< YieldTermStructure > r
Real beta
Definition: sabr.cpp:200
second derivative operator
std::uint64_t x_
Interest-rate term structure.