1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 /*
4  Copyright (C) 2008 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/everestoption.hpp>
21 #include <ql/instruments/payoffs.hpp>
22 
23 namespace QuantLib {
24 
EverestOption(Real notional,Rate guarantee,const ext::shared_ptr<Exercise> & exercise)25     EverestOption::EverestOption(Real notional,
26                                  Rate guarantee,
27                                  const ext::shared_ptr<Exercise>& exercise)
28     : MultiAssetOption(ext::shared_ptr<Payoff>(new NullPayoff), exercise),
29       notional_(notional), guarantee_(guarantee) {}
30 
yield() const31     Rate EverestOption::yield() const {
32         calculate();
33         QL_REQUIRE(yield_ != Null<Rate>(), "yield not provided");
34         return yield_;
35     }
36 
setupArguments(PricingEngine::arguments * args) const37     void EverestOption::setupArguments(PricingEngine::arguments* args) const {
38         MultiAssetOption::setupArguments(args);
39 
40         EverestOption::arguments* arguments =
41             dynamic_cast<EverestOption::arguments*>(args);
42         QL_REQUIRE(arguments != 0, "wrong argument type");
43 
44         arguments->notional = notional_;
45         arguments->guarantee= guarantee_;
46     }
47 
fetchResults(const PricingEngine::results * r) const48     void EverestOption::fetchResults(const PricingEngine::results* r) const {
49         MultiAssetOption::fetchResults(r);
50         const EverestOption::results* results =
51             dynamic_cast<const EverestOption::results*>(r);
52         QL_ENSURE(results != 0,
53                   "no results returned from pricing engine");
54         yield_ = results->yield;
55     }
56 
57 
arguments()58     EverestOption::arguments::arguments()
59     : notional(Null<Real>()), guarantee(Null<Rate>()) {}
60 
validate() const61     void EverestOption::arguments::validate() const {
62         MultiAssetOption::arguments::validate();
63         QL_REQUIRE(notional != Null<Rate>(), "no notional given");
64         QL_REQUIRE(notional != 0.0, "null notional given");
65         QL_REQUIRE(guarantee != Null<Rate>(), "no guarantee given");
66     }
67 
68 
reset()69     void EverestOption::results::reset() {
70         MultiAssetOption::results::reset();
71         yield = Null<Rate>();
72     }
73 
74 }
75 
76