1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 /*
4  Copyright (C) 2014 Master IMAFA - Polytech'Nice Sophia - Université de Nice Sophia Antipolis
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 #include <ql/experimental/exoticoptions/holderextensibleoption.hpp>
21 #include <ql/exercise.hpp>
22 
23 namespace QuantLib {
24 
HolderExtensibleOption(Option::Type type,Real premium,Date secondExpiryDate,Real secondStrike,const ext::shared_ptr<StrikedTypePayoff> & payoff,const ext::shared_ptr<Exercise> & exercise)25     HolderExtensibleOption::HolderExtensibleOption(
26                            Option::Type type,
27                            Real premium,
28                            Date secondExpiryDate,
29                            Real secondStrike,
30                            const ext::shared_ptr<StrikedTypePayoff>& payoff,
31                            const ext::shared_ptr<Exercise>& exercise)
32     : OneAssetOption(payoff,exercise),
33       premium_(premium),
34       secondExpiryDate_(secondExpiryDate),
35       secondStrike_(secondStrike) {}
36 
setupArguments(PricingEngine::arguments * args) const37     void HolderExtensibleOption::setupArguments(
38                                        PricingEngine::arguments* args) const {
39         OneAssetOption::setupArguments(args);
40         HolderExtensibleOption::arguments* moreArgs =
41             dynamic_cast<HolderExtensibleOption::arguments*>(args);
42         QL_REQUIRE(moreArgs != 0, "wrong argument type");
43         moreArgs->premium = premium_;
44         moreArgs->secondExpiryDate = secondExpiryDate_;
45         moreArgs->secondStrike = secondStrike_;
46     }
47 
validate() const48     void HolderExtensibleOption:: arguments::validate() const {
49         OneAssetOption::arguments::validate();
50         QL_REQUIRE(premium > 0,"negative premium not allowed");
51         QL_REQUIRE(secondExpiryDate != Date() , "no extending date given");
52         QL_REQUIRE(secondExpiryDate >= exercise->lastDate(),
53                    "extended date is earlier than or equal to first maturity date");
54     }
55 
56 }
57