Coverage Report

Created: 2026-01-25 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/models/equity/hestonmodel.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2005 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
 <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 hestonmodel.hpp
21
    \brief Heston model for the stochastic volatility of an asset
22
*/
23
24
#ifndef quantlib_heston_model_hpp
25
#define quantlib_heston_model_hpp
26
27
#include <ql/models/model.hpp>
28
#include <ql/processes/hestonprocess.hpp>
29
30
namespace QuantLib {
31
32
    //! Heston model for the stochastic volatility of an asset
33
    /*! References:
34
35
        Heston, Steven L., 1993. A Closed-Form Solution for Options
36
        with Stochastic Volatility with Applications to Bond and
37
        Currency Options.  The review of Financial Studies, Volume 6,
38
        Issue 2, 327-343.
39
40
        \test calibration is tested against known good values.
41
    */
42
    class HestonModel : public CalibratedModel {
43
      public:
44
        explicit HestonModel(const ext::shared_ptr<HestonProcess>& process);
45
46
        // variance mean version level
47
0
        Real theta() const { return arguments_[0](0.0); }
48
        // variance mean reversion speed
49
0
        Real kappa() const { return arguments_[1](0.0); }
50
        // volatility of the volatility
51
0
        Real sigma() const { return arguments_[2](0.0); }
52
        // correlation
53
0
        Real rho()   const { return arguments_[3](0.0); }
54
        // spot variance
55
0
        Real v0()    const { return arguments_[4](0.0); }
56
57
        // underlying process
58
0
        ext::shared_ptr<HestonProcess> process() const { return process_; }
59
60
        class FellerConstraint;
61
      protected:
62
        void generateArguments() override;
63
        ext::shared_ptr<HestonProcess> process_;
64
    };
65
66
    class HestonModel::FellerConstraint : public Constraint {
67
      private:
68
        class Impl final : public Constraint::Impl {
69
          public:
70
0
            bool test(const Array& params) const override {
71
0
                const Real theta = params[0];
72
0
                const Real kappa = params[1];
73
0
                const Real sigma = params[2];
74
0
75
0
                return (sigma >= 0.0 && sigma*sigma < 2.0*kappa*theta);
76
0
            }
77
        };
78
      public:
79
        FellerConstraint()
80
        : Constraint(ext::shared_ptr<Constraint::Impl>(
81
0
                                           new FellerConstraint::Impl)) {}
82
    };
83
}
84
85
86
#endif
87