QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fdmcevop.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) 2018 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 fdmcevop.cpp */
21
28
29
30namespace QuantLib {
31
33 const ext::shared_ptr<FdmMesher>& mesher,
34 const ext::shared_ptr<YieldTermStructure>& rTS,
35 Real f0, Real alpha, Real beta,
36 Size direction)
37 : rTS_(rTS),
38 direction_(direction),
39 dxxMap_(SecondDerivativeOp(0, mesher)
40 .mult(0.5 * alpha * alpha *
41 Pow(mesher->locations(direction), 2.0 * beta))),
42 mapT_(direction, mesher) {
43 }
44
45 Size FdmCEVOp::size() const { return 1U; }
46
48 const Rate r = rTS_->forwardRate(t1, t2, Continuous).rate();
50 }
51
52 Array FdmCEVOp::apply(const Array& r) const {
53 return mapT_.apply(r);
54 }
55
57 return Array(r.size(), 0.0);
58 }
59
60 Array FdmCEVOp::apply_direction(Size direction, const Array& r) const {
61 if (direction == direction_) {
62 return mapT_.apply(r);
63 }
64 else {
65 return Array(r.size(), 0.0);
66 }
67 }
68
69 Array FdmCEVOp::solve_splitting(Size direction, const Array& r, Real a) const {
70 if (direction == direction_) {
71 return mapT_.solve_splitting(r, a, 1.0);
72 }
73 else {
74 return Array(r.size(), 0.0);
75 }
76 }
77
79 return solve_splitting(direction_, r, dt);
80 }
81
82 std::vector<SparseMatrix> FdmCEVOp::toMatrixDecomp() const {
83 return std::vector<SparseMatrix>(1, mapT_.toMatrix());
84 }
85
86}
87
1-D array used in linear algebra.
Definition: array.hpp:52
FdmCEVOp(const ext::shared_ptr< FdmMesher > &mesher, const ext::shared_ptr< YieldTermStructure > &rTS, Real f0, Real alpha, Real beta, Size direction)
Definition: fdmcevop.cpp:32
Size size() const override
Definition: fdmcevop.cpp:45
Array apply_direction(Size direction, const Array &r) const override
Definition: fdmcevop.cpp:60
Array preconditioner(const Array &r, Real s) const override
Definition: fdmcevop.cpp:78
std::vector< SparseMatrix > toMatrixDecomp() const override
Definition: fdmcevop.cpp:82
const TripleBandLinearOp dxxMap_
Definition: fdmcevop.hpp:65
void setTime(Time t1, Time t2) override
Time is required.
Definition: fdmcevop.cpp:47
Array apply_mixed(const Array &r) const override
Definition: fdmcevop.cpp:56
TripleBandLinearOp mapT_
Definition: fdmcevop.hpp:66
const ext::shared_ptr< YieldTermStructure > & rTS_
Definition: fdmcevop.hpp:63
Array solve_splitting(Size direction, const Array &r, Real s) const override
Definition: fdmcevop.cpp:69
const Size direction_
Definition: fdmcevop.hpp:64
Array apply(const Array &r) const override
Definition: fdmcevop.cpp:52
SparseMatrix toMatrix() const override
Array solve_splitting(const Array &r, Real a, Real b=1.0) const
void axpyb(const Array &a, const TripleBandLinearOp &x, const TripleBandLinearOp &y, const Array &b)
Array apply(const Array &r) const override
FDM operator for the Constant Elasticity of Variance (CEV) model.
const ext::shared_ptr< YieldTermStructure > rTS_
memory layout of a fdm linear operator
mesher for a fdm grid
const Size direction_
first derivative linear operator
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real Rate
interest rates
Definition: types.hpp:70
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
ext::shared_ptr< YieldTermStructure > r
Real beta
Definition: sabr.cpp:200
Real alpha
Definition: sabr.cpp:200
second derivative operator
Interest-rate term structure.