| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl |
| 5 | Copyright (C) 2001, 2002, 2003 Sadruddin Rejeb |
| 6 | Copyright (C) 2003 Ferdinando Ametrano |
| 7 | |
| 8 | This file is part of QuantLib, a free-software/open-source library |
| 9 | for financial quantitative analysts and developers - http://quantlib.org/ |
| 10 | |
| 11 | QuantLib is free software: you can redistribute it and/or modify it |
| 12 | under the terms of the QuantLib license. You should have received a |
| 13 | copy of the license along with this program; if not, please email |
| 14 | <quantlib-dev@lists.sf.net>. The license is also available online at |
| 15 | <http://quantlib.org/license.shtml>. |
| 16 | |
| 17 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 | FOR A PARTICULAR PURPOSE. See the license for more details. |
| 20 | */ |
| 21 | |
| 22 | #include <ql/exercise.hpp> |
| 23 | #include <ql/errors.hpp> |
| 24 | #include <algorithm> |
| 25 | |
| 26 | namespace QuantLib { |
| 27 | |
| 28 | Date Exercise::lastDate() const { |
| 29 | QL_REQUIRE(!dates_.empty(), "no exercise date given" ); |
| 30 | return dates_.back(); |
| 31 | } |
| 32 | |
| 33 | AmericanExercise::AmericanExercise(const Date& earliest, |
| 34 | const Date& latest, |
| 35 | bool payoffAtExpiry) |
| 36 | : EarlyExercise(American, payoffAtExpiry) { |
| 37 | QL_REQUIRE(earliest<=latest, |
| 38 | "earliest > latest exercise date" ); |
| 39 | dates_ = std::vector<Date>(2); |
| 40 | dates_[0] = earliest; |
| 41 | dates_[1] = latest; |
| 42 | } |
| 43 | |
| 44 | AmericanExercise::AmericanExercise(const Date& latest, |
| 45 | bool payoffAtExpiry) |
| 46 | : EarlyExercise(American, payoffAtExpiry) { |
| 47 | dates_ = std::vector<Date>(2); |
| 48 | dates_[0] = Date::minDate(); |
| 49 | dates_[1] = latest; |
| 50 | } |
| 51 | |
| 52 | BermudanExercise::BermudanExercise(const std::vector<Date>& dates, |
| 53 | bool payoffAtExpiry) |
| 54 | : EarlyExercise(Bermudan, payoffAtExpiry) { |
| 55 | QL_REQUIRE(!dates.empty(), "no exercise date given" ); |
| 56 | dates_ = dates; |
| 57 | std::sort(first: dates_.begin(), last: dates_.end()); |
| 58 | } |
| 59 | |
| 60 | EuropeanExercise::EuropeanExercise(const Date& date) |
| 61 | : Exercise(European) { |
| 62 | dates_ = std::vector<Date>(1,date); |
| 63 | } |
| 64 | |
| 65 | } |
| 66 | |