QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
bsmoperator.cpp
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
25namespace QuantLib {
26
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
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}
1-D array used in linear algebra.
Definition: array.hpp:52
Base implementation for tridiagonal operator.
void setMidRow(Size, Real, Real, Real)
QL_REAL Real
real number
Definition: types.hpp:50
Real Volatility
volatility
Definition: types.hpp:78
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35