| 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 | <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 | |
| 20 | /*! \file qdplusamericanengine.hpp |
| 21 | */ |
| 22 | |
| 23 | #ifndef quantlib_qd_plus_american_engine_hpp |
| 24 | #define quantlib_qd_plus_american_engine_hpp |
| 25 | |
| 26 | #include <ql/utilities/null.hpp> |
| 27 | #include <ql/instruments/vanillaoption.hpp> |
| 28 | #include <ql/processes/blackscholesprocess.hpp> |
| 29 | #include <ql/math/distributions/normaldistribution.hpp> |
| 30 | |
| 31 | |
| 32 | namespace QuantLib { |
| 33 | |
| 34 | class Interpolation; |
| 35 | class ChebyshevInterpolation; |
| 36 | class QdPlusBoundaryEvaluator; |
| 37 | |
| 38 | namespace detail { |
| 39 | |
| 40 | class QdPutCallParityEngine: public VanillaOption::engine { |
| 41 | public: |
| 42 | explicit QdPutCallParityEngine( |
| 43 | ext::shared_ptr<GeneralizedBlackScholesProcess> process); |
| 44 | |
| 45 | void calculate() const override; |
| 46 | |
| 47 | protected: |
| 48 | virtual Real calculatePut( |
| 49 | Real S, Real K, Rate r, Rate q, Volatility vol, Time T) const = 0; |
| 50 | |
| 51 | const ext::shared_ptr<GeneralizedBlackScholesProcess> process_; |
| 52 | |
| 53 | private: |
| 54 | Real calculatePutWithEdgeCases( |
| 55 | Real S, Real K, Rate r, Rate q, Volatility vol, Time T) const; |
| 56 | }; |
| 57 | |
| 58 | class QdPlusAddOnValue { |
| 59 | public: |
| 60 | QdPlusAddOnValue(Time T, |
| 61 | Real S, |
| 62 | Real K, |
| 63 | Rate r, |
| 64 | Rate q, |
| 65 | Volatility vol, |
| 66 | Real xmax, |
| 67 | ext::shared_ptr<Interpolation> q_z); |
| 68 | |
| 69 | Real operator()(Real z) const; |
| 70 | private: |
| 71 | const Time T_; |
| 72 | const Real S_, K_, xmax_; |
| 73 | const Rate r_, q_; |
| 74 | const Volatility vol_; |
| 75 | const ext::shared_ptr<Interpolation> q_z_; |
| 76 | const CumulativeNormalDistribution Phi_; |
| 77 | }; |
| 78 | } |
| 79 | |
| 80 | |
| 81 | //! American engine based on the QD+ approximation to the exercise boundary. |
| 82 | /*! The main purpose of this engine is to provide a good initial guess to the exercise |
| 83 | boundary for the superior fixed point American engine QdFpAmericanEngine |
| 84 | |
| 85 | References: |
| 86 | Li, M. (2009), “Analytical Approximations for the Critical Stock Prices |
| 87 | of American Options: A Performance Comparison,” |
| 88 | Working paper, Georgia Institute of Technology. |
| 89 | |
| 90 | https://mpra.ub.uni-muenchen.de/15018/1/MPRA_paper_15018.pdf |
| 91 | */ |
| 92 | class QdPlusAmericanEngine: public detail::QdPutCallParityEngine { |
| 93 | public: |
| 94 | enum SolverType {Brent, Newton, Ridder, Halley, SuperHalley}; |
| 95 | |
| 96 | explicit QdPlusAmericanEngine( |
| 97 | ext::shared_ptr<GeneralizedBlackScholesProcess>, |
| 98 | Size interpolationPoints = 8, |
| 99 | SolverType solverType = Halley, |
| 100 | Real eps = 1e-6, |
| 101 | Size maxIter = Null<Size>()); |
| 102 | |
| 103 | std::pair<Size, Real> putExerciseBoundaryAtTau( |
| 104 | Real S, Real K, Rate r, Rate q, |
| 105 | Volatility vol, Time T, Time tau) const; |
| 106 | |
| 107 | ext::shared_ptr<ChebyshevInterpolation> getPutExerciseBoundary( |
| 108 | Real S, Real K, Rate r, Rate q, Volatility vol, Time T) const; |
| 109 | |
| 110 | static Real xMax(Real K, Rate r, Rate q); |
| 111 | |
| 112 | protected: |
| 113 | Real calculatePut( |
| 114 | Real S, Real K, Rate r, Rate q, Volatility vol, Time T) const override; |
| 115 | |
| 116 | private: |
| 117 | template <class Solver> |
| 118 | Real buildInSolver( |
| 119 | const QdPlusBoundaryEvaluator& eval, |
| 120 | Solver solver, Real S, Real strike, Size maxIter, |
| 121 | Real guess = Null<Real>()) const; |
| 122 | |
| 123 | const Size interpolationPoints_; |
| 124 | const SolverType solverType_; |
| 125 | const Real eps_; |
| 126 | const Size maxIter_; |
| 127 | }; |
| 128 | } |
| 129 | |
| 130 | #endif |
| 131 | |