Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
fdmdefaultableequityjumpdiffusionfokkerplanckop.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
20
21#include <ql/methods/finitedifferences/meshers/fdmmesher.hpp>
22#include <ql/methods/finitedifferences/operators/secondderivativeop.hpp>
23
24namespace QuantExt {
25
26using namespace QuantLib;
27
29 const Real T, const QuantLib::ext::shared_ptr<QuantLib::FdmMesher>& mesher,
30 const QuantLib::ext::shared_ptr<const DefaultableEquityJumpDiffusionModel>& model, const Size direction)
31 : T_(T), mesher_(mesher), model_(model), direction_(direction), dxMap_(FirstDerivativeOp(direction, mesher)),
32 dxxMap_(SecondDerivativeOp(direction, mesher)), mapT_(direction, mesher), y_(mesher_->locations(direction_)) {}
33
35
37
38 Size n = mesher_->locations(direction_).size();
39
40 Real r = model_->r(T_ - t1);
41 Real q = model_->q(T_ - t1);
42 Real v = model_->sigma(T_ - t1) * model_->sigma(T_ - t1);
43
44 Array h = Array(n);
45 for (Size i = 0; i < h.size(); ++i) {
46 Real S = std::exp(y_[i]);
47 h[i] = model_->h(T_ - t1, S);
48 }
49
50 mapT_.axpyb(-(Array(n, r - q - 0.5 * v) + model_->eta() * h), dxMap_, dxxMap_.mult(Array(n, 0.5 * v)),
51 -(Array(n, r) + h * (1.0 - model_->p())));
52}
53
55 return mapT_.apply(r);
56}
57
59 Array retVal(r.size(), 0.0);
60 return retVal;
61}
62
64 const Array& r) const {
65 if (direction == direction_)
66 return mapT_.apply(r);
67 else {
68 Array retVal(r.size(), 0.0);
69 return retVal;
70 }
71}
72
74 Real s) const {
75 if (direction == direction_)
76 return mapT_.solve_splitting(r, s, 1.0);
77 else {
78 Array retVal(r);
79 return retVal;
80 }
81}
82
84 return solve_splitting(direction_, r, s);
85}
86
87#if !defined(QL_NO_UBLAS_SUPPORT)
88std::vector<QuantLib::SparseMatrix>
90 std::vector<SparseMatrix> retVal(1, mapT_.toMatrix());
91 return retVal;
92}
93#endif
94
95} // namespace QuantExt
QuantLib::ext::shared_ptr< const DefaultableEquityJumpDiffusionModel > model_
FdmDefaultableEquityJumpDiffusionFokkerPlanckOp(const Real T, const QuantLib::ext::shared_ptr< QuantLib::FdmMesher > &mesher, const QuantLib::ext::shared_ptr< const DefaultableEquityJumpDiffusionModel > &model, const Size direction=0)
this op is implemented in terms of time to maturity T, so that we can use a backward solver to evolve
Array solve_splitting(Size direction, const Array &r, Real s) const override