QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
cranknicolsonscheme.cpp
Go to the documentation of this file.
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
22
23namespace QuantLib {
25 Real theta,
26 const ext::shared_ptr<FdmLinearOpComposite> & map,
27 const bc_set& bcSet,
28 Real relTol,
30 : dt_(Null<Real>()),
32 explicit_(ext::make_shared<ExplicitEulerScheme>(map, bcSet)),
33 implicit_(ext::make_shared<ImplicitEulerScheme>(
34 map, bcSet, relTol, solverType)) {
35 }
36
38 QL_REQUIRE(t-dt_ > -1e-8, "a step towards negative time given");
39
40 if (theta_ != 1.0)
41 explicit_->step(a, t, 1.0-theta_);
42
43 if (theta_ != 0.0)
44 implicit_->step(a, t, theta_);
45 }
46
48 dt_ = dt;
49 explicit_->setStep(dt_);
50 implicit_->setStep(dt_);
51 }
52
54 return implicit_->numberOfIterations();
55 }
56}
CrankNicolsonScheme(Real theta, const ext::shared_ptr< FdmLinearOpComposite > &map, const bc_set &bcSet=bc_set(), Real relTol=1e-8, ImplicitEulerScheme::SolverType solverType=ImplicitEulerScheme::BiCGstab)
const ext::shared_ptr< ImplicitEulerScheme > implicit_
void step(array_type &a, Time t)
const ext::shared_ptr< ExplicitEulerScheme > explicit_
template class providing a null value for a given type.
Definition: null.hpp:76
Crank-Nicolson scheme.
const DefaultType & t
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
explicit-Euler scheme
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
Real theta
Definition: any.hpp:35