QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
transformedgrid.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 transformedgrid.hpp
21 \brief encapuslates a grid
22*/
23
24#ifndef quantlib_transformed_grid_hpp
25#define quantlib_transformed_grid_hpp
26
27#include <ql/math/array.hpp>
28#include <functional>
29#include <numeric>
30
31namespace QuantLib {
32
33 /*! \deprecated Part of the old FD framework; copy this function
34 in your codebase if needed.
35 Deprecated in version 1.37.
36 */
37 class [[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]] TransformedGrid {
38 public:
39 TransformedGrid (const Array &grid) :
40 grid_(grid), transformedGrid_(grid),
41 dxm_(grid.size()), dxp_(grid.size()),
42 dx_(grid.size()){
43 for (Size i=1; i < transformedGrid_.size() -1 ; i++) {
44 dxm_[i] = transformedGrid_[i] - transformedGrid_[i-1];
45 dxp_[i] = transformedGrid_[i+1] - transformedGrid_[i];
46 dx_[i] = dxm_[i] + dxp_[i];
47 }
48 }
49
50#if defined(__GNUC__) && (__GNUC__ >= 7)
51#pragma GCC diagnostic push
52#pragma GCC diagnostic ignored "-Wnoexcept-type"
53#endif
54
55 template <class T>
56 TransformedGrid (const Array &grid, T func) :
57 grid_(grid), transformedGrid_(grid.size()),
58 dxm_(grid.size()), dxp_(grid.size()),
59 dx_(grid.size()){
60 std::transform(grid_.begin(),
61 grid_.end(),
62 transformedGrid_.begin(),
63 func);
64 for (Size i=1; i < transformedGrid_.size() -1 ; i++) {
65 dxm_[i] = transformedGrid_[i] - transformedGrid_[i-1];
66 dxp_[i] = transformedGrid_[i+1] - transformedGrid_[i];
67 dx_[i] = dxm_[i] + dxp_[i];
68 }
69 }
70
71#if defined(__GNUC__) && (__GNUC__ >= 7)
72#pragma GCC diagnostic pop
73#endif
74
75 const Array &gridArray() const { return grid_;}
76 const Array &transformedGridArray() const { return transformedGrid_;}
77 const Array &dxmArray() const { return dxm_;}
78 const Array &dxpArray() const { return dxp_;}
79 const Array &dxArray() const { return dx_;}
80
81 Real grid(Size i) const { return grid_[i];}
82 Real transformedGrid(Size i) const { return transformedGrid_[i];}
83 Real dxm(Size i) const { return dxm_[i];}
84 Real dxp(Size i) const { return dxp_[i];}
85 Real dx(Size i) const { return dx_[i];}
86 Size size() const {return grid_.size();}
87
88 protected:
94 };
95
96
98
99 /*! \deprecated Part of the old FD framework; copy this function
100 in your codebase if needed.
101 Deprecated in version 1.37.
102 */
103 class [[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]] LogGrid : public TransformedGrid {
104 public:
105 LogGrid(const Array &grid) :
106 TransformedGrid(grid, [](Real x) -> Real { return std::log(x); }){};
107 const Array & logGridArray() const { return transformedGridArray();}
108 Real logGrid(Size i) const { return transformedGrid(i);}
109 };
110
112
113}
114
115
116#endif
1-D array used in linear algebra.
1-D array used in linear algebra.
Definition: array.hpp:52
LogGrid(const Array &grid)
Real logGrid(Size i) const
const Array & logGridArray() const
TransformedGrid(const Array &grid)
const Array & transformedGridArray() const
const Array & dxmArray() const
TransformedGrid(const Array &grid, T func)
const Array & gridArray() const
Real transformedGrid(Size i) const
const Array & dxpArray() const
const Array & dxArray() const
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:37
STL namespace.
#define QL_DEPRECATED_DISABLE_WARNING
Definition: qldefines.hpp:216
#define QL_DEPRECATED_ENABLE_WARNING
Definition: qldefines.hpp:217