QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fdmhestonsolver.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) 2008 Andreas Gaida
5 Copyright (C) 2008, 2009 Ralph Schreyer
6 Copyright (C) 2008, 2009, 2011, 2014, 2015 Klaus Spanderen
7 Copyright (C) 2015 Johannes Göttker-Schnetmann
8
9 This file is part of QuantLib, a free-software/open-source library
10 for financial quantitative analysts and developers - http://quantlib.org/
11
12 QuantLib is free software: you can redistribute it and/or modify it
13 under the terms of the QuantLib license. You should have received a
14 copy of the license along with this program; if not, please email
15 <quantlib-dev@lists.sf.net>. The license is also available online at
16 <http://quantlib.org/license.shtml>.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the license for more details.
21*/
22
27#include <utility>
28
29namespace QuantLib {
30
32 FdmSolverDesc solverDesc,
33 const FdmSchemeDesc& schemeDesc,
34 Handle<FdmQuantoHelper> quantoHelper,
35 ext::shared_ptr<LocalVolTermStructure> leverageFct,
36 const Real mixingFactor)
37 : process_(std::move(process)), solverDesc_(std::move(solverDesc)), schemeDesc_(schemeDesc),
38 quantoHelper_(std::move(quantoHelper)), leverageFct_(std::move(leverageFct)),
39 mixingFactor_(mixingFactor) {
40
43 }
44
46 ext::shared_ptr<FdmLinearOpComposite> op(
47 ext::make_shared<FdmHestonOp>(
48 solverDesc_.mesher, process_.currentLink(),
49 (!quantoHelper_.empty()) ? quantoHelper_.currentLink()
50 : ext::shared_ptr<FdmQuantoHelper>(),
52
53 solver_ = ext::make_shared<Fdm2DimSolver>(solverDesc_, schemeDesc_, op);
54 }
55
57 calculate();
58 return solver_->interpolateAt(std::log(s), v);
59 }
60
62 calculate();
63 return solver_->derivativeX(std::log(s), v)/s;
64 }
65
67 calculate();
68 const Real x = std::log(s);
69 return (solver_->derivativeXX(x, v)-solver_->derivativeX(x, v))/(s*s);
70 }
71
73 calculate();
74
75 const Real alpha = process_->rho()*process_->sigma()/s;
76 return deltaAt(s, v) + alpha*solver_->derivativeY(std::log(s), v);
77 }
78
80 calculate();
81
82 const Real x = std::log(s);
83 const Real alpha = process_->rho()*process_->sigma()/s;
84 return gammaAt(s, v)
85 + solver_->derivativeYY(x, v)*alpha*alpha
86 +2*solver_->derivativeXY(x, v)*alpha/s;
87 }
88
90 calculate();
91 return solver_->thetaAt(std::log(s), v);
92 }
93}
ext::shared_ptr< Fdm2DimSolver > solver_
void performCalculations() const override
Real thetaAt(Real s, Real v) const
FdmHestonSolver(Handle< HestonProcess > process, FdmSolverDesc solverDesc, const FdmSchemeDesc &schemeDesc=FdmSchemeDesc::Hundsdorfer(), Handle< FdmQuantoHelper > quantoHelper=Handle< FdmQuantoHelper >(), ext::shared_ptr< LocalVolTermStructure > leverageFct=ext::shared_ptr< LocalVolTermStructure >(), Real mixingFactor=1.0)
Real meanVarianceDeltaAt(Real s, Real v) const
const FdmSolverDesc solverDesc_
const ext::shared_ptr< LocalVolTermStructure > leverageFct_
Real gammaAt(Real s, Real v) const
const Handle< HestonProcess > process_
Real valueAt(Real s, Real v) const
Real deltaAt(Real s, Real v) const
const Handle< FdmQuantoHelper > quantoHelper_
Real meanVarianceGammaAt(Real s, Real v) const
const FdmSchemeDesc schemeDesc_
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
Heston linear operator.
QL_REAL Real
real number
Definition: types.hpp:50
Heston stochastic process.
Definition: any.hpp:35
STL namespace.
ext::shared_ptr< BlackVolTermStructure > v
Real alpha
Definition: sabr.cpp:200
const ext::shared_ptr< FdmMesher > mesher