QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
polynomialmathfunction.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2015 Ferdinando Ametrano
5 Copyright (C) 2015 Paolo Mazzocchi
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21#ifndef quantlib_polynomial_math_function_hpp
22#define quantlib_polynomial_math_function_hpp
23
24#include <ql/math/matrix.hpp>
25
26#include <vector>
27
28namespace QuantLib {
29
30 //! %Cubic functional form
31 /*! \f[ f(t) = \sum_{i=0}^n{c_i t^i} \f] */
33
34 public:
35 PolynomialFunction(const std::vector<Real>& coeff);
36
37 //! function value at time t: \f[ f(t) = \sum_{i=0}^n{c_i t^i} \f]
38 Real operator()(Time t) const;
39
40 /*! first derivative of the function at time t
41 \f[ f'(t) = \sum_{i=0}^{n-1}{(i+1) c_{i+1} t^i} \f] */
42 Real derivative(Time t) const;
43
44 /*! indefinite integral of the function at time t
45 \f[ \int f(t)dt = \sum_{i=0}^n{c_i t^{i+1} / (i+1)} + K \f] */
46 Real primitive(Time t) const;
47
48 /*! definite integral of the function between t1 and t2
49 \f[ \int_{t1}^{t2} f(t)dt \f] */
51 Time t2) const;
52
53 /*! Inspectors */
54 Size order() const { return order_; }
55 const std::vector<Real>& coefficients() { return c_; }
56 const std::vector<Real>& derivativeCoefficients() { return derC_; }
57 const std::vector<Real>& primitiveCoefficients() { return prC_; }
58
59 /*! coefficients of a PolynomialFunction defined as definite
60 integral on a rolling window of length tau, with tau = t2-t */
61 std::vector<Real> definiteIntegralCoefficients(Time t,
62 Time t2) const;
63
64 /*! coefficients of a PolynomialFunction defined as definite
65 derivative on a rolling window of length tau, with tau = t2-t */
66 std::vector<Real> definiteDerivativeCoefficients(Time t,
67 Time t2) const;
68
69 private:
71 std::vector<Real> c_, derC_, prC_;
73 mutable Matrix eqs_;
75 Time t2) const;
76 };
77
78}
79
80#endif
Matrix used in linear algebra.
Definition: matrix.hpp:41
Real definiteIntegral(Time t1, Time t2) const
const std::vector< Real > & primitiveCoefficients()
void initializeEqs_(Time t, Time t2) const
const std::vector< Real > & derivativeCoefficients()
std::vector< Real > definiteIntegralCoefficients(Time t, Time t2) const
const std::vector< Real > & coefficients()
Real operator()(Time t) const
function value at time t:
std::vector< Real > definiteDerivativeCoefficients(Time t, Time t2) const
const DefaultType & t
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
matrix used in linear algebra.
Definition: any.hpp:35