QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fdmhullwhiteop.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) 2011 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/*! \file fdmhullwhiteop.cpp */
21
22
29
30namespace QuantLib {
31
33 const ext::shared_ptr<FdmMesher>& mesher,
34 const ext::shared_ptr<HullWhite>& model,
35 Size direction)
36 : direction_(direction),
37 x_(mesher->locations(direction)),
38 dzMap_(FirstDerivativeOp(direction, mesher).mult(-x_*model->a()).add(
39 SecondDerivativeOp(direction, mesher)
40 .mult(0.5*model->sigma()*model->sigma()
41 *Array(mesher->layout()->size(), 1.0)))),
42 mapT_(direction, mesher),
43 model_(model) {
44 }
45
46 Size FdmHullWhiteOp::size() const { return 1U; }
47
49
50 const ext::shared_ptr<OneFactorModel::ShortRateDynamics> dynamics =
51 model_->dynamics();
52
53 const Real phi = 0.5*( dynamics->shortRate(t1, 0.0)
54 + dynamics->shortRate(t2, 0.0));
55
56 mapT_.axpyb(Array(), dzMap_, dzMap_, -(x_+phi));
57 }
58
60 return mapT_.apply(r);
61 }
62
64 return Array(r.size(), 0.0);
65 }
66
68 if (direction == direction_)
69 return mapT_.apply(r);
70 else {
71 return Array(r.size(), 0.0);
72 }
73 }
74
75 Array FdmHullWhiteOp::solve_splitting(Size direction, const Array& r, Real a) const {
76 if (direction == direction_) {
77 return mapT_.solve_splitting(r, a, 1.0);
78 }
79 else {
80 return Array(r.size(), 0.0);
81 }
82 }
83
85 return solve_splitting(direction_, r, dt);
86 }
87
88 std::vector<SparseMatrix> FdmHullWhiteOp::toMatrixDecomp() const {
89 return std::vector<SparseMatrix>(1, mapT_.toMatrix());
90 }
91
92}
93
1-D array used in linear algebra.
Definition: array.hpp:52
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
const TripleBandLinearOp dzMap_
FdmHullWhiteOp(const ext::shared_ptr< FdmMesher > &mesher, const ext::shared_ptr< HullWhite > &model, Size direction)
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
const ext::shared_ptr< HullWhite > model_
SparseMatrix toMatrix() const override
Array solve_splitting(const Array &r, Real a, Real b=1.0) const
void axpyb(const Array &a, const TripleBandLinearOp &x, const TripleBandLinearOp &y, const Array &b)
Array apply(const Array &r) const override
FDM operator for the Hull-White interest rate model.
memory layout of a fdm linear operator
mesher for a fdm grid
const Size direction_
first derivative linear operator
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 sigma
Hull & White (HW) model.
Definition: any.hpp:35
ext::shared_ptr< YieldTermStructure > r
second derivative operator
std::uint64_t x_