QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
methodoflinesscheme.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) 2018 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#include <utility>
23
24namespace QuantLib {
25
27 const Real relInitStepSize,
28 ext::shared_ptr<FdmLinearOpComposite> map,
29 const bc_set& bcSet)
30 : dt_(Null<Real>()), eps_(eps), relInitStepSize_(relInitStepSize), map_(std::move(map)),
31 bcSet_(bcSet) {}
32
33
34 std::vector<Real> MethodOfLinesScheme::apply(Time t, const std::vector<Real>& u) const {
35 map_->setTime(t, t + 0.0001);
37
38 const Array dxdt = -map_->apply(Array(u.begin(), u.end()));
39
40 return std::vector<Real>(dxdt.begin(), dxdt.end());
41 }
42
44 QL_REQUIRE(t-dt_ > -1e-8, "a step towards negative time given");
45
46 const std::vector<Real> v =
48 [&](Time _t, const std::vector<Real>& _u){ return apply(_t, _u); },
49 std::vector<Real>(a.begin(), a.end()),
50 t, std::max(0.0, t-dt_));
51
52 Array y(v.begin(), v.end());
53
55
56 a = y;
57 }
58
60 dt_ = dt;
61 }
62}
Runge-Kutta ODE integration.
1-D array used in linear algebra.
Definition: array.hpp:52
const_iterator end() const
Definition: array.hpp:511
const_iterator begin() const
Definition: array.hpp:503
const BoundaryConditionSchemeHelper bcSet_
const ext::shared_ptr< FdmLinearOpComposite > map_
MethodOfLinesScheme(Real eps, Real relInitStepSize, ext::shared_ptr< FdmLinearOpComposite > map, const bc_set &bcSet=bc_set())
void step(array_type &a, Time t)
std::vector< Real > apply(Time, const std::vector< Real > &) const
template class providing a null value for a given type.
Definition: null.hpp:76
const DefaultType & t
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Method of Lines scheme.
Definition: any.hpp:35
STL namespace.
ext::shared_ptr< BlackVolTermStructure > v