QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
abcdmathfunction.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) 2006, 2007, 2015 Ferdinando Ametrano
5 Copyright (C) 2006 Cristina Duminuco
6 Copyright (C) 2007 Giorgio Facchinetti
7 Copyright (C) 2015 Paolo Mazzocchi
8
9 This file is part of QuantLib, a free-software/open-source library
10 for financial quantitative analysts and developers - http://quantlib.org/
11
12 QuantLib is free software: you can redistribute it and/or modify it
13 under the terms of the QuantLib license. You should have received a
14 copy of the license along with this program; if not, please email
15 <quantlib-dev@lists.sf.net>. The license is also available online at
16 <http://quantlib.org/license.shtml>.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the license for more details.
21*/
22
23#ifndef quantlib_abcd_math_function_hpp
24#define quantlib_abcd_math_function_hpp
25
26#include <ql/types.hpp>
27#include <ql/errors.hpp>
28#include <vector>
29
30namespace QuantLib {
31
32 //! %Abcd functional form
33 /*! \f[ f(t) = [ a + b*t ] e^{-c*t} + d \f]
34 following Rebonato's notation. */
36
37 public:
38 AbcdMathFunction(Real a = 0.002,
39 Real b = 0.001,
40 Real c = 0.16,
41 Real d = 0.0005);
42 AbcdMathFunction(std::vector<Real> abcd);
43
44 //! function value at time t: \f[ f(t) \f]
45 Real operator()(Time t) const;
46
47 //! time at which the function reaches maximum (if any)
48 Time maximumLocation() const;
49
50 //! maximum value of the function
51 Real maximumValue() const;
52
53 //! function value at time +inf: \f[ f(\inf) \f]
54 Real longTermValue() const { return d_; }
55
56 /*! first derivative of the function at time t
57 \f[ f'(t) = [ (b-c*a) + (-c*b)*t) ] e^{-c*t} \f] */
58 Real derivative(Time t) const;
59
60 /*! indefinite integral of the function at time t
61 \f[ \int f(t)dt = [ (-a/c-b/c^2) + (-b/c)*t ] e^{-c*t} + d*t \f] */
62 Real primitive(Time t) const;
63
64 /*! definite integral of the function between t1 and t2
65 \f[ \int_{t1}^{t2} f(t)dt \f] */
66 Real definiteIntegral(Time t1, Time t2) const;
67
68 /*! Inspectors */
69 Real a() const { return a_; }
70 Real b() const { return b_; }
71 Real c() const { return c_; }
72 Real d() const { return d_; }
73 const std::vector<Real>& coefficients() { return abcd_; }
74 const std::vector<Real>& derivativeCoefficients() { return dabcd_; }
75 // the primitive is not abcd
76
77 /*! coefficients of a AbcdMathFunction defined as definite
78 integral on a rolling window of length tau, with tau = t2-t */
79 std::vector<Real> definiteIntegralCoefficients(Time t,
80 Time t2) const;
81
82 /*! coefficients of a AbcdMathFunction defined as definite
83 derivative on a rolling window of length tau, with tau = t2-t */
84 std::vector<Real> definiteDerivativeCoefficients(Time t,
85 Time t2) const;
86
87 static void validate(Real a,
88 Real b,
89 Real c,
90 Real d);
91 protected:
93 private:
94 void initialize_();
95 std::vector<Real> abcd_;
96 std::vector<Real> dabcd_;
99
101 };
102
103 // inline AbcdMathFunction
105 //return (a_ + b_*t)*std::exp(-c_*t) + d_;
106 return t<0 ? 0.0 : Real((a_ + b_*t)*std::exp(-c_*t) + d_);
107 }
108
110 //return (da_ + db_*t)*std::exp(-c_*t);
111 return t<0 ? 0.0 : Real((da_ + db_*t)*std::exp(-c_*t));
112 }
113
115 //return (pa_ + pb_*t)*std::exp(-c_*t) + d_*t + K_;
116 return t<0 ? 0.0 : Real((pa_ + pb_*t)*std::exp(-c_*t) + d_*t + K_);
117 }
118
120 if (b_==0.0 || a_<=0.0)
121 return d_;
122 return (*this)(maximumLocation());
123 }
124
125}
126
127#endif
static void validate(Real a, Real b, Real c, Real d)
Real definiteIntegral(Time t1, Time t2) const
const std::vector< Real > & derivativeCoefficients()
std::vector< Real > definiteIntegralCoefficients(Time t, Time t2) const
Time maximumLocation() const
time at which the function reaches maximum (if any)
const std::vector< Real > & coefficients()
Real maximumValue() const
maximum value of the function
Real longTermValue() const
function value at time +inf:
std::vector< Real > dabcd_
Real operator()(Time t) const
function value at time t:
std::vector< Real > definiteDerivativeCoefficients(Time t, Time t2) const
const DefaultType & t
Classes and functions for error handling.
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
Custom types.