QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
laplaceinterpolation.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) 2015, 2024 Peter Caspers
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 laplaceinterpolation.hpp
21 \brief Laplace interpolation of missing values
22*/
23
24#ifndef quantlib_laplace_interpolation
25#define quantlib_laplace_interpolation
26
27#include <ql/math/array.hpp>
28#include <ql/math/matrix.hpp>
29#include <ql/shared_ptr.hpp>
30#include <ql/types.hpp>
31
32#include <vector>
33
34namespace QuantLib {
35
36 class FdmLinearOpLayout;
37
38 /*! Reconstruction of missing values using Laplace interpolation. We support an arbitrary number
39 of dimensions n >= 1 and non-equidistant grids. For n = 1 the method is identical to linear
40 interpolation with flat extrapolation. Reference: Numerical Recipes, 3rd edition, ch. 3.8. */
41
43 public:
44 /*! Missing values y should be encoded as Null<Real>(). */
45 LaplaceInterpolation(std::function<Real(const std::vector<Size>&)> y,
46 std::vector<std::vector<Real>> x,
47 Real relTol = 1E-6,
48 Size maxIterMultiplier = 10);
49 Real operator()(const std::vector<Size>& coordinates) const;
50
51 private:
52 std::vector<Size> projectedCoordinates(const std::vector<Size>& coordinates) const;
53 std::vector<Size> fullCoordinates(const std::vector<Size>& projectedCoordinates) const;
54
55 std::function<Real(const std::vector<Size>&)> y_;
56 std::vector<std::vector<Real>> x_;
59
60 std::vector<bool> coordinateIncluded_;
62
63 ext::shared_ptr<FdmLinearOpLayout> layout_;
65 };
66
67 /*! Convenience function that Laplace-interpolates null values in a given matrix.
68 If the x or y grid or both are not given, an equidistant grid is assumed. */
69
71 const std::vector<Real>& x = {},
72 const std::vector<Real>& y = {},
73 Real relTol = 1E-6,
74 Size maxIterMultiplier = 10);
75}
76
77#endif
1-D array used in linear algebra.
1-D array used in linear algebra.
Definition: array.hpp:52
std::vector< Size > fullCoordinates(const std::vector< Size > &projectedCoordinates) const
ext::shared_ptr< FdmLinearOpLayout > layout_
std::vector< Size > projectedCoordinates(const std::vector< Size > &coordinates) const
std::function< Real(const std::vector< Size > &)> y_
std::vector< std::vector< Real > > x_
Real operator()(const std::vector< Size > &coordinates) const
Matrix used in linear algebra.
Definition: matrix.hpp:41
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
matrix used in linear algebra.
Definition: any.hpp:35
void laplaceInterpolation(Matrix &A, const std::vector< Real > &x, const std::vector< Real > &y, Real relTol, Size maxIterMultiplier)
Maps shared_ptr to either the boost or std implementation.
Custom types.