QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
abcdmathfunction.hpp
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
33
36
37 public:
41 QL_DEPRECATED
43
47 QL_DEPRECATED
49
50 AbcdMathFunction(Real a = 0.002,
51 Real b = 0.001,
52 Real c = 0.16,
53 Real d = 0.0005);
54 AbcdMathFunction(std::vector<Real> abcd);
55
57 Real operator()(Time t) const;
58
60 Time maximumLocation() const;
61
63 Real maximumValue() const;
64
66 Real longTermValue() const { return d_; }
67
70 Real derivative(Time t) const;
71
74 Real primitive(Time t) const;
75
78 Real definiteIntegral(Time t1, Time t2) const;
79
81 Real a() const { return a_; }
82 Real b() const { return b_; }
83 Real c() const { return c_; }
84 Real d() const { return d_; }
85 const std::vector<Real>& coefficients() { return abcd_; }
86 const std::vector<Real>& derivativeCoefficients() { return dabcd_; }
87 // the primitive is not abcd
88
91 std::vector<Real> definiteIntegralCoefficients(Time t,
92 Time t2) const;
93
96 std::vector<Real> definiteDerivativeCoefficients(Time t,
97 Time t2) const;
98
99 static void validate(Real a,
100 Real b,
101 Real c,
102 Real d);
103 protected:
105 private:
106 void initialize_();
107 std::vector<Real> abcd_;
108 std::vector<Real> dabcd_;
111
113 };
114
115 // inline AbcdMathFunction
117 //return (a_ + b_*t)*std::exp(-c_*t) + d_;
118 return t<0 ? 0.0 : Real((a_ + b_*t)*std::exp(-c_*t) + d_);
119 }
120
122 //return (da_ + db_*t)*std::exp(-c_*t);
123 return t<0 ? 0.0 : Real((da_ + db_*t)*std::exp(-c_*t));
124 }
125
127 //return (pa_ + pb_*t)*std::exp(-c_*t) + d_*t + K_;
128 return t<0 ? 0.0 : Real((pa_ + pb_*t)*std::exp(-c_*t) + d_*t + K_);
129 }
130
132 if (b_==0.0 || a_<=0.0)
133 return d_;
134 return (*this)(maximumLocation());
135 }
136
137}
138
139#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:
QL_DEPRECATED typedef Time argument_type
QL_DEPRECATED typedef Real result_type
Real operator()(Time t) const
function value at time t:
std::vector< Real > definiteDerivativeCoefficients(Time t, Time t2) const
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