/src/quantlib/ql/methods/finitedifferences/utilities/fdmdiscountdirichletboundary.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) 2019 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 | | |
21 | | /*! \file fdmdiscountdirichletboundary.cpp */ |
22 | | |
23 | | #include <ql/methods/finitedifferences/utilities/fdmdiscountdirichletboundary.hpp> |
24 | | #include <ql/termstructures/yieldtermstructure.hpp> |
25 | | #include <utility> |
26 | | |
27 | | namespace QuantLib { |
28 | | |
29 | | namespace { |
30 | | class DiscountedCashflowAtBoundary { |
31 | | public: |
32 | | DiscountedCashflowAtBoundary(Time maturityTime, |
33 | | Real valueOnBoundary, |
34 | | ext::shared_ptr<YieldTermStructure> rTS) |
35 | 0 | : maturityTime_(maturityTime), cashFlow_(valueOnBoundary), rTS_(std::move(rTS)) {} |
36 | | |
37 | 0 | Real operator()(Real t) const { |
38 | 0 | return cashFlow_ |
39 | 0 | * rTS_->discount(maturityTime_)/rTS_->discount(t); |
40 | 0 | } |
41 | | |
42 | | private: |
43 | | const Time maturityTime_; |
44 | | const Real cashFlow_; |
45 | | const ext::shared_ptr<YieldTermStructure> rTS_; |
46 | | }; |
47 | | } |
48 | | |
49 | | FdmDiscountDirichletBoundary::FdmDiscountDirichletBoundary( |
50 | | const ext::shared_ptr<FdmMesher>& mesher, |
51 | | const ext::shared_ptr<YieldTermStructure>& rTS, |
52 | | Time maturityTime, |
53 | | Real valueOnBoundary, |
54 | | Size direction, Side side) |
55 | 0 | : bc_(ext::make_shared<FdmTimeDepDirichletBoundary>( |
56 | 0 | mesher, |
57 | 0 | std::function<Real (Real)>( |
58 | 0 | DiscountedCashflowAtBoundary( |
59 | 0 | maturityTime, valueOnBoundary, rTS)), |
60 | 0 | direction, side)) { |
61 | 0 | } |
62 | | |
63 | 0 | void FdmDiscountDirichletBoundary::setTime(Time t) { |
64 | 0 | bc_->setTime(t); |
65 | 0 | } |
66 | | void FdmDiscountDirichletBoundary::applyBeforeApplying( |
67 | 0 | operator_type& op) const { |
68 | 0 | bc_->applyBeforeApplying(op); |
69 | 0 | } |
70 | | void FdmDiscountDirichletBoundary::applyBeforeSolving( |
71 | 0 | operator_type& op, array_type& r) const { |
72 | 0 | bc_->applyBeforeSolving(op, r); |
73 | 0 | } |
74 | 0 | void FdmDiscountDirichletBoundary::applyAfterApplying(array_type& r) const { |
75 | 0 | bc_->applyAfterApplying(r); |
76 | 0 | } |
77 | 0 | void FdmDiscountDirichletBoundary::applyAfterSolving(array_type& r) const { |
78 | 0 | bc_->applyAfterSolving(r); |
79 | 0 | } |
80 | | } |