QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fdmdupire1dop.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) 2014 Peter Caspers
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 <boost/numeric/ublas/matrix.hpp>
23
24namespace QuantLib {
25
26FdmDupire1dOp::FdmDupire1dOp(const ext::shared_ptr<FdmMesher> &mesher,
27 const Array &localVolatility)
28 : mesher_(mesher), localVolatility_(localVolatility),
29 mapT_(SecondDerivativeOp(0, mesher)
30 .mult(0.5 * localVolatility * localVolatility)) {}
31
33
34Size FdmDupire1dOp::size() const { return 1; }
35
37 return mapT_.apply(u);
38}
39
41 if (direction == 0)
42 return mapT_.apply(r);
43 QL_FAIL("direction too large");
44}
45
47 return r;
48}
49
50Array FdmDupire1dOp::solve_splitting(Size direction, const Array &r, Real a) const {
51 if (direction == 0) {
52 return mapT_.solve_splitting(r, a, 1.0);
53 }
54 QL_FAIL("direction too large");
55}
56
58
59 return solve_splitting(0, r, dt);
60}
61
62std::vector<SparseMatrix> FdmDupire1dOp::toMatrixDecomp() const {
63 return std::vector<SparseMatrix>(1, mapT_.toMatrix());
64}
65
66}
1-D array used in linear algebra.
Definition: array.hpp:52
FdmDupire1dOp(const ext::shared_ptr< FdmMesher > &mesher, const Array &localVolatility)
Size size() const override
Array apply_direction(Size direction, const Array &r) const override
Array preconditioner(const Array &r, Real s) const override
std::vector< SparseMatrix > toMatrixDecomp() const override
void setTime(Time t1, Time t2) override
Time is required.
Array apply_mixed(const Array &r) const override
TripleBandLinearOp mapT_
Array solve_splitting(Size direction, const Array &r, Real s) const override
Array apply(const Array &r) const override
SparseMatrix toMatrix() const override
Array solve_splitting(const Array &r, Real a, Real b=1.0) const
Array apply(const Array &r) const override
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
Dupire local volatility pricing operator Note that time is reversed in order to make backward solvers...
const ext::shared_ptr< FdmMesher > mesher_
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
ext::shared_ptr< YieldTermStructure > r
second derivative operator