QuantLib
: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
ql
methods
finitedifferences
bsmoperator.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) 2000, 2001, 2002, 2003 RiskMap srl
5
Copyright (C) 2003, 2004, 2005, 2006 StatPro Italia srl
6
7
This file is part of QuantLib, a free-software/open-source library
8
for financial quantitative analysts and developers - http://quantlib.org/
9
10
QuantLib is free software: you can redistribute it and/or modify it
11
under the terms of the QuantLib license. You should have received a
12
copy of the license along with this program; if not, please email
13
<quantlib-dev@lists.sf.net>. The license is also available online at
14
<http://quantlib.org/license.shtml>.
15
16
This program is distributed in the hope that it will be useful, but WITHOUT
17
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
FOR A PARTICULAR PURPOSE. See the license for more details.
19
*/
20
21
#include <
ql/methods/finitedifferences/bsmoperator.hpp
>
22
#include <
ql/math/transformedgrid.hpp
>
23
#include <
ql/methods/finitedifferences/pdebsm.hpp
>
24
25
namespace
QuantLib
{
26
27
BSMOperator::BSMOperator
(
Size
size,
Real
dx,
Rate
r
,
28
Rate
q
,
Volatility
sigma
)
29
:
TridiagonalOperator
(size) {
30
Real
sigma2 =
sigma
*
sigma
;
31
Real
nu
=
r
-
q
-sigma2/2;
32
Real
pd = -(sigma2/dx-
nu
)/(2*dx);
33
Real
pu = -(sigma2/dx+
nu
)/(2*dx);
34
Real
pm = sigma2/(dx*dx)+
r
;
35
setMidRows
(pd,pm,pu);
36
}
37
38
BSMOperator::BSMOperator
(
const
Array
& grid,
39
Rate
r
,
Rate
q
,
Volatility
sigma
)
40
:
TridiagonalOperator
(grid.size()) {
41
PdeBSM::grid_type
logGrid(grid);
42
Real
sigma2 =
sigma
*
sigma
;
43
Real
nu
=
r
-
q
-sigma2/2;
44
for
(
Size
i=1; i<logGrid.
size
()-1; ++i) {
45
Real
pd = -(sigma2/logGrid.
dxm
(i)-
nu
)/logGrid.
dx
(i);
46
Real
pu = -(sigma2/logGrid.
dxp
(i)+
nu
)/logGrid.
dx
(i);
47
Real
pm = sigma2/(logGrid.
dxm
(i)*logGrid.
dxp
(i)) +
r
;
48
setMidRow
(i,pd,pm,pu);
49
}
50
}
51
52
}
bsmoperator.hpp
differential operator for Black-Scholes-Merton equation
QuantLib::Array
1-D array used in linear algebra.
Definition:
array.hpp:52
QuantLib::BSMOperator::BSMOperator
BSMOperator()=default
QuantLib::LogGrid
Definition:
transformedgrid.hpp:96
QuantLib::TransformedGrid::dxp
Real dxp(Size i) const
Definition:
transformedgrid.hpp:84
QuantLib::TransformedGrid::dx
Real dx(Size i) const
Definition:
transformedgrid.hpp:85
QuantLib::TransformedGrid::size
Size size() const
Definition:
transformedgrid.hpp:86
QuantLib::TransformedGrid::dxm
Real dxm(Size i) const
Definition:
transformedgrid.hpp:83
QuantLib::TridiagonalOperator
Base implementation for tridiagonal operator.
Definition:
tridiagonaloperator.hpp:42
QuantLib::TridiagonalOperator::setMidRows
void setMidRows(Real, Real, Real)
Definition:
tridiagonaloperator.hpp:161
QuantLib::TridiagonalOperator::setMidRow
void setMidRow(Size, Real, Real, Real)
Definition:
tridiagonaloperator.hpp:150
QuantLib::Real
QL_REAL Real
real number
Definition:
types.hpp:50
QuantLib::Volatility
Real Volatility
volatility
Definition:
types.hpp:78
QuantLib::Rate
Real Rate
interest rates
Definition:
types.hpp:70
QuantLib::Size
std::size_t Size
size of a container
Definition:
types.hpp:58
sigma
Real sigma
Definition:
hestonrndcalculator.cpp:36
QuantLib
Definition:
any.hpp:35
pdebsm.hpp
Black-Scholes-Merton PDE.
q
ext::shared_ptr< YieldTermStructure > q
Definition:
perturbativebarrieroptionengine.cpp:1464
r
ext::shared_ptr< YieldTermStructure > r
Definition:
perturbativebarrieroptionengine.cpp:1454
nu
Real nu
Definition:
sabr.cpp:200
transformedgrid.hpp
encapuslates a grid
Generated by
Doxygen
1.9.5