QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdm2dblackscholessolver.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2010 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#include <ql/methods/finitedifferences/operators/fdm2dblackscholesop.hpp>
21#include <ql/methods/finitedifferences/solvers/fdm2dblackscholessolver.hpp>
22#include <ql/methods/finitedifferences/solvers/fdm2dimsolver.hpp>
23#include <ql/processes/blackscholesprocess.hpp>
24#include <utility>
25
26namespace QuantLib {
27
30 const Real correlation,
31 FdmSolverDesc solverDesc,
32 const FdmSchemeDesc& schemeDesc,
33 bool localVol,
34 Real illegalLocalVolOverwrite)
35 : p1_(std::move(p1)), p2_(std::move(p2)), correlation_(correlation),
36 solverDesc_(std::move(solverDesc)), schemeDesc_(schemeDesc), localVol_(localVol),
37 illegalLocalVolOverwrite_(illegalLocalVolOverwrite) {
38
41 }
42
43
45
46 ext::shared_ptr<Fdm2dBlackScholesOp> op(
47 ext::make_shared<Fdm2dBlackScholesOp>(solverDesc_.mesher,
48 p1_.currentLink(),
49 p2_.currentLink(),
54
55 solver_ = ext::make_shared<Fdm2DimSolver>(solverDesc_, schemeDesc_, op);
56 }
57
59 calculate();
60 const Real x = std::log(u);
61 const Real y = std::log(v);
62
63 return solver_->interpolateAt(x, y);
64 }
65
67 calculate();
68 const Real x = std::log(u);
69 const Real y = std::log(v);
70 return solver_->thetaAt(x, y);
71 }
72
73
75 calculate();
76
77 const Real x = std::log(u);
78 const Real y = std::log(v);
79
80 return solver_->derivativeX(x, y)/u;
81 }
82
84 calculate();
85
86 const Real x = std::log(u);
87 const Real y = std::log(v);
88
89 return solver_->derivativeY(x, y)/v;
90 }
91
93 calculate();
94
95 const Real x = std::log(u);
96 const Real y = std::log(v);
97
98 return (solver_->derivativeXX(x, y)
99 -solver_->derivativeX(x, y))/(u*u);
100 }
101
103 calculate();
104
105 const Real x = std::log(u);
106 const Real y = std::log(v);
107
108 return (solver_->derivativeYY(x, y)
109 -solver_->derivativeY(x, y))/(v*v);
110 }
111
113 calculate();
114
115 const Real x = std::log(u);
116 const Real y = std::log(v);
117
118 return solver_->derivativeXY(x, y)/(u*v);
119 }
120}
const Handle< GeneralizedBlackScholesProcess > p2_
ext::shared_ptr< Fdm2DimSolver > solver_
Fdm2dBlackScholesSolver(Handle< GeneralizedBlackScholesProcess > p1, Handle< GeneralizedBlackScholesProcess > p2, Real correlation, FdmSolverDesc solverDesc, const FdmSchemeDesc &schemeDesc=FdmSchemeDesc::Hundsdorfer(), bool localVol=false, Real illegalLocalVolOverwrite=-Null< Real >())
const Handle< GeneralizedBlackScholesProcess > p1_
Shared handle to an observable.
Definition: handle.hpp:41
virtual void calculate() const
Definition: lazyobject.hpp:253
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
STL namespace.
const ext::shared_ptr< FdmMesher > mesher