QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdmhestonhullwhitesolver.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2009 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/fdmhestonhullwhiteop.hpp>
21#include <ql/methods/finitedifferences/solvers/fdm3dimsolver.hpp>
22#include <ql/methods/finitedifferences/solvers/fdmhestonhullwhitesolver.hpp>
23#include <ql/methods/finitedifferences/utilities/fdmquantohelper.hpp>
24#include <utility>
25
26namespace QuantLib {
27
29 const Handle<HullWhiteProcess>& hwProcess,
30 Rate corrEquityShortRate,
31 FdmSolverDesc solverDesc,
32 const FdmSchemeDesc& schemeDesc)
33 : hestonProcess_(hestonProcess), hwProcess_(hwProcess),
34 corrEquityShortRate_(corrEquityShortRate), solverDesc_(std::move(solverDesc)),
35 schemeDesc_(schemeDesc) {
36
37 registerWith(hestonProcess);
38 registerWith(hwProcess);
39 }
40
42 const ext::shared_ptr<FdmLinearOpComposite> op(
43 ext::make_shared<FdmHestonHullWhiteOp>(solverDesc_.mesher,
44 hestonProcess_.currentLink(),
45 hwProcess_.currentLink(),
47
48 solver_ = ext::make_shared<Fdm3DimSolver>(solverDesc_, schemeDesc_, op);
49 }
50
52 calculate();
53
54 const Real x = std::log(s);
55 return solver_->interpolateAt(x, v, r);
56 }
57
59 const {
60 return (valueAt(s+eps, v, r) - valueAt(s-eps, v, r))/(2*eps);
61 }
62
64 const {
65 return (valueAt(s+eps, v, r)+valueAt(s-eps, v,r )
66 -2*valueAt(s, v, r))/(eps*eps);
67 }
68
70 calculate();
71
72 const Real x = std::log(s);
73 return solver_->thetaAt(x, v, r);
74 }
75}
Real gammaAt(Real s, Real v, Rate r, Real eps) const
Real thetaAt(Real s, Real v, Rate r) const
Real valueAt(Real s, Real v, Rate r) const
const Handle< HullWhiteProcess > hwProcess_
const Handle< HestonProcess > hestonProcess_
FdmHestonHullWhiteSolver(const Handle< HestonProcess > &hestonProcess, const Handle< HullWhiteProcess > &hwProcess, Rate corrEquityShortRate, FdmSolverDesc solverDesc, const FdmSchemeDesc &schemeDesc=FdmSchemeDesc::Hundsdorfer())
ext::shared_ptr< Fdm3DimSolver > solver_
Real deltaAt(Real s, Real v, Rate r, Real eps) const
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
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
STL namespace.
const ext::shared_ptr< FdmMesher > mesher