/src/quantlib/ql/exercise.cpp
Line | Count | Source (jump to first uncovered line) |
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 | 508k | Date Exercise::lastDate() const { |
29 | 508k | QL_REQUIRE(!dates_.empty(), "no exercise date given"); |
30 | 508k | return dates_.back(); |
31 | 508k | } |
32 | | |
33 | | AmericanExercise::AmericanExercise(const Date& earliest, |
34 | | const Date& latest, |
35 | | bool payoffAtExpiry) |
36 | 508k | : EarlyExercise(American, payoffAtExpiry) { |
37 | 508k | QL_REQUIRE(earliest<=latest, |
38 | 508k | "earliest > latest exercise date"); |
39 | 508k | dates_ = std::vector<Date>(2); |
40 | 508k | dates_[0] = earliest; |
41 | 508k | dates_[1] = latest; |
42 | 508k | } |
43 | | |
44 | | AmericanExercise::AmericanExercise(const Date& latest, |
45 | | bool payoffAtExpiry) |
46 | 0 | : EarlyExercise(American, payoffAtExpiry) { |
47 | 0 | dates_ = std::vector<Date>(2); |
48 | 0 | dates_[0] = Date::minDate(); |
49 | 0 | dates_[1] = latest; |
50 | 0 | } |
51 | | |
52 | | BermudanExercise::BermudanExercise(const std::vector<Date>& dates, |
53 | | bool payoffAtExpiry) |
54 | 0 | : EarlyExercise(Bermudan, payoffAtExpiry) { |
55 | 0 | QL_REQUIRE(!dates.empty(), "no exercise date given"); |
56 | 0 | dates_ = dates; |
57 | 0 | std::sort(dates_.begin(), dates_.end()); |
58 | 0 | } |
59 | | |
60 | | EuropeanExercise::EuropeanExercise(const Date& date) |
61 | 0 | : Exercise(European) { |
62 | 0 | dates_ = std::vector<Date>(1,date); |
63 | 0 | } |
64 | | |
65 | | } |