QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
analyticpdfhestonengine.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2014, 2015 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
24#include <ql/experimental/exoticoptions/analyticpdfhestonengine.hpp>
25#include <ql/math/integrals/gausslobattointegral.hpp>
26#include <ql/methods/finitedifferences/utilities/hestonrndcalculator.hpp>
27#include <utility>
28
29namespace QuantLib {
30
31 AnalyticPDFHestonEngine::AnalyticPDFHestonEngine(ext::shared_ptr<HestonModel> model,
32 Real integrationEps_,
33 Size maxIntegrationIterations)
34 : maxIntegrationIterations_(maxIntegrationIterations), integrationEps_(integrationEps_),
35 model_(std::move(model)) {}
36
38 // this is an European option pricer
39 QL_REQUIRE(arguments_.exercise->type() == Exercise::European,
40 "not an European option");
41
42 const ext::shared_ptr<HestonProcess>& process = model_->process();
43
44 const Time t = process->time(arguments_.exercise->lastDate());
45
46 const Real xMax = 8.0 * std::sqrt(process->theta()*t
47 + (process->v0() - process->theta())
48 *(1-std::exp(-process->kappa()*t))/process->kappa());
49
50 const Real x0 = std::log(process->s0()->value());
51 const Real rD = process->riskFreeRate()->discount(t);
52 const Real qD = process->dividendYield()->discount(t);
53
54 const Real drift = x0 + std::log(rD/qD);
55
57 [&](Real _x){ return weightedPayoff(_x, t); },
58 -xMax+drift, xMax+drift);
59 }
60
64 .pdf(x_t, t);
65 }
66
68 const Real x_t = std::log(s);
71 .cdf(x_t, t);
72 }
73
75 const DiscountFactor rD
76 = model_->process()->riskFreeRate()->discount(t);
77
78 const Real s_t = std::exp(x_t);
79 const Real payoff = (*arguments_.payoff)(s_t);
80
81 return (payoff != 0.0) ? payoff*Pv(x_t, t)*rD : Real(0.0);
82 }
83}
84
AnalyticPDFHestonEngine(ext::shared_ptr< HestonModel > model, Real gaussLobattoEps=1e-6, Size gaussLobattoIntegrationOrder=10000UL)
const ext::shared_ptr< HestonModel > model_
Real weightedPayoff(Real x_t, Time t) const
Integral of a one-dimensional function.
Risk neutral terminal probability density for the Heston model.
Real pdf(Real x, Time t) const override
Real cdf(Real x, Time t) const override
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real DiscountFactor
discount factor between dates
Definition: types.hpp:66
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
STL namespace.