/usr/include/ql/pricingengines/vanilla/analytichestonengine.hpp is in libquantlib0-dev 1.12-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2004, 2005, 2008 Klaus Spanderen
Copyright (C) 2007 StatPro Italia srl
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<quantlib-dev@lists.sf.net>. The license is also available online at
<http://quantlib.org/license.shtml>.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
/*! \file analytichestonengine.hpp
\brief analytic Heston-model engine
*/
#ifndef quantlib_analytic_heston_engine_hpp
#define quantlib_analytic_heston_engine_hpp
#include <ql/utilities/null.hpp>
#include <ql/math/integrals/integral.hpp>
#include <ql/math/integrals/gaussianquadratures.hpp>
#include <ql/pricingengines/genericmodelengine.hpp>
#include <ql/models/equity/hestonmodel.hpp>
#include <ql/instruments/vanillaoption.hpp>
#include <boost/function.hpp>
#include <complex>
namespace QuantLib {
//! analytic Heston-model engine based on Fourier transform
/*! Integration detail:
Two algebraically equivalent formulations of the complex
logarithm of the Heston model exist. Gatherals [2005]
(also Duffie, Pan and Singleton [2000], and Schoutens,
Simons and Tistaert[2004]) version does not cause
discoutinuities whereas the original version (e.g. Heston [1993])
needs some sort of "branch correction" to work properly.
Gatheral's version does also work with adaptive integration
routines and should be preferred over the original Heston version.
*/
/*! References:
Heston, Steven L., 1993. A Closed-Form Solution for Options
with Stochastic Volatility with Applications to Bond and
Currency Options. The review of Financial Studies, Volume 6,
Issue 2, 327-343.
A. Sepp, Pricing European-Style Options under Jump Diffusion
Processes with Stochastic Volatility: Applications of Fourier
Transform (<http://math.ut.ee/~spartak/papers/stochjumpvols.pdf>)
R. Lord and C. Kahl, Why the rotation count algorithm works,
http://papers.ssrn.com/sol3/papers.cfm?abstract_id=921335
H. Albrecher, P. Mayer, W.Schoutens and J. Tistaert,
The Little Heston Trap, http://www.schoutens.be/HestonTrap.pdf
J. Gatheral, The Volatility Surface: A Practitioner's Guide,
Wiley Finance
F. Le Floc'h, Fourier Integration and Stochastic Volatility
Calibration,
https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2362968
L. Andersen, and V. Piterbarg, 2010,
Interest Rate Modeling, Volume I: Foundations and Vanilla Models,
Atlantic Financial Press London.
\ingroup vanillaengines
\test the correctness of the returned value is tested by
reproducing results available in web/literature
and comparison with Black pricing.
*/
class AnalyticHestonEngine
: public GenericModelEngine<HestonModel,
VanillaOption::arguments,
VanillaOption::results> {
public:
class Integration;
enum ComplexLogFormula { Gatheral, BranchCorrection, AndersenPiterbarg };
// Simple to use constructor: Using adaptive
// Gauss-Lobatto integration and Gatheral's version of complex log.
// Be aware: using a too large number for maxEvaluations might result
// in a stack overflow as the Lobatto integration is a recursive
// algorithm.
AnalyticHestonEngine(const boost::shared_ptr<HestonModel>& model,
Real relTolerance, Size maxEvaluations);
// Constructor using Laguerre integration
// and Gatheral's version of complex log.
AnalyticHestonEngine(const boost::shared_ptr<HestonModel>& model,
Size integrationOrder = 144);
// Constructor giving full control
// over the Fourier integration algorithm
AnalyticHestonEngine(const boost::shared_ptr<HestonModel>& model,
ComplexLogFormula cpxLog, const Integration& itg,
Real andersenPiterbargEpsilon = 1e-8);
// normalized characteristic function
std::complex<Real> chF(const std::complex<Real>& z, Time t) const;
std::complex<Real> lnChF(const std::complex<Real>& z, Time t) const;
void calculate() const;
Size numberOfEvaluations() const;
static void doCalculation(Real riskFreeDiscount,
Real dividendDiscount,
Real spotPrice,
Real strikePrice,
Real term,
Real kappa, Real theta, Real sigma, Real v0, Real rho,
const TypePayoff& type,
const Integration& integration,
const ComplexLogFormula cpxLog,
const AnalyticHestonEngine* const enginePtr,
Real& value,
Size& evaluations);
protected:
// call back for extended stochastic volatility
// plus jump diffusion engines like bates model
virtual std::complex<Real> addOnTerm(Real phi,
Time t,
Size j) const;
private:
class Fj_Helper;
class AP_Helper;
mutable Size evaluations_;
const ComplexLogFormula cpxLog_;
const boost::shared_ptr<Integration> integration_;
const Real andersenPiterbargEpsilon_;
};
class AnalyticHestonEngine::Integration {
public:
// non adaptive integration algorithms based on Gaussian quadrature
static Integration gaussLaguerre (Size integrationOrder = 128);
static Integration gaussLegendre (Size integrationOrder = 128);
static Integration gaussChebyshev (Size integrationOrder = 128);
static Integration gaussChebyshev2nd(Size integrationOrder = 128);
// for an adaptive integration algorithm Gatheral's version has to
// be used.Be aware: using a too large number for maxEvaluations might
// result in a stack overflow as the these integrations are based on
// recursive algorithms.
static Integration gaussLobatto(Real relTolerance, Real absTolerance,
Size maxEvaluations = 1000);
// usually these routines have a poor convergence behavior.
static Integration gaussKronrod(Real absTolerance,
Size maxEvaluations = 1000);
static Integration simpson(Real absTolerance,
Size maxEvaluations = 1000);
static Integration trapezoid(Real absTolerance,
Size maxEvaluations = 1000);
static Integration discreteSimpson(Size evaluation = 1000);
static Integration discreteTrapezoid(Size evaluation = 1000);
static Real andersenPiterbargIntegrationLimit(
Real c_inf, Real epsilon, Real v0, Real t);
Real calculate(Real c_inf,
const boost::function1<Real, Real>& f,
Real maxBound = Null<Real>()) const;
Size numberOfEvaluations() const;
bool isAdaptiveIntegration() const;
private:
enum Algorithm
{ GaussLobatto, GaussKronrod, Simpson, Trapezoid,
DiscreteTrapezoid, DiscreteSimpson,
GaussLaguerre, GaussLegendre,
GaussChebyshev, GaussChebyshev2nd };
Integration(Algorithm intAlgo,
const boost::shared_ptr<GaussianQuadrature>& quadrature);
Integration(Algorithm intAlgo,
const boost::shared_ptr<Integrator>& integrator);
const Algorithm intAlgo_;
const boost::shared_ptr<Integrator> integrator_;
const boost::shared_ptr<GaussianQuadrature> gaussianQuadrature_;
};
// inline
inline
std::complex<Real> AnalyticHestonEngine::addOnTerm(Real,
Time,
Size) const {
return std::complex<Real>(0,0);
}
}
#endif
|