1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2006, 2007 Ferdinando Ametrano
5 Copyright (C) 2006 Cristina Duminuco
6 Copyright (C) 2007 Giorgio Facchinetti
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22#ifndef quantlib_abcd_hpp
23#define quantlib_abcd_hpp
24
25#include <ql/types.hpp>
26#include <ql/errors.hpp>
27#include <ql/math/abcdmathfunction.hpp>
28
29namespace QuantLib {
30
31 //! %Abcd functional form for instantaneous volatility
32 /*! \f[ f(T-t) = [ a + b(T-t) ] e^{-c(T-t)} + d \f]
33 following Rebonato's notation. */
34 class AbcdFunction : public AbcdMathFunction {
35
36 public:
37 AbcdFunction(Real a = -0.06,
38 Real b = 0.17,
39 Real c = 0.54,
40 Real d = 0.17);
41
42 //! maximum value of the volatility function
43 Real maximumVolatility() const { return maximumValue(); }
44
45 //! volatility function value at time 0: \f[ f(0) \f]
46 Real shortTermVolatility() const { return (*this)(0.0); }
47
48 //! volatility function value at time +inf: \f[ f(\inf) \f]
49 Real longTermVolatility() const { return longTermValue(); }
50
51 /*! instantaneous covariance function at time t between T-fixing and
52 S-fixing rates \f[ f(T-t)f(S-t) \f] */
53 Real covariance(Time t, Time T, Time S) const;
54
55 /*! integral of the instantaneous covariance function between
56 time t1 and t2 for T-fixing and S-fixing rates
57 \f[ \int_{t1}^{t2} f(T-t)f(S-t)dt \f] */
58 Real covariance(Time t1, Time t2, Time T, Time S) const;
59
60 /*! average volatility in [tMin,tMax] of T-fixing rate:
61 \f[ \sqrt{ \frac{\int_{tMin}^{tMax} f^2(T-u)du}{tMax-tMin} } \f] */
62 Real volatility(Time tMin, Time tMax, Time T) const;
63
64 /*! variance between tMin and tMax of T-fixing rate:
65 \f[ \frac{\int_{tMin}^{tMax} f^2(T-u)du}{tMax-tMin} \f] */
66 Real variance(Time tMin, Time tMax, Time T) const;
67
68
69
70 // INSTANTANEOUS
71 /*! instantaneous volatility at time t of the T-fixing rate:
72 \f[ f(T-t) \f] */
73 Real instantaneousVolatility(Time t, Time T) const;
74
75 /*! instantaneous variance at time t of T-fixing rate:
76 \f[ f(T-t)f(T-t) \f] */
77 Real instantaneousVariance(Time t, Time T) const;
78
79 /*! instantaneous covariance at time t between T and S fixing rates:
80 \f[ f(T-u)f(S-u) \f] */
81 Real instantaneousCovariance(Time u, Time T, Time S) const;
82
83 // PRIMITIVE
84 /*! indefinite integral of the instantaneous covariance function at
85 time t between T-fixing and S-fixing rates
86 \f[ \int f(T-t)f(S-t)dt \f] */
87 Real primitive(Time t, Time T, Time S) const;
88
89 };
90
91
92 // Helper class used by unit tests
93 class AbcdSquared {
94
95 public:
96 /*! \deprecated Use `auto` or `decltype` instead.
97 Deprecated in version 1.29.
98 */
99 QL_DEPRECATED
100 typedef Real argument_type;
101
102 /*! \deprecated Use `auto` or `decltype` instead.
103 Deprecated in version 1.29.
104 */
105 QL_DEPRECATED
106 typedef Real result_type;
107
108 AbcdSquared(Real a, Real b, Real c, Real d, Time T, Time S);
109 Real operator()(Time t) const;
110
111 private:
112 ext::shared_ptr<AbcdFunction> abcd_;
113 Time T_, S_;
114 };
115
116 inline Real abcdBlackVolatility(Time u, Real a, Real b, Real c, Real d) {
117 AbcdFunction model(a,b,c,d);
118 return model.volatility(tMin: 0.,tMax: u,T: u);
119 }
120}
121
122#endif
123

source code of quantlib/ql/termstructures/volatility/abcd.hpp