| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2002, 2003 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 forwardvanillaoption.hpp |
| 22 | \brief Forward version of a vanilla option |
| 23 | */ |
| 24 | |
| 25 | #ifndef quantlib_forward_vanilla_option_hpp |
| 26 | #define quantlib_forward_vanilla_option_hpp |
| 27 | |
| 28 | #include <ql/instruments/oneassetoption.hpp> |
| 29 | #include <ql/instruments/payoffs.hpp> |
| 30 | #include <ql/exercise.hpp> |
| 31 | #include <ql/settings.hpp> |
| 32 | |
| 33 | namespace QuantLib { |
| 34 | |
| 35 | //! %Arguments for forward (strike-resetting) option calculation |
| 36 | template <class ArgumentsType> |
| 37 | class ForwardOptionArguments : public ArgumentsType { |
| 38 | public: |
| 39 | ForwardOptionArguments() : moneyness(Null<Real>()), |
| 40 | resetDate(Null<Date>()) {} |
| 41 | void validate() const override; |
| 42 | Real moneyness; |
| 43 | Date resetDate; |
| 44 | }; |
| 45 | |
| 46 | //! %Forward version of a vanilla option |
| 47 | /*! \ingroup instruments */ |
| 48 | class ForwardVanillaOption : public OneAssetOption { |
| 49 | public: |
| 50 | typedef ForwardOptionArguments<OneAssetOption::arguments> arguments; |
| 51 | typedef OneAssetOption::results results; |
| 52 | ForwardVanillaOption(Real moneyness, |
| 53 | const Date& resetDate, |
| 54 | const ext::shared_ptr<StrikedTypePayoff>& payoff, |
| 55 | const ext::shared_ptr<Exercise>& exercise); |
| 56 | void setupArguments(PricingEngine::arguments*) const override; |
| 57 | void fetchResults(const PricingEngine::results*) const override; |
| 58 | |
| 59 | private: |
| 60 | // arguments |
| 61 | Real moneyness_; |
| 62 | Date resetDate_; |
| 63 | }; |
| 64 | |
| 65 | |
| 66 | // template definitions |
| 67 | |
| 68 | template <class ArgumentsType> |
| 69 | inline void ForwardOptionArguments<ArgumentsType>::validate() const { |
| 70 | ArgumentsType::validate(); |
| 71 | |
| 72 | QL_REQUIRE(moneyness != Null<Real>(), "null moneyness given" ); |
| 73 | QL_REQUIRE(moneyness > 0.0, "negative or zero moneyness given" ); |
| 74 | |
| 75 | QL_REQUIRE(resetDate != Null<Date>(), "null reset date given" ); |
| 76 | QL_REQUIRE(resetDate >= Settings::instance().evaluationDate(), |
| 77 | "reset date in the past" ); |
| 78 | QL_REQUIRE(this->exercise->lastDate() > resetDate, |
| 79 | "reset date later or equal to maturity" ); |
| 80 | } |
| 81 | |
| 82 | |
| 83 | } |
| 84 | |
| 85 | |
| 86 | #endif |
| 87 | |
| 88 | |