| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2020 Jack Gillett |
| 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 analytichestonforwardeuropeanengine.hpp |
| 21 | \brief analytic heston engine for forward-starting european options |
| 22 | */ |
| 23 | |
| 24 | #ifndef quantlib_analytic_heston_forward_european_engine_hpp |
| 25 | #define quantlib_analytic_heston_forward_european_engine_hpp |
| 26 | |
| 27 | #include <ql/instruments/forwardvanillaoption.hpp> |
| 28 | #include <ql/pricingengines/vanilla/analytichestonengine.hpp> |
| 29 | #include <ql/processes/hestonprocess.hpp> |
| 30 | #include <ql/models/equity/hestonmodel.hpp> |
| 31 | #include <ql/math/modifiedbessel.hpp> |
| 32 | #include <ql/math/integrals/gaussianquadratures.hpp> |
| 33 | #include <ql/exercise.hpp> |
| 34 | #include <ql/quotes/simplequote.hpp> |
| 35 | |
| 36 | namespace QuantLib { |
| 37 | |
| 38 | //! Analytic Heston engine incl. stochastic interest rates |
| 39 | /*! This class is pricing a european option under the following process |
| 40 | |
| 41 | \f[ |
| 42 | \begin{array}{rcl} |
| 43 | dS(t, S) &=& (r-d) S dt +\sqrt{v} S dW_1 \\ |
| 44 | dv(t, S) &=& \kappa (\theta - v) dt + \sigma \sqrt{v} dW_2 \\ |
| 45 | dW_1 dW_2 &=& \rho dt \\ |
| 46 | \end{array} |
| 47 | \f] |
| 48 | |
| 49 | References: |
| 50 | |
| 51 | Implements the analytical solution for forward-starting |
| 52 | strike-reset options descriped in "On the Pricing of Forward |
| 53 | Starting Options under Stochastic Volatility", S. Kruse (2003) |
| 54 | |
| 55 | \ingroup forwardengines |
| 56 | |
| 57 | \test |
| 58 | - For tReset > 0, price from the analytic pricer is compared |
| 59 | to the MC priver for calls/puts at various moneynesses |
| 60 | - For tReset ~ 0, price from the analytic pricer is compared |
| 61 | to the Heston analytic vanilla pricer for various options |
| 62 | */ |
| 63 | |
| 64 | class AnalyticHestonForwardEuropeanEngine : public GenericEngine<ForwardOptionArguments<VanillaOption::arguments>, |
| 65 | VanillaOption::results> { |
| 66 | public: |
| 67 | explicit AnalyticHestonForwardEuropeanEngine(ext::shared_ptr<HestonProcess> process, |
| 68 | Size integrationOrder = 144); |
| 69 | |
| 70 | void calculate() const override; |
| 71 | |
| 72 | // The evolution probability function from t0 to tReset |
| 73 | Real propagator(Time resetTime, |
| 74 | Real varReset) const; |
| 75 | |
| 76 | // Forward characteristic function for given (t, vt, St) |
| 77 | ext::shared_ptr<AnalyticHestonEngine> forwardChF( |
| 78 | Handle<Quote>& spotReset, |
| 79 | Real varReset) const; |
| 80 | |
| 81 | private: |
| 82 | // Parameters for the internal chF generators |
| 83 | ext::shared_ptr<HestonProcess> process_; |
| 84 | Size integrationOrder_; |
| 85 | |
| 86 | // Initial process params |
| 87 | Real v0_, rho_, kappa_, theta_, sigma_; |
| 88 | Handle<YieldTermStructure> dividendYield_; |
| 89 | Handle<YieldTermStructure> riskFreeRate_; |
| 90 | Handle<Quote> s0_; |
| 91 | |
| 92 | // Some intermediate calculation constant parameters |
| 93 | Real kappaHat_, thetaHat_, R_; |
| 94 | |
| 95 | // The integrator for nu. This pricer needs to perform nested integrations, the outer |
| 96 | // integrator should be non-adaptive as this can cause very long runtimes. Gaussian |
| 97 | // Quadrature has been found to work well. |
| 98 | GaussLegendreIntegration outerIntegrator_; |
| 99 | |
| 100 | // Integrate over characteristic function to generate P1, P2 (fall back on this |
| 101 | // when reset time is very close, to avoid numerical issues with tReset=0s) |
| 102 | std::pair<Real, Real> calculateP1P2(Time t, |
| 103 | Handle<Quote>& St, |
| 104 | Real K, |
| 105 | Real ratio, |
| 106 | Real phiRightLimit = 100) const; |
| 107 | |
| 108 | // Integrate P1, P2 over te propagator function to calculate forward-start price |
| 109 | std::pair<Real, Real> calculateP1P2Hat(Time tenor, |
| 110 | Time resetTime, |
| 111 | Real K, |
| 112 | Real ratio, |
| 113 | Real phiRightLimit = 100, |
| 114 | Real nuRightLimit = 2.0) const; |
| 115 | |
| 116 | }; |
| 117 | } |
| 118 | |
| 119 | #endif |
| 120 | |