QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
polynomial2Dspline.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2003 Ferdinando Ametrano
5 Copyright (C) 2004 StatPro Italia srl
6 Copyright (C) 2009 Bernd Engelmann
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
26#ifndef quantlib_polynomial2D_spline_hpp
27#define quantlib_polynomial2D_spline_hpp
28
29#include <ql/math/interpolations/interpolation2d.hpp>
30#include <ql/math/interpolations/cubicinterpolation.hpp>
31
32namespace QuantLib {
33
34 namespace detail {
35
36 template <class I1, class I2, class M>
38 : public Interpolation2D::templateImpl<I1,I2,M> {
39 public:
40 Polynomial2DSplineImpl(const I1& xBegin, const I1& xEnd,
41 const I2& yBegin, const I2& yEnd, const M& zData)
42 : Interpolation2D::templateImpl<I1,I2,M>(xBegin,xEnd,
43 yBegin,yEnd,
44 zData) {
45 calculate();
46 }
47 void calculate() {
48 QL_REQUIRE(this->zData_.rows() == this->yEnd_ - this->yBegin_,
49 "size mismatch of the interpolation data");
50
51 polynomials_.reserve(this->zData_.columns());
52 for (Size i=0; i<(this->zData_.columns()); ++i)
53 polynomials_.push_back(Parabolic(
54 this->yBegin_, this->yEnd_,
55 this->zData_.column_begin(i)));
56 }
58 Real y) const {
59 std::vector<Real> section(polynomials_.size());
60 for (Size i=0; i<polynomials_.size(); ++i)
61 section[i] = polynomials_[i](y, true);
62
63 QL_REQUIRE(section.size() == this->xEnd_ - this->xBegin_,
64 "size mismatch of the interpolation data");
65
66 CubicInterpolation spline(
67 this->xBegin_, this->xEnd_,
68 section.begin(),
72 return spline(x,true);
73 }
74 private:
75 std::vector<Interpolation> polynomials_;
76 };
77
78 }
79
82 public:
84 template <class I1, class I2, class M>
85 Polynomial2DSpline(const I1& xBegin, const I1& xEnd,
86 const I2& yBegin, const I2& yEnd,
87 const M& zData) {
88 impl_ = ext::shared_ptr<Interpolation2D::Impl>(
90 yBegin, yEnd, zData));
91 }
92 };
93
95 class Polynomial {
96 public:
97 template <class I1, class I2, class M>
98 Interpolation2D interpolate(const I1& xBegin, const I1& xEnd,
99 const I2& yBegin, const I2& yEnd,
100 const M& z) const {
101 return Polynomial2DSpline(xBegin,xEnd,yBegin,yEnd,z);
102 }
103 };
104
105}
106
107#endif
Cubic interpolation between discrete points.
@ SecondDerivative
Match value of second derivative at end.
basic template implementation
const Matrix & zData() const override
templateImpl(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin, const I2 &yEnd, const M &zData)
base class for 2-D interpolations.
const Matrix & zData() const
ext::shared_ptr< Impl > impl_
polynomial2D-spline interpolation between discrete points
Polynomial2DSpline(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin, const I2 &yEnd, const M &zData)
polynomial2D-spline-interpolation factory
Interpolation2D interpolate(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin, const I2 &yEnd, const M &z) const
Polynomial2DSplineImpl(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin, const I2 &yEnd, const M &zData)
std::vector< Interpolation > polynomials_
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