QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
lmlinexpvolmodel.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2005, 2006 Klaus Spanderen
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20#include <ql/legacy/libormarketmodels/lmlinexpvolmodel.hpp>
21
22namespace QuantLib {
23
25 const std::vector<Time>& fixingTimes,
26 Real a, Real b, Real c, Real d)
27 : LmVolatilityModel(fixingTimes.size(), 4),
28 fixingTimes_(fixingTimes) {
33 }
34
35
37 Time t, const Array&) const {
38 const Real a = arguments_[0](0.0);
39 const Real b = arguments_[1](0.0);
40 const Real c = arguments_[2](0.0);
41 const Real d = arguments_[3](0.0);
42
43 Array tmp(size_, 0.0);
44
45 for (Size i=0; i<size_; ++i) {
46 const Time T = fixingTimes_[i];
47 if (T>t) {
48 tmp[i] = (a*(T-t)+d)*std::exp(-b*(T-t)) + c;
49 }
50 }
51
52 return tmp;
53 }
54
56 Size i, Time t, const Array&) const {
57 const Real a = arguments_[0](0.0);
58 const Real b = arguments_[1](0.0);
59 const Real c = arguments_[2](0.0);
60 const Real d = arguments_[3](0.0);
61
62 const Time T = fixingTimes_[i];
63
64 return (T>t) ? (a*(T-t)+d)*std::exp(-b*(T-t)) + c : Real(0.0);
65 }
66
68 Size i, Size j, Time u, const Array&) const {
69 const Real a = arguments_[0](0.0);
70 const Real b = arguments_[1](0.0);
71 const Real c = arguments_[2](0.0);
72 const Real d = arguments_[3](0.0);
73
74 const Time T = fixingTimes_[i];
75 const Time S = fixingTimes_[j];
76
77 const Real k1=std::exp(b*u);
78 const Real k2=std::exp(b*S);
79 const Real k3=std::exp(b*T);
80
81 return (a*a*(-1 - 2*b*b*S*T - b*(S + T)
82 + k1*k1*(1 + b*(S + T - 2*u) + 2*b*b*(S - u)*(T - u)))
83 + 2*b*b*(2*c*d*(k2 + k3)*(k1 - 1)
84 +d*d*(k1*k1 - 1)+2*b*c*c*k2*k3*u)
85 + 2*a*b*(d*(-1 - b*(S + T) + k1*k1*(1 + b*(S + T - 2*u)))
86 -2*c*(k3*(1 + b*S) + k2*(1 + b*T)
87 - k1*k3*(1 + b*(S - u))
88 - k1*k2*(1 + b*(T - u)))
89 )
90 ) / (4*b*b*b*k2*k3);
91 }
92
94
95}
96
1-D array used in linear algebra.
Definition: array.hpp:52
Standard constant parameter .
Definition: parameter.hpp:71
Array volatility(Time t, const Array &x=Null< Array >()) const override
LmLinearExponentialVolatilityModel(const std::vector< Time > &fixingTimes, Real a, Real b, Real c, Real d)
Real integratedVariance(Size i, Size j, Time u, const Array &x=Null< Array >()) const override
caplet volatility model
Definition: lmvolmodel.hpp:33
std::vector< Parameter > arguments_
Definition: lmvolmodel.hpp:50
Constraint imposing positivity to all arguments
Definition: constraint.hpp:92
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real Volatility
volatility
Definition: types.hpp:78
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35