QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
batesengine.cpp
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) 2005 Klaus Spanderen
5 Copyright (C) 2007 StatPro Italia srl
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
23
24namespace QuantLib {
25
26 BatesEngine::BatesEngine(const ext::shared_ptr<BatesModel> & model,
27 Size integrationOrder)
29 model, AnalyticHestonEngine::Gatheral,
30 AnalyticHestonEngine::Integration::gaussLaguerre(integrationOrder)) { }
31
32 BatesEngine::BatesEngine(const ext::shared_ptr<BatesModel>& model,
33 Real relTolerance, Size maxEvaluations)
35 model, AnalyticHestonEngine::Gatheral,
36 AnalyticHestonEngine::Integration::gaussLobatto(
37 relTolerance, Null<Real>(), maxEvaluations)) { }
38
39 std::complex<Real> BatesEngine::addOnTerm(
40 Real phi, Time t, Size j) const {
41
42 ext::shared_ptr<BatesModel> batesModel =
43 ext::dynamic_pointer_cast<BatesModel>(*model_);
44
45 const Real nu_ = batesModel->nu();
46 const Real delta2_ = 0.5*batesModel->delta()*batesModel->delta();
47 const Real lambda_ = batesModel->lambda();
48 const Real i = (j == 1)? 1.0 : 0.0;
49 const std::complex<Real> g(i, phi);
50
51 //it can throw: to be fixed
52 return t*lambda_*(std::exp(nu_*g + delta2_*g*g) - 1.0
53 -g*(std::exp(nu_+delta2_) - 1.0));
54 }
55
56
58 const ext::shared_ptr<BatesDetJumpModel>& model,
59 Size integrationOrder)
60 : BatesEngine(model, integrationOrder) { }
61
63 const ext::shared_ptr<BatesDetJumpModel>& model,
64 Real relTolerance, Size maxEvaluations)
65 : BatesEngine(model, relTolerance, maxEvaluations) { }
66
68 Real phi, Time t, Size j) const {
69
70 const std::complex<Real> l =
72
73 ext::shared_ptr<BatesDetJumpModel> batesDetJumpModel =
74 ext::dynamic_pointer_cast<BatesDetJumpModel>(*model_);
75
76 const Real lambda = batesDetJumpModel->lambda();
77 const Real kappaLambda = batesDetJumpModel->kappaLambda();
78 const Real thetaLambda = batesDetJumpModel->thetaLambda();
79
80 return (kappaLambda*t - 1.0 + std::exp(-kappaLambda*t))
81 * thetaLambda*l/(kappaLambda*t*lambda)
82 + (1.0 - std::exp(-kappaLambda*t))*l/(kappaLambda*t);
83 }
84
85
87 const ext::shared_ptr<BatesDoubleExpModel> & model,
88 Size integrationOrder)
90 model, AnalyticHestonEngine::Gatheral,
91 AnalyticHestonEngine::Integration::gaussLaguerre(integrationOrder)) { }
92
94 const ext::shared_ptr<BatesDoubleExpModel>& model,
95 Real relTolerance, Size maxEvaluations)
97 model, AnalyticHestonEngine::Gatheral,
98 AnalyticHestonEngine::Integration::gaussLobatto(
99 relTolerance, Null<Real>(), maxEvaluations)) { }
100
102 Real phi, Time t, Size j) const {
103 ext::shared_ptr<BatesDoubleExpModel> batesDoubleExpModel =
104 ext::dynamic_pointer_cast<BatesDoubleExpModel>(*model_);
105
106 const Real p_ = batesDoubleExpModel->p();
107 const Real q_ = 1.0-p_;
108 const Real nuDown_= batesDoubleExpModel->nuDown();
109 const Real nuUp_ = batesDoubleExpModel->nuUp();
110 const Real lambda_= batesDoubleExpModel->lambda();
111 const Real i = (j == 1)? 1.0 : 0.0;
112 const std::complex<Real> g(i, phi);
113
114 return t*lambda_*(p_/(1.0-g*nuUp_) + q_/(1.0+g*nuDown_) - 1.0
115 - g*(p_/(1-nuUp_) + q_/(1+nuDown_)-1));
116 }
117
119 const ext::shared_ptr<BatesDoubleExpDetJumpModel> & model,
120 Size integrationOrder)
121 : BatesDoubleExpEngine(model, integrationOrder) { }
122
124 const ext::shared_ptr<BatesDoubleExpDetJumpModel>& model,
125 Real relTolerance, Size maxEvaluations)
126 : BatesDoubleExpEngine(model, relTolerance, maxEvaluations) { }
127
129 Real phi, Time t, Size j) const {
130 const std::complex<Real> l =
132
133 ext::shared_ptr<BatesDoubleExpDetJumpModel> doubleExpDetJumpModel
134 = ext::dynamic_pointer_cast<BatesDoubleExpDetJumpModel>(*model_);
135
136 const Real lambda = doubleExpDetJumpModel->lambda();
137 const Real kappaLambda = doubleExpDetJumpModel->kappaLambda();
138 const Real thetaLambda = doubleExpDetJumpModel->thetaLambda();
139
140 return (kappaLambda*t - 1.0 + std::exp(-kappaLambda*t))
141 * thetaLambda*l/(kappaLambda*t*lambda)
142 + (1.0 - std::exp(-kappaLambda*t))*l/(kappaLambda*t);
143 }
144
145}
analytic Bates model engine
analytic Heston-model engine based on Fourier transform
std::complex< Real > addOnTerm(Real phi, Time t, Size j) const override
Definition: batesengine.cpp:67
BatesDetJumpEngine(const ext::shared_ptr< BatesDetJumpModel > &model, Size integrationOrder=144)
Definition: batesengine.cpp:57
BatesDoubleExpDetJumpEngine(const ext::shared_ptr< BatesDoubleExpDetJumpModel > &model, Size integrationOrder=144)
std::complex< Real > addOnTerm(Real phi, Time t, Size j) const override
BatesDoubleExpEngine(const ext::shared_ptr< BatesDoubleExpModel > &model, Size integrationOrder=144)
Definition: batesengine.cpp:86
std::complex< Real > addOnTerm(Real phi, Time t, Size j) const override
Bates model engines based on Fourier transform.
std::complex< Real > addOnTerm(Real phi, Time t, Size j) const override
Definition: batesengine.cpp:39
BatesEngine(const ext::shared_ptr< BatesModel > &model, Size integrationOrder=144)
Definition: batesengine.cpp:26
template class providing a null value for a given type.
Definition: null.hpp:76
const DefaultType & t
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
const HestonParams p_
Definition: any.hpp:35
Payoffs for various options.