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/partialtimebarrieroption.hpp> 21 #include <ql/exercise.hpp> 22 23 namespace QuantLib { 24 PartialTimeBarrierOption(PartialBarrier::Type barrierType,PartialBarrier::Range barrierRange,Real barrier,Real rebate,Date coverEventDate,const ext::shared_ptr<StrikedTypePayoff> & payoff,const ext::shared_ptr<Exercise> & exercise)25 PartialTimeBarrierOption::PartialTimeBarrierOption( 26 PartialBarrier::Type barrierType, 27 PartialBarrier::Range barrierRange, 28 Real barrier, 29 Real rebate, 30 Date coverEventDate, 31 const ext::shared_ptr<StrikedTypePayoff>& payoff, 32 const ext::shared_ptr<Exercise>& exercise) 33 : OneAssetOption(payoff, exercise), 34 barrierType_(barrierType), barrierRange_(barrierRange), 35 barrier_(barrier), rebate_(rebate), 36 coverEventDate_(coverEventDate) {} 37 setupArguments(PricingEngine::arguments * args) const38 void PartialTimeBarrierOption::setupArguments( 39 PricingEngine::arguments* args) const { 40 OneAssetOption::setupArguments(args); 41 42 PartialTimeBarrierOption::arguments* moreArgs = 43 dynamic_cast<PartialTimeBarrierOption::arguments*>(args); 44 QL_REQUIRE(moreArgs != 0, "wrong argument type"); 45 moreArgs->barrierType = barrierType_; 46 moreArgs->barrierRange = barrierRange_; 47 moreArgs->barrier = barrier_; 48 moreArgs->rebate = rebate_; 49 moreArgs->coverEventDate = coverEventDate_; 50 } 51 arguments()52 PartialTimeBarrierOption::arguments::arguments() 53 : barrierType(PartialBarrier::Type(-1)), 54 barrierRange(PartialBarrier::Range(-1)), 55 barrier(Null<Real>()), rebate(Null<Real>()), 56 coverEventDate(Null<Date>()) {} 57 validate() const58 void PartialTimeBarrierOption::arguments::validate() const { 59 OneAssetOption::arguments::validate(); 60 61 // checking barrier type and suitable barrier range 62 switch (barrierType) { 63 case PartialBarrier::DownIn: 64 case PartialBarrier::UpIn: 65 QL_REQUIRE(barrierRange == PartialBarrier::Start || 66 barrierRange == PartialBarrier::End, 67 "in-barrier requires Start or End range"); 68 break; 69 case PartialBarrier::DownOut: 70 case PartialBarrier::UpOut: 71 QL_REQUIRE(barrierRange == PartialBarrier::Start || 72 barrierRange == PartialBarrier::EndB1 || 73 barrierRange == PartialBarrier::EndB2, 74 "out-barrier requires Start, EndB1 or EndB2 range"); 75 break; 76 default: 77 QL_FAIL("unknown barrier type"); 78 } 79 80 QL_REQUIRE(barrier != Null<Real>(), "no barrier given"); 81 QL_REQUIRE(rebate != Null<Real>(), "no rebate given"); 82 QL_REQUIRE(coverEventDate != Null<Date>(), "no cover event date given"); 83 QL_REQUIRE(coverEventDate < exercise->lastDate(), 84 "cover event date equal or later than exercise date"); 85 } 86 87 } 88 89