| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2002, 2003, 2004 Ferdinando Ametrano |
| 5 | Copyright (C) 2002, 2003 RiskMap srl |
| 6 | Copyright (C) 2003, 2004, 2005, 2007 StatPro Italia srl |
| 7 | Copyright (C) 2005 Joseph Wang |
| 8 | |
| 9 | This file is part of QuantLib, a free-software/open-source library |
| 10 | for financial quantitative analysts and developers - http://quantlib.org/ |
| 11 | |
| 12 | QuantLib is free software: you can redistribute it and/or modify it |
| 13 | under the terms of the QuantLib license. You should have received a |
| 14 | copy of the license along with this program; if not, please email |
| 15 | <quantlib-dev@lists.sf.net>. The license is also available online at |
| 16 | <http://quantlib.org/license.shtml>. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 19 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 20 | FOR A PARTICULAR PURPOSE. See the license for more details. |
| 21 | */ |
| 22 | |
| 23 | /*! \file fdvanillaengine.hpp |
| 24 | \brief Finite-differences vanilla-option engine |
| 25 | */ |
| 26 | |
| 27 | #ifndef quantlib_fd_vanilla_engine_hpp |
| 28 | #define quantlib_fd_vanilla_engine_hpp |
| 29 | |
| 30 | #include <ql/math/sampledcurve.hpp> |
| 31 | #include <ql/methods/finitedifferences/boundarycondition.hpp> |
| 32 | #include <ql/methods/finitedifferences/tridiagonaloperator.hpp> |
| 33 | #include <ql/payoff.hpp> |
| 34 | #include <ql/pricingengine.hpp> |
| 35 | #include <ql/processes/blackscholesprocess.hpp> |
| 36 | #include <utility> |
| 37 | |
| 38 | |
| 39 | namespace QuantLib { |
| 40 | |
| 41 | /*! \deprecated Use the new finite-differences framework instead. |
| 42 | Deprecated in version 1.32. |
| 43 | */ |
| 44 | class [[deprecated("Use the new finite-differences framework instead" )]] FDVanillaEngine { |
| 45 | public: |
| 46 | QL_DEPRECATED_DISABLE_WARNING |
| 47 | FDVanillaEngine(ext::shared_ptr<GeneralizedBlackScholesProcess> process, |
| 48 | Size timeSteps, |
| 49 | Size gridPoints, |
| 50 | bool timeDependent = false) |
| 51 | : process_(std::move(process)), timeSteps_(timeSteps), gridPoints_(gridPoints), |
| 52 | timeDependent_(timeDependent), intrinsicValues_(gridPoints), BCs_(2) {} |
| 53 | virtual ~FDVanillaEngine() = default; |
| 54 | // accessors |
| 55 | const Array& grid() const { return intrinsicValues_.grid(); } |
| 56 | QL_DEPRECATED_ENABLE_WARNING |
| 57 | protected: |
| 58 | // methods |
| 59 | virtual void setupArguments(const PricingEngine::arguments*) const; |
| 60 | virtual void setGridLimits() const; |
| 61 | virtual void setGridLimits(Real, Time) const; |
| 62 | virtual void initializeInitialCondition() const; |
| 63 | virtual void initializeBoundaryConditions() const; |
| 64 | virtual void initializeOperator() const; |
| 65 | virtual Time getResidualTime() const; |
| 66 | // data |
| 67 | ext::shared_ptr<GeneralizedBlackScholesProcess> process_; |
| 68 | Size timeSteps_, gridPoints_; |
| 69 | bool timeDependent_; |
| 70 | mutable Date exerciseDate_; |
| 71 | mutable ext::shared_ptr<Payoff> payoff_; |
| 72 | mutable TridiagonalOperator finiteDifferenceOperator_; |
| 73 | QL_DEPRECATED_DISABLE_WARNING |
| 74 | mutable SampledCurve intrinsicValues_; |
| 75 | QL_DEPRECATED_ENABLE_WARNING |
| 76 | typedef BoundaryCondition<TridiagonalOperator> bc_type; |
| 77 | mutable std::vector<ext::shared_ptr<bc_type> > BCs_; |
| 78 | // temporaries |
| 79 | mutable Real sMin_, center_, sMax_; |
| 80 | |
| 81 | void ensureStrikeInGrid() const; |
| 82 | private: |
| 83 | Size safeGridPoints(Size gridPoints, |
| 84 | Time residualTime) const; |
| 85 | static const Real safetyZoneFactor_; |
| 86 | }; |
| 87 | |
| 88 | } |
| 89 | |
| 90 | #endif |
| 91 | |