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