QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fdmextendedornsteinuhlenbeckop.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 fdmextendedornsteinuhlenbeckop.cpp
21*/
22
31#include <utility>
32
33namespace QuantLib {
34
36 const ext::shared_ptr<FdmMesher>& mesher,
37 ext::shared_ptr<ExtendedOrnsteinUhlenbeckProcess> process,
38 ext::shared_ptr<YieldTermStructure> rTS,
40 Size direction)
41 : mesher_(mesher), process_(std::move(process)), rTS_(std::move(rTS)), bcSet_(std::move(bcSet)),
42 direction_(direction), x_(mesher->locations(direction)), dxMap_(direction, mesher),
43 dxxMap_(SecondDerivativeOp(direction, mesher)
44 .mult(0.5 * squared(process_->volatility()) *
45 Array(mesher->layout()->size(), 1.))),
46 mapX_(direction, mesher) {}
47
49 return mesher_->layout()->dim().size();;
50 }
51
53 const Rate r = rTS_->forwardRate(t1, t2, Continuous).rate();
54
55 Array drift(mesher_->layout()->size());
56 for (const auto& iter : *mesher_->layout()) {
57 const Size i = iter.index();
58 drift[i] = process_->drift(0.5*(t1+t2), x_[i]);
59 }
60 mapX_.axpyb(drift, dxMap_, dxxMap_, Array(1, -r));
61 }
62
64 return mapX_.apply(r);
65 }
66
68 return Array(r.size(), 0.0);
69 }
70
72 Size direction, const Array& r) const {
73 if (direction == direction_) {
74 return mapX_.apply(r);
75 }
76 else {
77 return Array(r.size(), 0.0);
78 }
79 }
80
82 Size direction, const Array& r, Real a) const {
83 if (direction == direction_) {
84 return mapX_.solve_splitting(r, a, 1.0);
85 }
86 else {
87 return r;
88 }
89 }
90
92 const Array& r, Real dt) const {
93 return solve_splitting(direction_, r, dt);
94 }
95
96 std::vector<SparseMatrix> FdmExtendedOrnsteinUhlenbeckOp::toMatrixDecomp() const {
97 return std::vector<SparseMatrix>(1, mapX_.toMatrix());
98 }
99
100}
1-D array used in linear algebra.
Definition: array.hpp:52
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.
FdmExtendedOrnsteinUhlenbeckOp(const ext::shared_ptr< FdmMesher > &mesher, ext::shared_ptr< ExtendedOrnsteinUhlenbeckProcess > p, ext::shared_ptr< YieldTermStructure > rTS, FdmBoundaryConditionSet bcSet, Size direction=0)
Array apply_mixed(const Array &r) const override
Array solve_splitting(Size direction, const Array &r, Real s) const override
const ext::shared_ptr< YieldTermStructure > rTS_
const ext::shared_ptr< ExtendedOrnsteinUhlenbeckProcess > process_
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
extended Ornstein-Uhlenbeck process
const ext::shared_ptr< YieldTermStructure > rTS_
Ornstein Uhlenbeck process plus jumps (Kluge Model)
memory layout of a fdm linear operator
mesher for a fdm grid
const ext::shared_ptr< FdmMesher > mesher_
const Size direction_
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
linear interpolation between discrete points
functionals and combinators not included in the STL
Definition: any.hpp:35
T squared(T x)
Definition: functional.hpp:37
OperatorTraits< FdmLinearOp >::bc_set FdmBoundaryConditionSet
STL namespace.
ext::shared_ptr< YieldTermStructure > r
second derivative operator
std::uint64_t x_
Interest-rate term structure.