QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
pde.hpp
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) 2005 Joseph Wang
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 pde.hpp
21 \brief General class for one dimensional PDE's
22*/
23
24#ifndef quantlib_pde_hpp
25#define quantlib_pde_hpp
26
27#include <ql/math/array.hpp>
30#include <utility>
31
32namespace QuantLib {
33
34 /*! \deprecated Part of the old FD framework; copy this function
35 in your codebase if needed.
36 Deprecated in version 1.37.
37 */
38 class [[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]] PdeSecondOrderParabolic {
39 public:
40 virtual ~PdeSecondOrderParabolic() = default;
41 virtual Real diffusion(Time t, Real x) const = 0;
42 virtual Real drift(Time t, Real x) const = 0;
43 virtual Real discount(Time t, Real x) const = 0;
45 virtual void
47 for (Size i = 1; i < tg.size() - 1; i++) {
48 Real sigma = diffusion(t, tg.grid(i));
49 Real nu = drift(t, tg.grid(i));
50 Real r = discount(t, tg.grid(i));
51 Real sigma2 = sigma * sigma;
52
53 Real pd = -(sigma2 / tg.dxm(i) - nu) / tg.dx(i);
54 Real pu = -(sigma2 / tg.dxp(i) + nu) / tg.dx(i);
55 Real pm = sigma2 / (tg.dxm(i) * tg.dxp(i)) + r;
56 L.setMidRow(i, pd, pm, pu);
57 }
58 }
59 };
60
61 /*! \deprecated Part of the old FD framework; copy this function
62 in your codebase if needed.
63 Deprecated in version 1.37.
64 */
65 template <class PdeClass>
66 class [[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]] PdeConstantCoeff : public PdeSecondOrderParabolic {
67 public:
68 PdeConstantCoeff(const typename PdeClass::argument_type &process,
69 Time t, Real x) {
70 PdeClass pde(process);
71 diffusion_ = pde.diffusion(t, x);
72 drift_ = pde.drift(t, x);
73 discount_ = pde.discount(t, x);
74 }
75 Real diffusion(Time, Real) const override { return diffusion_; }
76 Real drift(Time, Real) const override { return drift_; }
77 Real discount(Time, Real) const override { return discount_; }
78
79 private:
83 };
84
86
87 /*! \deprecated Part of the old FD framework; copy this function
88 in your codebase if needed.
89 Deprecated in version 1.37.
90 */
91 template <class PdeClass>
92 class [[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]] GenericTimeSetter:public TridiagonalOperator::TimeSetter {
93 public:
94 template <class T>
95 GenericTimeSetter(const Array &grid, T process) :
96 grid_(grid), pde_(std::move(process)) {}
97 void setTime(Time t, TridiagonalOperator& L) const override {
98 pde_.generateOperator(t, grid_, L);
99 }
100
101 private:
102 typename PdeClass::grid_type grid_;
103 PdeClass pde_;
104 };
105
106 /*! \deprecated Part of the old FD framework; copy this function
107 in your codebase if needed.
108 Deprecated in version 1.37.
109 */
110 template <class PdeClass>
111 class [[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]] PdeOperator:public TridiagonalOperator {
112 public:
113 template <class T>
114 PdeOperator(const Array& grid,
115 T process,
116 Time residualTime = 0.0) :
117 TridiagonalOperator(grid.size()) {
119 timeSetter_ =
120 ext::shared_ptr<GenericTimeSetter<PdeClass> >(
121 new GenericTimeSetter<PdeClass>(grid, std::move(process)));
123 setTime(residualTime);
124 }
125 };
126}
127
128
129#endif
1-D array used in linear algebra.
1-D array used in linear algebra.
Definition: array.hpp:52
PdeClass::grid_type grid_
Definition: pde.hpp:102
GenericTimeSetter(const Array &grid, T process)
Definition: pde.hpp:95
void setTime(Time t, TridiagonalOperator &L) const override
Definition: pde.hpp:97
Real drift(Time, Real) const override
Definition: pde.hpp:76
Real diffusion(Time, Real) const override
Definition: pde.hpp:75
PdeConstantCoeff(const typename PdeClass::argument_type &process, Time t, Real x)
Definition: pde.hpp:68
Real discount(Time, Real) const override
Definition: pde.hpp:77
PdeOperator(const Array &grid, T process, Time residualTime=0.0)
Definition: pde.hpp:114
virtual QL_DEPRECATED_DISABLE_WARNING void generateOperator(Time t, const TransformedGrid &tg, TridiagonalOperator &L) const
Definition: pde.hpp:46
virtual Real discount(Time t, Real x) const =0
virtual Real drift(Time t, Real x) const =0
virtual ~PdeSecondOrderParabolic()=default
virtual Real diffusion(Time t, Real x) const =0
encapsulation of time-setting logic
Base implementation for tridiagonal operator.
void setMidRow(Size, Real, Real, Real)
const DefaultType & t
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
Real sigma
Rate drift_
Definition: any.hpp:37
STL namespace.
ext::shared_ptr< YieldTermStructure > r
#define QL_DEPRECATED_DISABLE_WARNING
Definition: qldefines.hpp:216
#define QL_DEPRECATED_ENABLE_WARNING
Definition: qldefines.hpp:217
Real nu
Definition: sabr.cpp:200
encapuslates a grid
tridiagonal operator