Coverage Report

Created: 2026-03-31 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/pricingengines/vanilla/hestonexpansionengine.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2014 Fabien Le Floc'h
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
 <https://www.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
/*! \file hestonexpansionengine.hpp
21
    \brief analytic Heston expansion engine
22
*/
23
24
#ifndef quantlib_heston_expansion_engine_hpp
25
#define quantlib_heston_expansion_engine_hpp
26
27
#include <ql/pricingengines/genericmodelengine.hpp>
28
#include <ql/models/equity/hestonmodel.hpp>
29
#include <ql/instruments/vanillaoption.hpp>
30
31
namespace QuantLib {
32
33
    //! Heston-model engine for European options based on analytic expansions
34
    /*! References:
35
36
        M Forde, A Jacquier, R Lee, The small-time smile and term
37
        structure of implied volatility under the Heston model
38
        SIAM Journal on Financial Mathematics, 2012 - SIAM
39
40
        M Lorig, S Pagliarani, A Pascucci, Explicit implied vols for
41
        multifactor local-stochastic vol models
42
        arXiv preprint arXiv:1306.5447v3, 2014 - arxiv.org
43
44
        \ingroup vanillaengines
45
    */
46
    class HestonExpansionEngine
47
        : public GenericModelEngine<HestonModel,
48
                                    VanillaOption::arguments,
49
                                    VanillaOption::results> {
50
      public:
51
        enum HestonExpansionFormula { LPP2, LPP3, Forde };
52
53
        HestonExpansionEngine(const ext::shared_ptr<HestonModel>& model,
54
                              HestonExpansionFormula formula);
55
56
        void calculate() const override;
57
58
      private:
59
        const HestonExpansionFormula formula_;
60
    };
61
62
    /*! Interface to represent some Heston expansion formula.
63
        During calibration, it would typically be initialized once per
64
        implied volatility surface slice, then calls for each surface
65
        strike to impliedVolatility(strike, forward) would be
66
        performed.
67
    */
68
    class HestonExpansion {
69
      public:
70
0
        virtual ~HestonExpansion() = default;
71
        virtual Real impliedVolatility(Real strike, Real forward) const = 0;
72
    };
73
74
    /*! Lorig Pagliarani Pascucci expansion of order-2 for the Heston model.
75
        During calibration, it can be initialized once per expiry, and
76
        called many times with different strikes.  The formula is also
77
        available in the Mathematica notebook from the authors at
78
        http://explicitsolutions.wordpress.com/
79
    */
80
    class LPP2HestonExpansion : public HestonExpansion {
81
      public:
82
        LPP2HestonExpansion(Real kappa, Real theta, Real sigma, Real v0, Real rho, Real term);
83
        Real impliedVolatility(Real strike, Real forward) const override;
84
85
      private:
86
        Real coeffs[3];
87
        Real ekt, e2kt, e3kt, e4kt;
88
        Real z0(Real t, Real kappa, Real theta,
89
                Real delta, Real y, Real rho) const;
90
        Real z1(Real t, Real kappa, Real theta,
91
                Real delta, Real y, Real rho) const;
92
        Real z2(Real t, Real kappa, Real theta,
93
                Real delta, Real y, Real rho) const;
94
    };
95
96
    /*! Lorig Pagliarani Pascucci expansion of order-3 for the Heston model.
97
        During calibration, it can be initialized once per expiry, and
98
        called many times with different strikes.  The formula is also
99
        available in the Mathematica notebook from the authors at
100
        http://explicitsolutions.wordpress.com/
101
    */
102
    class LPP3HestonExpansion : public HestonExpansion{
103
      public:
104
        LPP3HestonExpansion(Real kappa, Real theta, Real sigma, Real v0, Real rho, Real term);
105
        Real impliedVolatility(Real strike, Real forward) const override;
106
107
      private:
108
        Real coeffs[4];
109
        Real ekt, e2kt, e3kt, e4kt;
110
        Real z0(Real t, Real kappa, Real theta,
111
                Real delta, Real y, Real rho) const;
112
        Real z1(Real t, Real kappa, Real theta,
113
                Real delta, Real y, Real rho) const;
114
        Real z2(Real t, Real kappa, Real theta,
115
                Real delta, Real y, Real rho) const;
116
        Real z3(Real t, Real kappa, Real theta,
117
                Real delta, Real y, Real rho) const;
118
    };
119
120
    /*! Small-time expansion from
121
        "The small-time smile and term structure of implied volatility
122
        under the Heston model" M Forde, A Jacquier, R Lee - SIAM
123
        Journal on Financial Mathematics, 2012 - SIAM
124
    */
125
    class FordeHestonExpansion : public HestonExpansion {
126
      public:
127
        FordeHestonExpansion(Real kappa, Real theta, Real sigma, Real v0, Real rho, Real term);
128
        Real impliedVolatility(Real strike, Real forward) const override;
129
130
      private:
131
        Real coeffs[5];
132
    };
133
134
}
135
136
137
#endif