| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2020 Lew Wei Hao |
| 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 fdcirvanillaengine.hpp |
| 21 | \brief Finite-differences CIR vanilla option engine |
| 22 | */ |
| 23 | |
| 24 | #ifndef quantlib_fd_cir_vanilla_engine_hpp |
| 25 | #define quantlib_fd_cir_vanilla_engine_hpp |
| 26 | |
| 27 | #include <ql/instruments/dividendvanillaoption.hpp> |
| 28 | #include <ql/methods/finitedifferences/solvers/fdmbackwardsolver.hpp> |
| 29 | #include <ql/methods/finitedifferences/solvers/fdmsolverdesc.hpp> |
| 30 | #include <ql/models/equity/hestonmodel.hpp> |
| 31 | #include <ql/pricingengines/genericmodelengine.hpp> |
| 32 | #include <ql/processes/coxingersollrossprocess.hpp> |
| 33 | #include <ql/termstructures/volatility/equityfx/localvoltermstructure.hpp> |
| 34 | |
| 35 | namespace QuantLib { |
| 36 | |
| 37 | class FdmQuantoHelper; |
| 38 | |
| 39 | QL_DEPRECATED_DISABLE_WARNING |
| 40 | |
| 41 | //! Finite-differences CIR vanilla option engine |
| 42 | /*! \ingroup vanillaengines |
| 43 | |
| 44 | \test the engine has been tested to converge among different schemes. |
| 45 | */ |
| 46 | class FdCIRVanillaEngine : public DividendVanillaOption::engine { |
| 47 | QL_DEPRECATED_ENABLE_WARNING |
| 48 | public: |
| 49 | FdCIRVanillaEngine(ext::shared_ptr<CoxIngersollRossProcess> cirProcess, |
| 50 | ext::shared_ptr<GeneralizedBlackScholesProcess> bsProcess, |
| 51 | Size tGrid, |
| 52 | Size xGrid, |
| 53 | Size vGrid, |
| 54 | Size dampingSteps, |
| 55 | Real rho, |
| 56 | const FdmSchemeDesc& schemeDesc = FdmSchemeDesc::ModifiedHundsdorfer(), |
| 57 | ext::shared_ptr<FdmQuantoHelper> quantoHelper = {}); |
| 58 | |
| 59 | FdCIRVanillaEngine(ext::shared_ptr<CoxIngersollRossProcess> cirProcess, |
| 60 | ext::shared_ptr<GeneralizedBlackScholesProcess> bsProcess, |
| 61 | DividendSchedule dividends, |
| 62 | Size tGrid, |
| 63 | Size xGrid, |
| 64 | Size vGrid, |
| 65 | Size dampingSteps, |
| 66 | Real rho, |
| 67 | const FdmSchemeDesc& schemeDesc = FdmSchemeDesc::ModifiedHundsdorfer(), |
| 68 | ext::shared_ptr<FdmQuantoHelper> quantoHelper = {}); |
| 69 | |
| 70 | void calculate() const override; |
| 71 | |
| 72 | FdmSolverDesc getSolverDesc(Real equityScaleFactor) const; |
| 73 | |
| 74 | private: |
| 75 | ext::shared_ptr<GeneralizedBlackScholesProcess> bsProcess_; |
| 76 | ext::shared_ptr<CoxIngersollRossProcess> cirProcess_; |
| 77 | ext::shared_ptr<FdmQuantoHelper> quantoHelper_; |
| 78 | DividendSchedule dividends_; |
| 79 | bool explicitDividends_; |
| 80 | const Size tGrid_, xGrid_, rGrid_, dampingSteps_; |
| 81 | const Real rho_; |
| 82 | const FdmSchemeDesc schemeDesc_; |
| 83 | }; |
| 84 | |
| 85 | class MakeFdCIRVanillaEngine { |
| 86 | public: |
| 87 | explicit MakeFdCIRVanillaEngine(ext::shared_ptr<CoxIngersollRossProcess> cirProcess, |
| 88 | ext::shared_ptr<GeneralizedBlackScholesProcess> bsProcess, |
| 89 | Real rho); |
| 90 | |
| 91 | MakeFdCIRVanillaEngine& withQuantoHelper( |
| 92 | const ext::shared_ptr<FdmQuantoHelper>& quantoHelper); |
| 93 | |
| 94 | MakeFdCIRVanillaEngine& withTGrid(Size tGrid); |
| 95 | MakeFdCIRVanillaEngine& withXGrid(Size xGrid); |
| 96 | MakeFdCIRVanillaEngine& withRGrid(Size rGrid); |
| 97 | MakeFdCIRVanillaEngine& withDampingSteps( |
| 98 | Size dampingSteps); |
| 99 | |
| 100 | MakeFdCIRVanillaEngine& withFdmSchemeDesc( |
| 101 | const FdmSchemeDesc& schemeDesc); |
| 102 | |
| 103 | MakeFdCIRVanillaEngine& withCashDividends( |
| 104 | const std::vector<Date>& dividendDates, |
| 105 | const std::vector<Real>& dividendAmounts); |
| 106 | |
| 107 | operator ext::shared_ptr<PricingEngine>() const; |
| 108 | |
| 109 | private: |
| 110 | ext::shared_ptr<CoxIngersollRossProcess> cirProcess_; |
| 111 | ext::shared_ptr<GeneralizedBlackScholesProcess> bsProcess_; |
| 112 | DividendSchedule dividends_; |
| 113 | bool explicitDividends_ = false; |
| 114 | const Real rho_; |
| 115 | Size tGrid_ = 10, xGrid_ = 100, rGrid_ = 100, dampingSteps_ = 0; |
| 116 | ext::shared_ptr<FdmSchemeDesc> schemeDesc_; |
| 117 | ext::shared_ptr<FdmQuantoHelper> quantoHelper_; |
| 118 | }; |
| 119 | } |
| 120 | |
| 121 | #endif |
| 122 | |