QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
grid.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) 2001, 2002, 2003 Sadruddin Rejeb
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 grid.hpp
21 \brief Grid constructors
22*/
23
24#ifndef quantlib_grid_hpp
25#define quantlib_grid_hpp
26
27#include <ql/math/array.hpp>
28
29namespace QuantLib {
30
31 /*! \deprecated Part of the old FD framework; copy this function
32 in your codebase if needed.
33 Deprecated in version 1.37.
34 */
35 [[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]]
36 Array CenteredGrid(Real center, Real dx, Size steps);
37
38 /*! \deprecated Part of the old FD framework; copy this function
39 in your codebase if needed.
40 Deprecated in version 1.37.
41 */
42 [[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]]
43 Array BoundedGrid(Real xMin, Real xMax, Size steps);
44
45 /*! \deprecated Part of the old FD framework; copy this function
46 in your codebase if needed.
47 Deprecated in version 1.37.
48 */
49 [[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]]
50 Array BoundedLogGrid(Real xMin, Real xMax, Size steps);
51
52
53 // inline definitions
54
55 inline Array CenteredGrid(Real center, Real dx, Size steps) {
56 Array result(steps+1);
57 for (Size i=0; i<steps+1; i++)
58 result[i] = center + (i - steps/2.0)*dx;
59 return result;
60 }
61
62 inline Array BoundedGrid(Real xMin, Real xMax, Size steps) {
63 Array result(steps+1);
64 Real x=xMin, dx=(xMax-xMin)/steps;
65 for (Size i=0; i<steps+1; i++, x+=dx)
66 result[i] = x;
67 return result;
68 }
69
70 inline Array BoundedLogGrid(Real xMin, Real xMax, Size steps) {
71 Array result(steps+1);
72 Real gridLogSpacing = (std::log(xMax) - std::log(xMin)) /
73 (steps);
74 Real edx = std::exp(gridLogSpacing);
75 result[0] = xMin;
76 for (Size j=1; j < steps+1; j++) {
77 result[j] = result[j-1]*edx;
78 }
79 return result;
80 }
81}
82
83
84#endif
1-D array used in linear algebra.
1-D array used in linear algebra.
Definition: array.hpp:52
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
Array BoundedLogGrid(Real xMin, Real xMax, Size steps)
Definition: grid.hpp:70
Array BoundedGrid(Real xMin, Real xMax, Size steps)
Definition: grid.hpp:62
Array CenteredGrid(Real center, Real dx, Size steps)
Definition: grid.hpp:55