| 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) 2007 StatPro Italia srl |
| 6 | |
| 7 | This file is part of QuantLib, a free-software/open-source library |
| 8 | for financial quantitative analysts and developers - http://quantlib.org/ |
| 9 | |
| 10 | QuantLib is free software: you can redistribute it and/or modify it |
| 11 | under the terms of the QuantLib license. You should have received a |
| 12 | copy of the license along with this program; if not, please email |
| 13 | <quantlib-dev@lists.sf.net>. The license is also available online at |
| 14 | <http://quantlib.org/license.shtml>. |
| 15 | |
| 16 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 18 | FOR A PARTICULAR PURPOSE. See the license for more details. |
| 19 | */ |
| 20 | |
| 21 | /*! \file forwardperformanceengine.hpp |
| 22 | \brief Forward (strike-resetting) performance vanilla-option engine |
| 23 | */ |
| 24 | |
| 25 | #ifndef quantlib_forward_performance_engine_hpp |
| 26 | #define quantlib_forward_performance_engine_hpp |
| 27 | |
| 28 | #include <ql/pricingengines/forward/forwardengine.hpp> |
| 29 | |
| 30 | namespace QuantLib { |
| 31 | |
| 32 | //! %Forward performance engine for vanilla options |
| 33 | /*! \ingroup forwardengines |
| 34 | |
| 35 | \test |
| 36 | - the correctness of the returned value is tested by |
| 37 | reproducing results available in literature. |
| 38 | - the correctness of the returned greeks is tested by |
| 39 | reproducing numerical derivatives. |
| 40 | */ |
| 41 | template <class Engine> |
| 42 | class ForwardPerformanceVanillaEngine |
| 43 | : public ForwardVanillaEngine<Engine> { |
| 44 | public: |
| 45 | ForwardPerformanceVanillaEngine( |
| 46 | const ext::shared_ptr<GeneralizedBlackScholesProcess>&); |
| 47 | void calculate() const override; |
| 48 | |
| 49 | protected: |
| 50 | void getOriginalResults() const; |
| 51 | }; |
| 52 | |
| 53 | |
| 54 | // template definitions |
| 55 | |
| 56 | template <class Engine> |
| 57 | ForwardPerformanceVanillaEngine<Engine>::ForwardPerformanceVanillaEngine( |
| 58 | const ext::shared_ptr<GeneralizedBlackScholesProcess>& process) |
| 59 | : ForwardVanillaEngine<Engine>(process) {} |
| 60 | |
| 61 | template <class Engine> |
| 62 | void ForwardPerformanceVanillaEngine<Engine>::calculate() const { |
| 63 | this->setup(); |
| 64 | this->originalEngine_->calculate(); |
| 65 | getOriginalResults(); |
| 66 | } |
| 67 | |
| 68 | template <class Engine> |
| 69 | void ForwardPerformanceVanillaEngine<Engine>::getOriginalResults() const { |
| 70 | |
| 71 | DayCounter rfdc = this->process_->riskFreeRate()->dayCounter(); |
| 72 | Time resetTime = rfdc.yearFraction( |
| 73 | d1: this->process_->riskFreeRate()->referenceDate(), |
| 74 | d2: this->arguments_.resetDate); |
| 75 | DiscountFactor discR = this->process_->riskFreeRate()->discount( |
| 76 | this->arguments_.resetDate); |
| 77 | // it's a performance option |
| 78 | discR /= this->process_->stateVariable()->value(); |
| 79 | |
| 80 | Real temp = this->originalResults_->value; |
| 81 | this->results_.value = discR * temp; |
| 82 | this->results_.delta = 0.0; |
| 83 | this->results_.gamma = 0.0; |
| 84 | this->results_.theta = this->process_->riskFreeRate()-> |
| 85 | zeroRate(this->arguments_.resetDate, rfdc, Continuous, NoFrequency) |
| 86 | * this->results_.value; |
| 87 | this->results_.vega = discR * this->originalResults_->vega; |
| 88 | this->results_.rho = - resetTime * this->results_.value + |
| 89 | discR * this->originalResults_->rho; |
| 90 | this->results_.dividendRho = discR * this->originalResults_->dividendRho; |
| 91 | } |
| 92 | |
| 93 | } |
| 94 | |
| 95 | |
| 96 | #endif |
| 97 | |