QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
abcd.cpp
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) 2005, 2006 Klaus Spanderen
7 Copyright (C) 2007 Giorgio Facchinetti
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#include <ql/termstructures/volatility/abcd.hpp>
24#include <ql/math/comparison.hpp>
25#include <algorithm>
26
27namespace QuantLib {
28
30 : AbcdMathFunction(a, b, c, d) {}
31
33 if (tMax==tMin)
34 return instantaneousVolatility(tMax, T);
35 QL_REQUIRE(tMax>tMin, "tMax must be > tMin");
36 return std::sqrt(variance(tMin, tMax, T)/(tMax-tMin));
37 }
38
39 Real AbcdFunction::variance(Time tMin, Time tMax, Time T) const {
40 return covariance(tMin, tMax, T, T);
41 }
42
44 return (*this)(T-t) * (*this)(S-t);
45 }
46
48 QL_REQUIRE(t1<=t2,
49 "integrations bounds (" << t1 <<
50 "," << t2 << ") are in reverse order");
51 Time cutOff = std::min(S,T);
52 if (t1>=cutOff) {
53 return 0.0;
54 } else {
55 cutOff = std::min(t2, cutOff);
56 return primitive(cutOff, T, S) - primitive(t1, T, S);
57 }
58 }
59
60 // INSTANTANEOUS
62 return std::sqrt(instantaneousVariance(u, T));
63 }
64
66 return instantaneousCovariance(u, T, T);
67 }
69 return (*this)(T-u)*(*this)(S-u);
70 }
71
72 // PRIMITIVE
74 if (T<t || S<t) return 0.0;
75
76 if (close(c_,0.0)) {
77 Real v = a_+d_;
78 return t*(v*v+v*b_*S+v*b_*T-v*b_*t+b_*b_*S*T-0.5*b_*b_*t*(S+T)+b_*b_*t*t/3.0);
79 }
80
81 Real k1=std::exp(c_*t), k2=std::exp(c_*S), k3=std::exp(c_*T);
82
83 return (b_*b_*(-1 - 2*c_*c_*S*T - c_*(S + T)
84 + k1*k1*(1 + c_*(S + T - 2*t) + 2*c_*c_*(S - t)*(T - t)))
85 + 2*c_*c_*(2*d_*a_*(k2 + k3)*(k1 - 1)
86 +a_*a_*(k1*k1 - 1)+2*c_*d_*d_*k2*k3*t)
87 + 2*b_*c_*(a_*(-1 - c_*(S + T) + k1*k1*(1 + c_*(S + T - 2*t)))
88 -2*d_*(k3*(1 + c_*S) + k2*(1 + c_*T)
89 - k1*k3*(1 + c_*(S - t))
90 - k1*k2*(1 + c_*(T - t)))
91 )
92 ) / (4*c_*c_*c_*k2*k3);
93 }
94
95//===========================================================================//
96// AbcdSquared //
97//===========================================================================//
98
100 : abcd_(new AbcdFunction(a,b,c,d)),
101 T_(T), S_(S) {}
102
104 return abcd_->covariance(t, T_, S_);
105 }
106}
Abcd functional form for instantaneous volatility
Definition: abcd.hpp:34
Real covariance(Time t, Time T, Time S) const
Definition: abcd.cpp:43
Real instantaneousVolatility(Time t, Time T) const
Definition: abcd.cpp:61
Real instantaneousCovariance(Time u, Time T, Time S) const
Definition: abcd.cpp:68
Real volatility(Time tMin, Time tMax, Time T) const
Definition: abcd.cpp:32
AbcdFunction(Real a=-0.06, Real b=0.17, Real c=0.54, Real d=0.17)
Definition: abcd.cpp:29
Real instantaneousVariance(Time t, Time T) const
Definition: abcd.cpp:65
Real primitive(Time t, Time T, Time S) const
Definition: abcd.cpp:73
Real variance(Time tMin, Time tMax, Time T) const
Definition: abcd.cpp:39
AbcdSquared(Real a, Real b, Real c, Real d, Time T, Time S)
Definition: abcd.cpp:99
ext::shared_ptr< AbcdFunction > abcd_
Definition: abcd.hpp:112
Real operator()(Time t) const
Definition: abcd.cpp:103
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
bool close(const Quantity &m1, const Quantity &m2, Size n)
Definition: quantity.cpp:163