QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdmdiscountdirichletboundary.cpp
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
23#include <ql/methods/finitedifferences/utilities/fdmdiscountdirichletboundary.hpp>
24#include <ql/termstructures/yieldtermstructure.hpp>
25#include <utility>
26
27namespace QuantLib {
28
29 namespace {
30 class DiscountedCashflowAtBoundary {
31 public:
32 DiscountedCashflowAtBoundary(Time maturityTime,
33 Real valueOnBoundary,
34 ext::shared_ptr<YieldTermStructure> rTS)
35 : maturityTime_(maturityTime), cashFlow_(valueOnBoundary), rTS_(std::move(rTS)) {}
36
37 Real operator()(Real t) const {
38 return cashFlow_
39 * rTS_->discount(maturityTime_)/rTS_->discount(t);
40 }
41
42 private:
43 const Time maturityTime_;
44 const Real cashFlow_;
45 const ext::shared_ptr<YieldTermStructure> rTS_;
46 };
47 }
48
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 : bc_(ext::make_shared<FdmTimeDepDirichletBoundary>(
56 mesher,
57 ext::function<Real (Real)>(
58 DiscountedCashflowAtBoundary(
59 maturityTime, valueOnBoundary, rTS)),
60 direction, side)) {
61 }
62
64 bc_->setTime(t);
65 }
67 operator_type& op) const {
68 bc_->applyBeforeApplying(op);
69 }
71 operator_type& op, array_type& r) const {
72 bc_->applyBeforeSolving(op, r);
73 }
75 bc_->applyAfterApplying(r);
76 }
78 bc_->applyAfterSolving(r);
79 }
80}
1-D array used in linear algebra.
Definition: array.hpp:52
FdmDiscountDirichletBoundary(const ext::shared_ptr< FdmMesher > &mesher, const ext::shared_ptr< YieldTermStructure > &rTS, Time maturityTime, Real valueOnBoundary, Size direction, Side side)
void applyAfterSolving(array_type &) const override
BoundaryCondition< FdmLinearOp >::Side Side
void applyAfterApplying(array_type &) const override
void applyBeforeApplying(operator_type &) const override
void applyBeforeSolving(operator_type &, array_type &) const override
const ext::shared_ptr< FdmTimeDepDirichletBoundary > bc_
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
STL namespace.