QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
exercise.cpp
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
26namespace QuantLib {
27
29 QL_REQUIRE(!dates_.empty(), "no exercise date given");
30 return dates_.back();
31 }
32
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
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(dates_.begin(), dates_.end());
58 }
59
61 : Exercise(European) {
62 dates_ = std::vector<Date>(1,date);
63 }
64
65}
AmericanExercise(const Date &earliestDate, const Date &latestDate, bool payoffAtExpiry=false)
Definition: exercise.cpp:33
BermudanExercise(const std::vector< Date > &dates, bool payoffAtExpiry=false)
Definition: exercise.cpp:52
Concrete date class.
Definition: date.hpp:125
static Date minDate()
earliest allowed date
Definition: date.cpp:766
Early-exercise base class.
Definition: exercise.hpp:57
EuropeanExercise(const Date &date)
Definition: exercise.cpp:60
Base exercise class.
Definition: exercise.hpp:35
std::vector< Date > dates_
Definition: exercise.hpp:51
Date date(Size index) const
Definition: exercise.hpp:45
const std::vector< Date > & dates() const
Returns all exercise dates.
Definition: exercise.hpp:48
Date lastDate() const
Definition: exercise.cpp:28
Definition: any.hpp:35