QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdmklugeextouop.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
25#include <ql/quotes/simplequote.hpp>
26#include <ql/termstructures/yieldtermstructure.hpp>
27#include <ql/termstructures/yield/flatforward.hpp>
28#include <ql/methods/finitedifferences/meshers/fdmmesher.hpp>
29#include <ql/experimental/processes/klugeextouprocess.hpp>
30#include <ql/experimental/processes/extouwithjumpsprocess.hpp>
31#include <ql/experimental/processes/extendedornsteinuhlenbeckprocess.hpp>
32#include <ql/experimental/finitedifferences/fdmextoujumpop.hpp>
33#include <ql/experimental/finitedifferences/fdmklugeextouop.hpp>
34#include <ql/methods/finitedifferences/operators/fdmlinearoplayout.hpp>
35#include <ql/experimental/finitedifferences/fdmextendedornsteinuhlenbeckop.hpp>
36#include <ql/methods/finitedifferences/operators/secondordermixedderivativeop.hpp>
37
38namespace QuantLib {
39
41 const ext::shared_ptr<FdmMesher>& mesher,
42 const ext::shared_ptr<KlugeExtOUProcess>& klugeOUProcess,
43 const ext::shared_ptr<YieldTermStructure>& rTS,
44 const FdmBoundaryConditionSet& bcSet,
45 Size integroIntegrationOrder)
46 : mesher_ (mesher),
47 kluge_ (klugeOUProcess->getKlugeProcess()),
48 extOU_ (klugeOUProcess->getExtOUProcess()),
49 rTS_ (rTS),
50 bcSet_ (bcSet),
51 klugeOp_(new FdmExtOUJumpOp(mesher, kluge_, rTS, bcSet,
52 integroIntegrationOrder)),
54 mesher, extOU_,
55 ext::shared_ptr<YieldTermStructure>(
56 new FlatForward(rTS->referenceDate(),
57 Handle<Quote>(ext::shared_ptr<Quote>(
58 new SimpleQuote(0.0))),
59 rTS->dayCounter())),
60 bcSet, 2)),
61 corrMap_(SecondOrderMixedDerivativeOp(0, 2, mesher).mult(
62 Array(mesher->layout()->size(),
63 klugeOUProcess->rho()*extOU_->volatility()
64 *kluge_->getExtendedOrnsteinUhlenbeckProcess()
65 ->volatility())))
66 { }
67
69 return mesher_->layout()->dim().size();
70 }
71
73 ouOp_->setTime(t1, t2);
74 klugeOp_->setTime(t1, t2);
75 }
76
78 return ouOp_->apply(r) + klugeOp_->apply(r) + corrMap_.apply(r);
79 }
80
82 return corrMap_.apply(r) + klugeOp_->apply_mixed(r);
83 }
84
86 const Array& r) const {
87 return klugeOp_->apply_direction(direction, r)
88 + ouOp_->apply_direction(direction, r);
89 }
90
92 const Array& r, Real a) const {
93 if (direction == 0 || direction == 1) {
94 return klugeOp_->solve_splitting(direction, r, a);
95 }
96 else if (direction == 2) {
97 return ouOp_->solve_splitting(direction, r, a);
98 }
99 else {
100 Array retVal(r);
101 return retVal;
102 }
103 }
104
106 return klugeOp_->solve_splitting(0, r, dt);
107 }
108
109 std::vector<SparseMatrix> FdmKlugeExtOUOp::toMatrixDecomp() const {
110 const std::vector<SparseMatrix> klugeDecomp = klugeOp_->toMatrixDecomp();
111
112 return {
113 klugeDecomp[0],
114 klugeDecomp[1],
115 ouOp_->toMatrixDecomp().front(),
116 corrMap_.toMatrix() + klugeDecomp[2]
117 };
118 }
119
120}
1-D array used in linear algebra.
Definition: array.hpp:52
const ext::shared_ptr< FdmExtOUJumpOp > klugeOp_
FdmKlugeExtOUOp(const ext::shared_ptr< FdmMesher > &mesher, const ext::shared_ptr< KlugeExtOUProcess > &klugeOUProcess, const ext::shared_ptr< YieldTermStructure > &rTS, const FdmBoundaryConditionSet &bcSet, Size integroIntegrationOrder)
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
void setTime(Time t1, Time t2) override
Time is required.
Array apply_mixed(const Array &r) const override
const ext::shared_ptr< FdmMesher > mesher_
Array solve_splitting(Size direction, const Array &r, Real s) const override
const NinePointLinearOp corrMap_
Array apply(const Array &r) const override
const ext::shared_ptr< FdmExtendedOrnsteinUhlenbeckOp > ouOp_
Flat interest-rate curve.
Definition: flatforward.hpp:37
Shared handle to an observable.
Definition: handle.hpp:41
SparseMatrix toMatrix() const override
Array apply(const Array &r) const override
purely virtual base class for market observables
Definition: quote.hpp:37
market element returning a stored value
Definition: simplequote.hpp:33
Interest-rate term structure.
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
OperatorTraits< FdmLinearOp >::bc_set FdmBoundaryConditionSet