/src/quantlib/ql/methods/finitedifferences/utilities/escroweddividendadjustment.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) 2021 Klaus Spanderen |
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 | | <https://www.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 escroweddividendadjustment.cpp |
21 | | */ |
22 | | #include <ql/methods/finitedifferences/utilities/escroweddividendadjustment.hpp> |
23 | | |
24 | | namespace QuantLib { |
25 | | |
26 | | EscrowedDividendAdjustment::EscrowedDividendAdjustment( |
27 | | DividendSchedule dividendSchedule, |
28 | | Handle<YieldTermStructure> rTS, |
29 | | Handle<YieldTermStructure> qTS, |
30 | | std::function<Real(Date)> toTime, |
31 | | Time maturity) |
32 | 0 | : dividendSchedule_(std::move(dividendSchedule)), |
33 | 0 | rTS_(std::move(rTS)), qTS_(std::move(qTS)), |
34 | 0 | toTime_(std::move(toTime)), maturity_(maturity) {} |
35 | | |
36 | | |
37 | 0 | Real EscrowedDividendAdjustment::dividendAdjustment(Time t) const { |
38 | |
|
39 | 0 | Real divAdj = 0.0; |
40 | 0 | for (auto const& dividend: dividendSchedule_) { |
41 | 0 | const Time divTime = toTime_(dividend->date()); |
42 | |
|
43 | 0 | if (divTime >= t && t <= maturity_) |
44 | 0 | divAdj -= dividend->amount() |
45 | 0 | * rTS_->discount(divTime) / rTS_->discount(t) |
46 | 0 | * qTS_->discount(t) / qTS_->discount(divTime); |
47 | 0 | } |
48 | |
|
49 | 0 | return divAdj; |
50 | 0 | } |
51 | | |
52 | | const Handle<YieldTermStructure>& |
53 | 0 | EscrowedDividendAdjustment::riskFreeRate() const { |
54 | 0 | return rTS_; |
55 | 0 | } |
56 | | |
57 | | const Handle<YieldTermStructure>& |
58 | 0 | EscrowedDividendAdjustment::dividendYield() const { |
59 | 0 | return qTS_; |
60 | 0 | } |
61 | | } |