1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 /*
4  Copyright (C) 2010 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/simplechooseroption.hpp>
21 #include <ql/instruments/payoffs.hpp>
22 #include <ql/exercise.hpp>
23 
24 namespace QuantLib {
25 
SimpleChooserOption(Date choosingDate,Real strike,const ext::shared_ptr<Exercise> & exercise)26     SimpleChooserOption::SimpleChooserOption(
27                                   Date choosingDate,
28                                   Real strike,
29                                   const ext::shared_ptr<Exercise>& exercise)
30     : OneAssetOption(ext::shared_ptr<Payoff>(
31                                 new PlainVanillaPayoff(Option::Call, strike)),
32                      exercise),
33       choosingDate_(choosingDate) {}
34 
setupArguments(PricingEngine::arguments * args) const35     void SimpleChooserOption::setupArguments(
36                                     PricingEngine::arguments* args) const {
37         OneAssetOption::setupArguments(args);
38         SimpleChooserOption::arguments* moreArgs =
39             dynamic_cast<SimpleChooserOption::arguments*>(args);
40         QL_REQUIRE(moreArgs != 0, "wrong argument type");
41         moreArgs->choosingDate=choosingDate_;
42     }
43 
validate() const44     void SimpleChooserOption::arguments::validate() const {
45         OneAssetOption::arguments::validate();
46         QL_REQUIRE(choosingDate != Date(), " no choosing date given");
47         QL_REQUIRE(choosingDate < exercise->lastDate(),
48                    "choosing date later than or equal to maturity date");
49     }
50 
51 }
52