24#ifndef quantext_flat_extrapolation_hpp
25#define quantext_flat_extrapolation_hpp
27#include <ql/math/interpolation.hpp>
28#include <ql/math/interpolations/cubicinterpolation.hpp>
29#include <ql/math/interpolations/linearinterpolation.hpp>
30#include <ql/math/interpolations/loginterpolation.hpp>
32#include <boost/make_shared.hpp>
47 Real
xMin()
const override {
return i_->xMin(); }
48 Real
xMax()
const override {
return i_->xMax(); }
49 std::vector<Real>
xValues()
const override { QL_FAIL(
"not implemented"); }
50 std::vector<Real>
yValues()
const override { QL_FAIL(
"not implemented"); }
51 bool isInRange(Real x)
const override {
return i_->isInRange(x); }
52 Real
value(Real x)
const override {
53 Real tmp = std::max(std::min(x,
i_->xMax()),
i_->xMin());
54 return i_->operator()(tmp);
57 if (x >=
i_->xMin() && x <= i_->
xMax()) {
58 return i_->primitive(x);
61 return i_->primitive(
i_->xMin()) - (
i_->xMin() - x);
63 return i_->primitive(
i_->xMax()) + (x -
i_->xMax());
67 if (x >
i_->xMin() && x < i_->
xMax()) {
68 return i_->derivative(x);
76 if (x >
i_->xMin() && x < i_->
xMax()) {
77 return i_->secondDerivative(x);
86 const QuantLib::ext::shared_ptr<Interpolation>
i_;
91 impl_ = QuantLib::ext::make_shared<FlatExtrapolationImpl>(i);
99 template <
class I1,
class I2> Interpolation
interpolate(
const I1& xBegin,
const I1& xEnd,
const I2& yBegin)
const {
100 return FlatExtrapolation(QuantLib::ext::make_shared<LinearInterpolation>(xBegin, xEnd, yBegin));
109 template <
class I1,
class I2> Interpolation
interpolate(
const I1& xBegin,
const I1& xEnd,
const I2& yBegin)
const {
110 return FlatExtrapolation(QuantLib::ext::make_shared<LogLinearInterpolation>(xBegin, xEnd, yBegin));
119 template <
class I1,
class I2> Interpolation
interpolate(
const I1& xBegin,
const I1& xEnd,
const I2& yBegin)
const {
120 return FlatExtrapolation(QuantLib::ext::make_shared<Parabolic>(xBegin, xEnd, yBegin));
130 QuantLib::CubicInterpolation::DerivativeApprox da = QuantLib::CubicInterpolation::Kruger,
131 bool monotonic =
false,
132 QuantLib::CubicInterpolation::BoundaryCondition leftCondition = QuantLib::CubicInterpolation::SecondDerivative,
133 QuantLib::Real leftConditionValue = 0.0,
134 QuantLib::CubicInterpolation::BoundaryCondition rightCondition = QuantLib::CubicInterpolation::SecondDerivative,
135 QuantLib::Real rightConditionValue = 0.0)
139 template <
class I1,
class I2> Interpolation
interpolate(
const I1& xBegin,
const I1& xEnd,
const I2& yBegin)
const {
148 QuantLib::CubicInterpolation::DerivativeApprox
da_;
150 QuantLib::CubicInterpolation::BoundaryCondition
leftType_;
Cubic interpolation and flat extrapolation factory and traits.
QuantLib::CubicInterpolation::DerivativeApprox da_
CubicFlat(QuantLib::CubicInterpolation::DerivativeApprox da=QuantLib::CubicInterpolation::Kruger, bool monotonic=false, QuantLib::CubicInterpolation::BoundaryCondition leftCondition=QuantLib::CubicInterpolation::SecondDerivative, QuantLib::Real leftConditionValue=0.0, QuantLib::CubicInterpolation::BoundaryCondition rightCondition=QuantLib::CubicInterpolation::SecondDerivative, QuantLib::Real rightConditionValue=0.0)
QuantLib::Real rightValue_
QuantLib::Real leftValue_
static const Size requiredPoints
QuantLib::CubicInterpolation::BoundaryCondition leftType_
Interpolation interpolate(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin) const
QuantLib::CubicInterpolation::BoundaryCondition rightType_
Hermite interpolation and flat extrapolation factory and traits.
static const Size requiredPoints
Interpolation interpolate(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin) const
Linear-interpolation and flat extrapolation factory and traits
static const Size requiredPoints
Interpolation interpolate(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin) const
Linear-interpolation and flat extrapolation factory and traits
static const Size requiredPoints
Interpolation interpolate(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin) const