Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
constantinterpolation.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file constantinterpolation.hpp
20 \brief flat interpolation decorator
21 \ingroup math
22*/
23
24#pragma once
25
26#include <ql/math/interpolation.hpp>
27
28namespace QuantExt {
29
30using QuantLib::Real;
31
32//! %Constant interpolation
33/*! \ingroup interpolations
34 \warning See the Interpolation class for information about the
35 required lifetime of the underlying data.
36*/
37class ConstantInterpolation : public QuantLib::Interpolation {
38public:
39 ConstantInterpolation(const Real& y) { impl_ = QuantLib::ext::make_shared<ConstantInterpolationImpl>(y); }
40
41private:
42 struct ConstantInterpolationImpl : public Interpolation::Impl {
43 ConstantInterpolationImpl(const Real& y) : y_(y) {}
44 void update() override {}
45 Real xMin() const override { return -QL_MAX_REAL; }
46 Real xMax() const override { return QL_MAX_REAL; }
47 std::vector<Real> xValues() const override { return std::vector<Real>(1, 0.0); }
48 std::vector<Real> yValues() const override { return std::vector<Real>(1, y_); }
49 bool isInRange(Real) const override { return true; }
50 Real value(Real) const override { return y_; }
51 Real primitive(Real x) const override { return y_ * x; }
52 Real derivative(Real) const override { return 0.0; }
53 Real secondDerivative(Real) const override { return 0.0; }
54
55 const Real& y_;
56 };
57};
58
59//! %Constant-interpolation factory and traits
60/*! \ingroup interpolations */
61class Constant {
62public:
63 QuantLib::Interpolation interpolate(const Real& y) const { return ConstantInterpolation(y); }
64 static const bool global = false;
65 static const QuantLib::Size requiredPoints = 1;
66};
67
68} // namespace QuantExt
Constant-interpolation factory and traits
static const bool global
QuantLib::Interpolation interpolate(const Real &y) const
static const QuantLib::Size requiredPoints