1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 3 /* 4 Copyright (C) 2012 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/twoassetbarrieroption.hpp> 21 #include <ql/exercise.hpp> 22 #include <ql/event.hpp> 23 24 namespace QuantLib { 25 TwoAssetBarrierOption(Barrier::Type barrierType,Real barrier,const ext::shared_ptr<StrikedTypePayoff> & payoff,const ext::shared_ptr<Exercise> & exercise)26 TwoAssetBarrierOption::TwoAssetBarrierOption( 27 Barrier::Type barrierType, 28 Real barrier, 29 const ext::shared_ptr<StrikedTypePayoff>& payoff, 30 const ext::shared_ptr<Exercise>& exercise) 31 : Option(payoff, exercise), barrierType_(barrierType), barrier_(barrier) {} 32 setupArguments(PricingEngine::arguments * args) const33 void TwoAssetBarrierOption::setupArguments( 34 PricingEngine::arguments* args) const { 35 Option::setupArguments(args); 36 TwoAssetBarrierOption::arguments* moreArgs = 37 dynamic_cast<TwoAssetBarrierOption::arguments*>(args); 38 QL_REQUIRE(moreArgs != 0, "wrong argument type"); 39 moreArgs->barrierType = barrierType_; 40 moreArgs->barrier = barrier_; 41 } 42 isExpired() const43 bool TwoAssetBarrierOption::isExpired() const { 44 return detail::simple_event(exercise_->lastDate()).hasOccurred(); 45 } 46 arguments()47 TwoAssetBarrierOption::arguments::arguments() 48 : barrierType(Barrier::Type(-1)), barrier(Null<Real>()) {} 49 validate() const50 void TwoAssetBarrierOption::arguments::validate() const { 51 Option::arguments::validate(); 52 53 switch (barrierType) { 54 case Barrier::DownIn: 55 case Barrier::UpIn: 56 case Barrier::DownOut: 57 case Barrier::UpOut: 58 break; 59 default: 60 QL_FAIL("unknown type"); 61 } 62 63 QL_REQUIRE(barrier != Null<Real>(), "no barrier given"); 64 } 65 triggered(Real underlying) const66 bool TwoAssetBarrierOption::engine::triggered(Real underlying) const { 67 switch (arguments_.barrierType) { 68 case Barrier::DownIn: 69 case Barrier::DownOut: 70 return underlying < arguments_.barrier; 71 case Barrier::UpIn: 72 case Barrier::UpOut: 73 return underlying > arguments_.barrier; 74 default: 75 QL_FAIL("unknown type"); 76 } 77 } 78 79 } 80 81