1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2001, 2002, 2003 Sadruddin Rejeb
5 Copyright (C) 2003 Ferdinando Ametrano
6 Copyright (C) 2006 StatPro Italia srl
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/*! \file exercise.hpp
23 \brief Option exercise classes and payoff function
24*/
25
26#ifndef quantlib_exercise_type_h
27#define quantlib_exercise_type_h
28
29#include <ql/time/date.hpp>
30#include <vector>
31
32namespace QuantLib {
33
34 //! Base exercise class
35 class Exercise {
36 public:
37 enum Type {
38 American, Bermudan, European
39 };
40 // constructor
41 explicit Exercise(Type type) : type_(type) {}
42 virtual ~Exercise() = default;
43 // inspectors
44 Type type() const { return type_; }
45 Date date(Size index) const { return dates_[index]; }
46 Date dateAt(Size index) const { return dates_.at(n: index); }
47 //! Returns all exercise dates
48 const std::vector<Date>& dates() const { return dates_; }
49 Date lastDate() const;
50 protected:
51 std::vector<Date> dates_;
52 Type type_;
53 };
54
55 //! Early-exercise base class
56 /*! The payoff can be at exercise (the default) or at expiry */
57 class EarlyExercise : public Exercise {
58 public:
59 EarlyExercise(Type type,
60 bool payoffAtExpiry = false)
61 : Exercise(type), payoffAtExpiry_(payoffAtExpiry) {}
62 bool payoffAtExpiry() const { return payoffAtExpiry_; }
63 private:
64 bool payoffAtExpiry_;
65 };
66
67 //! American exercise
68 /*! An American option can be exercised at any time between two
69 predefined dates; the first date might be omitted, in which
70 case the option can be exercised at any time before the expiry.
71
72 \todo check that everywhere the American condition is applied
73 from earliestDate and not earlier
74 */
75 class AmericanExercise : public EarlyExercise {
76 public:
77 AmericanExercise(const Date& earliestDate,
78 const Date& latestDate,
79 bool payoffAtExpiry = false);
80 AmericanExercise(const Date& latestDate,
81 bool payoffAtExpiry = false);
82 };
83
84 //! Bermudan exercise
85 /*! A Bermudan option can only be exercised at a set of fixed dates.
86 */
87 class BermudanExercise : public EarlyExercise {
88 public:
89 BermudanExercise(const std::vector<Date>& dates,
90 bool payoffAtExpiry = false);
91 };
92
93 //! European exercise
94 /*! A European option can only be exercised at one (expiry) date.
95 */
96 class EuropeanExercise : public Exercise {
97 public:
98 EuropeanExercise(const Date& date);
99 };
100
101}
102
103
104#endif
105

source code of quantlib/ql/exercise.hpp