QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
transformedgrid.hpp
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
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
34
38 public:
41 dxm_(grid.size()), dxp_(grid.size()),
42 dx_(grid.size()){
43 for (Size i=1; i < transformedGrid_.size() -1 ; 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) :
58 dxm_(grid.size()), dxp_(grid.size()),
59 dx_(grid.size()){
60 std::transform(grid_.begin(),
61 grid_.end(),
63 func);
64 for (Size i=1; i < transformedGrid_.size() -1 ; 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_;}
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];}
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 class LogGrid : public TransformedGrid {
97 public:
98 LogGrid(const Array &grid) :
99 TransformedGrid(grid, [](Real x) -> Real { return std::log(x); }){};
100 const Array & logGridArray() const { return transformedGridArray();}
101 Real logGrid(Size i) const { return transformedGrid(i);}
102 };
103
104}
105
106
107#endif
1-D array used in linear algebra.
Definition: array.hpp:52
const_iterator end() const
Definition: array.hpp:511
Size size() const
dimension of the array
Definition: array.hpp:495
const_iterator begin() const
Definition: array.hpp:503
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:35
STL namespace.