21 #ifndef quantext_log_quadratic_interpolation_hpp
22 #define quantext_log_quadratic_interpolation_hpp
24 #include <ql/math/interpolations/loginterpolation.hpp>
25 #include <ql/utilities/dataformatters.hpp>
32 template<
class I1,
class I2,
class I>
class LogInterpolationImpl;
43 template <
class I1,
class I2>
46 Real x_mul = 1, Real x_offset = 0,
47 Real y_mul = 1, Real y_offset = 0,
49 impl_ = ext::shared_ptr<Interpolation::Impl>(
new
52 Quadratic(x_mul, x_offset, y_mul, y_offset, skip)));
55 template <
class I1,
class I2>
59 ext::shared_ptr<Impl> p =
60 ext::dynamic_pointer_cast<Impl>(impl_);
61 QL_REQUIRE(p,
"unable to cast impl to "
62 "LogInterpolationImpl<I1,I2,Quadratic>");
64 ext::shared_ptr<QuadraticInterpolation> p2 =
65 ext::dynamic_pointer_cast<QuadraticInterpolation>(
67 QL_REQUIRE(p2,
"unable to cast interpolation to "
68 "QuadraticInterpolation");
70 return p2->lambdas<I1,I2>();
79 Real y_mul = 1, Real y_offset = 0,
84 template <
class I1,
class I2>
86 const I2& yBegin)
const {
102 template <
class I1,
class I2,
class Interpolator>
104 :
public Interpolation::templateImpl<I1,I2> {
108 const Interpolator& factory = Interpolator())
109 : Interpolation::templateImpl<I1,I2>(xBegin, xEnd, yBegin,
110 Interpolator::requiredPoints),
120 for (Size i=0; i<
logY_.size(); ++i) {
121 QL_REQUIRE(this->yBegin_[i]>0.0,
122 "invalid value (" << this->yBegin_[i]
123 <<
") at index " << i);
124 logY_[i] = std::log(this->yBegin_[i]);
132 QL_FAIL(
"LogInterpolation primitive not implemented");
log-quadratic interpolation factory and traits
LogQuadratic(Real x_mul=1, Real x_offset=0, Real y_mul=1, Real y_offset=0, Size skip=0)
static const Size requiredPoints
Interpolation interpolate(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin) const
log-quadratic interpolation between discrete points
LogQuadraticInterpolation(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin, Real x_mul=1, Real x_offset=0, Real y_mul=1, Real y_offset=0, Size skip=0)
std::vector< Real > lambdas() const
Quadratic-interpolation factory and traits
Real value(Real x) const override
LogInterpolationImpl(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin, const Interpolator &factory=Interpolator())
Real primitive(Real) const override
Real derivative(Real x) const override
std::vector< Real > logY_
Real secondDerivative(Real x) const override
QuantLib::ext::shared_ptr< Interpolation > interpolation() const
QuantLib::ext::shared_ptr< Interpolation > interpolation_
quadratic interpolation between discrete points