QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdmzabrop.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2014 Peter Caspers
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#include <ql/experimental/finitedifferences/fdmzabrop.hpp>
21#include <ql/methods/finitedifferences/operators/secondderivativeop.hpp>
22#include <ql/methods/finitedifferences/operators/secondordermixedderivativeop.hpp>
23
24namespace QuantLib {
25
27 const ext::shared_ptr<FdmMesher> &mesher, const Real beta, const Real nu,
28 const Real rho, const Real gamma)
29 : volatilityValues_(mesher->locations(1)),
30 forwardValues_(mesher->locations(0)),
31 mapT_(SecondDerivativeOp(0, mesher)
32 .mult(0.5 * volatilityValues_ * volatilityValues_ *
33 Pow(forwardValues_, 2.0 * beta))),
34 mesher_(mesher) {}
35
37
39 return mapT_;
40}
41
43 const ext::shared_ptr<FdmMesher> &mesher, const Real beta, const Real nu,
44 const Real rho, const Real gamma)
45 : volatilityValues_(mesher->locations(1)),
46 forwardValues_(mesher->locations(0)),
47 mapT_(SecondDerivativeOp(1, mesher).mult(
48 0.5 * nu * nu * Pow(volatilityValues_, 2.0 * gamma))),
49 mesher_(mesher) {}
50
52
54 return mapT_;
55}
56
57FdmZabrOp::FdmZabrOp(const ext::shared_ptr<FdmMesher> &mesher,
58 const Real beta, const Real nu, const Real rho,
59 const Real gamma)
60 : volatilityValues_(mesher->locations(1)),
61 forwardValues_(mesher->locations(0)),
62 dxyMap_(SecondOrderMixedDerivativeOp(0, 1, mesher)
63 .mult(nu * rho * Pow(Abs(volatilityValues_), gamma + 1.0) *
64 Pow(forwardValues_, beta))),
65 dxMap_(FdmZabrUnderlyingPart(mesher, beta, nu, rho, gamma)),
66 dyMap_(FdmZabrVolatilityPart(mesher, beta, nu, rho, gamma)) {}
67
69 dxMap_.setTime(t1, t2);
70 dyMap_.setTime(t1, t2);
71}
72
73Size FdmZabrOp::size() const { return 2; }
74
75Array FdmZabrOp::apply(const Array &u) const {
76 return dyMap_.getMap().apply(u) + dxMap_.getMap().apply(u) +
77 dxyMap_.apply(u);
78}
79
81 const Array &r) const {
82 if (direction == 0)
83 return dxMap_.getMap().apply(r);
84 else if (direction == 1)
85 return dyMap_.getMap().apply(r);
86 else
87 QL_FAIL("direction too large");
88}
89
91 return dxyMap_.apply(r);
92}
93
95 Real a) const {
96
97 if (direction == 0) {
98 return dxMap_.getMap().solve_splitting(r, a, 1.0);
99 } else if (direction == 1) {
100 return dyMap_.getMap().solve_splitting(r, a, 1.0);
101 } else
102 QL_FAIL("direction too large");
103}
104
106 return solve_splitting(0, r, dt);
107}
108
109std::vector<SparseMatrix> FdmZabrOp::toMatrixDecomp() const {
110 return {
114 };
115}
116
117}
1-D array used in linear algebra.
Definition: array.hpp:52
FdmZabrVolatilityPart dyMap_
Definition: fdmzabrop.hpp:92
Size size() const override
Definition: fdmzabrop.cpp:73
Array apply_direction(Size direction, const Array &r) const override
Definition: fdmzabrop.cpp:80
Array preconditioner(const Array &r, Real s) const override
Definition: fdmzabrop.cpp:105
std::vector< SparseMatrix > toMatrixDecomp() const override
Definition: fdmzabrop.cpp:109
void setTime(Time t1, Time t2) override
Time is required.
Definition: fdmzabrop.cpp:68
FdmZabrOp(const ext::shared_ptr< FdmMesher > &mesher, Real beta, Real nu, Real rho, Real gamma=1.0)
Definition: fdmzabrop.cpp:57
Array apply_mixed(const Array &r) const override
Definition: fdmzabrop.cpp:90
Array solve_splitting(Size direction, const Array &r, Real s) const override
Definition: fdmzabrop.cpp:94
NinePointLinearOp dxyMap_
Definition: fdmzabrop.hpp:90
Array apply(const Array &r) const override
Definition: fdmzabrop.cpp:75
FdmZabrUnderlyingPart dxMap_
Definition: fdmzabrop.hpp:91
void setTime(Time t1, Time t2)
Definition: fdmzabrop.cpp:36
const TripleBandLinearOp & getMap() const
Definition: fdmzabrop.cpp:38
FdmZabrUnderlyingPart(const ext::shared_ptr< FdmMesher > &mesher, Real beta, Real nu, Real rho, Real gamma)
Definition: fdmzabrop.cpp:26
TripleBandLinearOp mapT_
Definition: fdmzabrop.hpp:46
void setTime(Time t1, Time t2)
Definition: fdmzabrop.cpp:51
FdmZabrVolatilityPart(const ext::shared_ptr< FdmMesher > &mesher, Real beta, Real nu, Real rho, Real gamma)
Definition: fdmzabrop.cpp:42
const TripleBandLinearOp & getMap() const
Definition: fdmzabrop.cpp:53
TripleBandLinearOp mapT_
Definition: fdmzabrop.hpp:62
SparseMatrix toMatrix() const override
Array apply(const Array &r) const override
SparseMatrix toMatrix() const override
Array solve_splitting(const Array &r, Real a, Real b=1.0) const
Array apply(const Array &r) const override
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
Array Pow(const Array &v, Real alpha)
Definition: array.hpp:889
Array Abs(const Array &v)
Definition: array.hpp:833