QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
flatextrapolation2d.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2007 Giorgio Facchinetti
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_flatextrapolation2D_hpp
25#define quantlib_flatextrapolation2D_hpp
26
27#include <ql/math/interpolations/interpolation2d.hpp>
28#include <utility>
29
30namespace QuantLib {
31
37 public:
38 FlatExtrapolator2D(const ext::shared_ptr<Interpolation2D>& decoratedInterpolation) {
39 impl_ = ext::shared_ptr<Interpolation2D::Impl>(
40 new FlatExtrapolator2DImpl(decoratedInterpolation));
41 }
42 protected:
44 public:
45 FlatExtrapolator2DImpl(ext::shared_ptr<Interpolation2D> decoratedInterpolation)
46 : decoratedInterp_(std::move(decoratedInterpolation)) {
48 }
49 Real xMin() const override { return decoratedInterp_->xMin(); }
50 Real xMax() const override { return decoratedInterp_->xMax(); }
51 std::vector<Real> xValues() const override { return decoratedInterp_->xValues(); }
52 Size locateX(Real x) const override { return decoratedInterp_->locateX(x); }
53 Real yMin() const override { return decoratedInterp_->yMin(); }
54 Real yMax() const override { return decoratedInterp_->yMax(); }
55 std::vector<Real> yValues() const override { return decoratedInterp_->yValues(); }
56 Size locateY(Real y) const override { return decoratedInterp_->locateY(y); }
57 const Matrix& zData() const override { return decoratedInterp_->zData(); }
58 bool isInRange(Real x, Real y) const override {
59 return decoratedInterp_->isInRange(x,y);
60 }
61 void update() {
62 decoratedInterp_->update();
63 }
64 void calculate() override {}
65 Real value(Real x, Real y) const override {
66 x = bindX(x);
67 y = bindY(y);
68 return (*decoratedInterp_)(x,y);
69 }
70
71 private:
72 ext::shared_ptr<Interpolation2D> decoratedInterp_;
73
74 Real bindX(Real x) const {
75 if(x < xMin())
76 return xMin();
77 if (x > xMax())
78 return xMax();
79 return x;
80 }
81 Real bindY(Real y) const {
82 if(y < yMin())
83 return yMin();
84 if (y > yMax())
85 return yMax();
86 return y;
87 }
88
89 };
90 };
91
92
93}
94
95
96#endif
FlatExtrapolator2DImpl(ext::shared_ptr< Interpolation2D > decoratedInterpolation)
FlatExtrapolator2D(const ext::shared_ptr< Interpolation2D > &decoratedInterpolation)
abstract base class for 2-D interpolation implementations
base class for 2-D interpolations.
ext::shared_ptr< Impl > impl_
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
Definition: any.hpp:35
STL namespace.