/src/quantlib/ql/pricingengines/vanilla/analytichestonhullwhiteengine.cpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2007 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 | | <https://www.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 | | |
21 | | #include <ql/pricingengines/vanilla/analytichestonhullwhiteengine.hpp> |
22 | | #include <utility> |
23 | | |
24 | | namespace QuantLib { |
25 | | |
26 | | AnalyticHestonHullWhiteEngine::AnalyticHestonHullWhiteEngine( |
27 | | const ext::shared_ptr<HestonModel>& hestonModel, |
28 | | ext::shared_ptr<HullWhite> hullWhiteModel, |
29 | | Size integrationOrder) |
30 | 0 | : AnalyticHestonEngine( |
31 | 0 | hestonModel, AnalyticHestonEngine::Gatheral, |
32 | 0 | AnalyticHestonEngine::Integration::gaussLaguerre(integrationOrder)), |
33 | 0 | hullWhiteModel_(std::move(hullWhiteModel)) { |
34 | 0 | setParameters(); |
35 | 0 | registerWith(hullWhiteModel_); |
36 | 0 | } |
37 | | |
38 | | AnalyticHestonHullWhiteEngine::AnalyticHestonHullWhiteEngine( |
39 | | const ext::shared_ptr<HestonModel>& hestonModel, |
40 | | ext::shared_ptr<HullWhite> hullWhiteModel, |
41 | | Real relTolerance, |
42 | | Size maxEvaluations) |
43 | 0 | : AnalyticHestonEngine( |
44 | 0 | hestonModel, AnalyticHestonEngine::Gatheral, |
45 | 0 | AnalyticHestonEngine::Integration::gaussLobatto( |
46 | 0 | relTolerance, Null<Real>(), maxEvaluations)), |
47 | 0 | hullWhiteModel_(std::move(hullWhiteModel)) { |
48 | 0 | setParameters(); |
49 | 0 | registerWith(hullWhiteModel_); |
50 | 0 | } |
51 | | |
52 | 0 | void AnalyticHestonHullWhiteEngine::update() { |
53 | 0 | setParameters(); |
54 | 0 | AnalyticHestonEngine::update(); |
55 | 0 | } |
56 | | |
57 | 0 | void AnalyticHestonHullWhiteEngine::calculate() const { |
58 | |
|
59 | 0 | const Real t = model_->process()->time(arguments_.exercise->lastDate()); |
60 | 0 | if (a_*t > std::pow(QL_EPSILON, 0.25)) { |
61 | 0 | m_ = sigma_*sigma_/(2*a_*a_) |
62 | 0 | *(t+2/a_*std::exp(-a_*t)-1/(2*a_)*std::exp(-2*a_*t)-3/(2*a_)); |
63 | 0 | } |
64 | 0 | else { |
65 | | // low-a algebraic limit |
66 | 0 | m_ = 0.5*sigma_*sigma_*t*t*t*(1/3.0-0.25*a_*t+7/60.0*a_*a_*t*t); |
67 | 0 | } |
68 | |
|
69 | 0 | AnalyticHestonEngine::calculate(); |
70 | 0 | } |
71 | | |
72 | 0 | void AnalyticHestonHullWhiteEngine::setParameters() { |
73 | 0 | a_ = hullWhiteModel_->params()[0]; |
74 | 0 | sigma_ = hullWhiteModel_->params()[1]; |
75 | 0 | } |
76 | | |
77 | | } |