| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2010 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 fdbatesvanillaengine.cpp |
| 21 | \brief Partial Integro Finite-Differences Bates vanilla option engine |
| 22 | */ |
| 23 | |
| 24 | #include <ql/processes/batesprocess.hpp> |
| 25 | #include <ql/methods/finitedifferences/solvers/fdmbatessolver.hpp> |
| 26 | #include <ql/pricingengines/vanilla/fdbatesvanillaengine.hpp> |
| 27 | #include <ql/pricingengines/vanilla/fdhestonvanillaengine.hpp> |
| 28 | |
| 29 | namespace QuantLib { |
| 30 | |
| 31 | QL_DEPRECATED_DISABLE_WARNING |
| 32 | |
| 33 | FdBatesVanillaEngine::FdBatesVanillaEngine( |
| 34 | const ext::shared_ptr<BatesModel>& model, |
| 35 | Size tGrid, Size xGrid, |
| 36 | Size vGrid, Size dampingSteps, |
| 37 | const FdmSchemeDesc& schemeDesc) |
| 38 | : GenericModelEngine<BatesModel, |
| 39 | DividendVanillaOption::arguments, |
| 40 | DividendVanillaOption::results>(model), |
| 41 | explicitDividends_(false), |
| 42 | tGrid_(tGrid), xGrid_(xGrid), |
| 43 | vGrid_(vGrid), dampingSteps_(dampingSteps), |
| 44 | schemeDesc_(schemeDesc) {} |
| 45 | |
| 46 | FdBatesVanillaEngine::FdBatesVanillaEngine( |
| 47 | const ext::shared_ptr<BatesModel>& model, |
| 48 | DividendSchedule dividends, |
| 49 | Size tGrid, Size xGrid, |
| 50 | Size vGrid, Size dampingSteps, |
| 51 | const FdmSchemeDesc& schemeDesc) |
| 52 | : GenericModelEngine<BatesModel, |
| 53 | DividendVanillaOption::arguments, |
| 54 | DividendVanillaOption::results>(model), |
| 55 | dividends_(std::move(dividends)), explicitDividends_(true), |
| 56 | tGrid_(tGrid), xGrid_(xGrid), |
| 57 | vGrid_(vGrid), dampingSteps_(dampingSteps), |
| 58 | schemeDesc_(schemeDesc) {} |
| 59 | |
| 60 | QL_DEPRECATED_ENABLE_WARNING |
| 61 | |
| 62 | void FdBatesVanillaEngine::calculate() const { |
| 63 | |
| 64 | // dividends will eventually be moved out of arguments, but for now we need the switch |
| 65 | QL_DEPRECATED_DISABLE_WARNING |
| 66 | const DividendSchedule& passedDividends = explicitDividends_ ? dividends_ : arguments_.cashFlow; |
| 67 | QL_DEPRECATED_ENABLE_WARNING |
| 68 | |
| 69 | FdHestonVanillaEngine helperEngine(model_.currentLink(), |
| 70 | passedDividends, |
| 71 | tGrid_, xGrid_, vGrid_, |
| 72 | dampingSteps_, schemeDesc_); |
| 73 | |
| 74 | QL_DEPRECATED_DISABLE_WARNING |
| 75 | *dynamic_cast<DividendVanillaOption::arguments*>( |
| 76 | helperEngine.getArguments()) = arguments_; |
| 77 | QL_DEPRECATED_ENABLE_WARNING |
| 78 | |
| 79 | FdmSolverDesc solverDesc = helperEngine.getSolverDesc(equityScaleFactor: 2.0); |
| 80 | |
| 81 | const ext::shared_ptr<BatesProcess> process = |
| 82 | ext::dynamic_pointer_cast<BatesProcess>(r: model_->process()); |
| 83 | |
| 84 | ext::shared_ptr<FdmBatesSolver> solver( |
| 85 | new FdmBatesSolver(Handle<BatesProcess>(process), |
| 86 | solverDesc, schemeDesc_)); |
| 87 | |
| 88 | const Real v0 = process->v0(); |
| 89 | const Real spot = process->s0()->value(); |
| 90 | |
| 91 | results_.value = solver->valueAt(s: spot, v: v0); |
| 92 | results_.delta = solver->deltaAt(s: spot, v: v0); |
| 93 | results_.gamma = solver->gammaAt(s: spot, v: v0); |
| 94 | results_.theta = solver->thetaAt(s: spot, v: v0); |
| 95 | } |
| 96 | } |
| 97 | |