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:
ForwardOptionArguments()39         ForwardOptionArguments() : moneyness(Null<Real>()),
40                                    resetDate(Null<Date>()) {}
41         void validate() const;
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;
57         void fetchResults(const PricingEngine::results*) const;
58       private:
59         // arguments
60         Real moneyness_;
61         Date resetDate_;
62     };
63 
64 
65     // template definitions
66 
67     template <class ArgumentsType>
validate() const68     inline void ForwardOptionArguments<ArgumentsType>::validate() const {
69         ArgumentsType::validate();
70 
71         QL_REQUIRE(moneyness != Null<Real>(), "null moneyness given");
72         QL_REQUIRE(moneyness > 0.0, "negative or zero moneyness given");
73 
74         QL_REQUIRE(resetDate != Null<Date>(), "null reset date given");
75         QL_REQUIRE(resetDate >= Settings::instance().evaluationDate(),
76                    "reset date in the past");
77         QL_REQUIRE(this->exercise->lastDate() > resetDate,
78                    "reset date later or equal to maturity");
79     }
80 
81 
82 }
83 
84 
85 #endif
86 
87