/src/quantlib/ql/rebatedexercise.hpp
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) 2013 Peter Caspers |
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 | | /*! \file rebatedexercise.hpp |
21 | | \brief Option exercise with rebate payments |
22 | | */ |
23 | | |
24 | | #ifndef quantlib_rebatedexercise_hpp |
25 | | #define quantlib_rebatedexercise_hpp |
26 | | |
27 | | #include <ql/exercise.hpp> |
28 | | #include <ql/time/calendars/nullcalendar.hpp> |
29 | | #include <ql/errors.hpp> |
30 | | |
31 | | namespace QuantLib { |
32 | | |
33 | | //! Rebated exercise |
34 | | /*! in case of exercise the holder receives a rebate (if positive) or pays |
35 | | it (if negative) |
36 | | on the rebate settlement date |
37 | | */ |
38 | | class RebatedExercise : public Exercise { |
39 | | public: |
40 | | // in case of exercise the holder receives the rebate |
41 | | // (if positive) or pays it (if negative) on the rebate |
42 | | // settlement date |
43 | | RebatedExercise(const Exercise& exercise, |
44 | | Real rebate = 0.0, |
45 | | Natural rebateSettlementDays = 0, |
46 | | Calendar rebatePaymentCalendar = NullCalendar(), |
47 | | BusinessDayConvention rebatePaymentConvention = Following); |
48 | | RebatedExercise(const Exercise& exercise, |
49 | | const std::vector<Real>& rebates, |
50 | | Natural rebateSettlementDays = 0, |
51 | | Calendar rebatePaymentCalendar = NullCalendar(), |
52 | | BusinessDayConvention rebatePaymentConvention = Following); |
53 | | Real rebate(Size index) const; |
54 | | Date rebatePaymentDate(Size index) const; |
55 | 0 | const std::vector<Real> &rebates() const { return rebates_; } |
56 | | |
57 | | private: |
58 | | const std::vector<Real> rebates_; |
59 | | const Natural rebateSettlementDays_; |
60 | | const Calendar rebatePaymentCalendar_; |
61 | | const BusinessDayConvention rebatePaymentConvention_; |
62 | | }; |
63 | | |
64 | 0 | inline Real RebatedExercise::rebate(Size index) const { |
65 | 0 | QL_REQUIRE(index < rebates_.size(), |
66 | 0 | "rebate with index " << index << " does not exist (0..." |
67 | 0 | << (rebates_.size()-1) << ")"); |
68 | 0 | return rebates_[index]; |
69 | 0 | } |
70 | | |
71 | 0 | inline Date RebatedExercise::rebatePaymentDate(Size index) const { |
72 | 0 | QL_REQUIRE(type_ == European || type_ == Bermudan, |
73 | 0 | "for american style exercises the rebate payment date " |
74 | 0 | << "has to be calculted in the client code"); |
75 | 0 | return rebatePaymentCalendar_.advance(dates_[index], |
76 | 0 | rebateSettlementDays_, Days, |
77 | 0 | rebatePaymentConvention_); |
78 | 0 | } |
79 | | |
80 | | } |
81 | | |
82 | | #endif |