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/complexchooseroption.hpp>
21 #include <ql/instruments/payoffs.hpp>
22 #include <ql/exercise.hpp>
23 
24 namespace QuantLib {
25 
ComplexChooserOption(Date choosingDate,Real strikeCall,Real strikePut,const ext::shared_ptr<Exercise> & exerciseCall,const ext::shared_ptr<Exercise> & exercisePut)26     ComplexChooserOption::ComplexChooserOption(
27         Date choosingDate,
28         Real strikeCall,
29         Real strikePut,
30         const ext::shared_ptr<Exercise>& exerciseCall,
31         const ext::shared_ptr<Exercise>& exercisePut)
32     : OneAssetOption(ext::make_shared<PlainVanillaPayoff>(Option::Call,
33                                                             strikeCall),
34                      exerciseCall),
35       choosingDate_(choosingDate),
36       strikeCall_(strikeCall),
37       strikePut_(strikePut),
38       exerciseCall_(exerciseCall),
39       exercisePut_(exercisePut) {}
40 
setupArguments(PricingEngine::arguments * args) const41     void ComplexChooserOption::setupArguments(
42                                        PricingEngine::arguments* args) const {
43         OneAssetOption::setupArguments(args);
44         ComplexChooserOption::arguments* moreArgs =
45             dynamic_cast<ComplexChooserOption::arguments*>(args);
46         QL_REQUIRE(moreArgs != 0, "wrong argument type");
47         moreArgs->choosingDate=choosingDate_;
48         moreArgs->strikeCall=strikeCall_;
49         moreArgs->strikePut=strikePut_;
50         moreArgs->exerciseCall = exerciseCall_;
51         moreArgs->exercisePut = exercisePut_;
52     }
53 
validate() const54     void ComplexChooserOption::arguments::validate() const {
55         OneAssetOption::arguments::validate();
56         QL_REQUIRE(choosingDate != Date() , " no choosing date given");
57         QL_REQUIRE(choosingDate < exerciseCall->lastDate(),
58                    "choosing date later than or equal to Call maturity date");
59         QL_REQUIRE(choosingDate < exercisePut->lastDate(),
60                    "choosing date later than or equal to Put maturity date");
61     }
62 
63 }
64