Coverage Report

Created: 2025-11-04 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/pricingengines/vanilla/qdfpamericanengine.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2022 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 qdfpamericanengine.hpp
21
*/
22
23
#ifndef quantlib_qd_fp_american_engine_hpp
24
#define quantlib_qd_fp_american_engine_hpp
25
26
#include <ql/pricingengines/vanilla/qdplusamericanengine.hpp>
27
28
namespace QuantLib {
29
30
    class Integrator;
31
32
    //! Iteration scheme for fixed-point QD American engine
33
    class QdFpIterationScheme {
34
      public:
35
        virtual Size getNumberOfChebyshevInterpolationNodes() const = 0;
36
        virtual Size getNumberOfNaiveFixedPointSteps() const = 0;
37
        virtual Size getNumberOfJacobiNewtonFixedPointSteps() const = 0;
38
39
        virtual ext::shared_ptr<Integrator> getFixedPointIntegrator() const = 0;
40
        virtual ext::shared_ptr<Integrator> getExerciseBoundaryToPriceIntegrator() const = 0;
41
42
0
        virtual ~QdFpIterationScheme() = default;
43
    };
44
45
    //! Gauss-Legendre (l,m,n)-p Scheme
46
    /*! \param l  order of Gauss-Legendre integration within every fixed point iteration step
47
        \param m  fixed point iteration steps, first step is a partial Jacobi-Newton,
48
                  the rest are naive Richardson fixed point iterations
49
        \param n  number of Chebyshev nodes to interpolate the exercise boundary
50
        \param p  order of Gauss-Legendre integration in final conversion of the
51
                  exercise boundary into option prices
52
    */
53
    class QdFpLegendreScheme: public QdFpIterationScheme {
54
      public:
55
        QdFpLegendreScheme(Size l, Size m, Size n, Size p);
56
57
        Size getNumberOfChebyshevInterpolationNodes() const override;
58
        Size getNumberOfNaiveFixedPointSteps() const override;
59
        Size getNumberOfJacobiNewtonFixedPointSteps() const override;
60
61
        ext::shared_ptr<Integrator> getFixedPointIntegrator() const override;
62
        ext::shared_ptr<Integrator> getExerciseBoundaryToPriceIntegrator() const override;
63
64
      private:
65
        const Size m_, n_;
66
        const ext::shared_ptr<Integrator> fpIntegrator_;
67
        const ext::shared_ptr<Integrator> exerciseBoundaryIntegrator_;
68
    };
69
70
    //! Legendre-Tanh-Sinh (l,m,n)-eps Scheme
71
    /*! \param l    order of Gauss-Legendre integration within every fixed point iteration step
72
        \param m    fixed point iteration steps, first step is a partial Jacobi-Newton,
73
                    the rest are naive Richardson fixed point iterations
74
        \param n    number of Chebyshev nodes to interpolate the exercise boundary
75
        \param eps  final conversion of the exercise boundary into option prices
76
                    is carried out by a tanh-sinh integration with accuracy eps
77
    */
78
    class QdFpLegendreTanhSinhScheme: public QdFpLegendreScheme {
79
      public:
80
        QdFpLegendreTanhSinhScheme(Size l, Size m, Size n, Real eps);
81
82
        ext::shared_ptr<Integrator> getExerciseBoundaryToPriceIntegrator() const override;
83
84
      private:
85
        const Real eps_;
86
    };
87
88
    //! tanh-sinh (m,n)-eps Scheme
89
    /*! \param m    fixed point iteration steps, first step is a partial Jacobi-Newton,
90
                    the rest are naive Richardson fixed point iterations
91
        \param n    number of Chebyshev nodes to interpolate the exercise boundary
92
        \param eps  tanh-sinh integration precision
93
    */
94
    class QdFpTanhSinhIterationScheme: public QdFpIterationScheme {
95
      public:
96
        QdFpTanhSinhIterationScheme(Size m, Size n, Real eps);
97
98
        Size getNumberOfChebyshevInterpolationNodes() const override;
99
        Size getNumberOfNaiveFixedPointSteps() const override;
100
        Size getNumberOfJacobiNewtonFixedPointSteps() const override;
101
102
        ext::shared_ptr<Integrator> getFixedPointIntegrator() const override;
103
        ext::shared_ptr<Integrator> getExerciseBoundaryToPriceIntegrator() const override;
104
      private:
105
        const Size m_, n_;
106
        const ext::shared_ptr<Integrator> integrator_;
107
    };
108
109
110
    //! High performance/precision American engine based on fixed point iteration for the exercise boundary
111
    /*! References:
112
        Leif Andersen, Mark Lake and Dimitri Offengenden (2015)
113
        "High Performance American Option Pricing",
114
        https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2547027
115
116
        Leif Andersen, Mark Lake (2021)
117
        "Fast American Option Pricing: The Double-Boundary Case"
118
119
        https://onlinelibrary.wiley.com/doi/abs/10.1002/wilm.10969
120
    */
121
    class QdFpAmericanEngine : public detail::QdPutCallParityEngine {
122
      public:
123
        enum FixedPointEquation { FP_A, FP_B, Auto };
124
125
        explicit QdFpAmericanEngine(
126
          ext::shared_ptr<GeneralizedBlackScholesProcess> bsProcess,
127
          ext::shared_ptr<QdFpIterationScheme> iterationScheme = accurateScheme(),
128
          FixedPointEquation fpEquation = Auto);
129
130
        static ext::shared_ptr<QdFpIterationScheme> fastScheme();
131
        static ext::shared_ptr<QdFpIterationScheme> accurateScheme();
132
        static ext::shared_ptr<QdFpIterationScheme> highPrecisionScheme();
133
134
      protected:
135
        Real calculatePut(
136
            Real S, Real K, Rate r, Rate q, Volatility vol, Time T) const override;
137
138
      private:
139
        const ext::shared_ptr<QdFpIterationScheme> iterationScheme_;
140
        const FixedPointEquation fpEquation_;
141
    };
142
143
}
144
145
#endif