QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdmblackscholessolver.cpp
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 Klaus Spanderen
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22#include <ql/methods/finitedifferences/operators/fdmblackscholesop.hpp>
23#include <ql/methods/finitedifferences/solvers/fdm1dimsolver.hpp>
24#include <ql/methods/finitedifferences/solvers/fdmblackscholessolver.hpp>
25#include <ql/processes/blackscholesprocess.hpp>
26#include <utility>
27
28namespace QuantLib {
29
31 Real strike,
32 FdmSolverDesc solverDesc,
33 const FdmSchemeDesc& schemeDesc,
34 bool localVol,
35 Real illegalLocalVolOverwrite,
36 Handle<FdmQuantoHelper> quantoHelper)
37 : process_(std::move(process)), strike_(strike), solverDesc_(std::move(solverDesc)),
38 schemeDesc_(schemeDesc), localVol_(localVol),
39 illegalLocalVolOverwrite_(illegalLocalVolOverwrite), quantoHelper_(std::move(quantoHelper)) {
40
43 }
44
46 const ext::shared_ptr<FdmBlackScholesOp> op(
47 ext::make_shared<FdmBlackScholesOp>(
48 solverDesc_.mesher, process_.currentLink(), strike_,
50 (quantoHelper_.empty())
51 ? ext::shared_ptr<FdmQuantoHelper>()
52 : quantoHelper_.currentLink()));
53
54 solver_ = ext::make_shared<Fdm1DimSolver>(solverDesc_, schemeDesc_, op);
55 }
56
58 calculate();
59 return solver_->interpolateAt(std::log(s));
60 }
61
63 calculate();
64 return solver_->derivativeX(std::log(s))/s;
65 }
66
68 calculate();
69 return (solver_->derivativeXX(std::log(s))
70 -solver_->derivativeX(std::log(s)))/(s*s);
71 }
72
74 return solver_->thetaAt(std::log(s));
75 }
76}
ext::shared_ptr< Fdm1DimSolver > solver_
const Handle< FdmQuantoHelper > quantoHelper_
FdmBlackScholesSolver(Handle< GeneralizedBlackScholesProcess > process, Real strike, FdmSolverDesc solverDesc, const FdmSchemeDesc &schemeDesc=FdmSchemeDesc::Douglas(), bool localVol=false, Real illegalLocalVolOverwrite=-Null< Real >(), Handle< FdmQuantoHelper > quantoHelper=Handle< FdmQuantoHelper >())
Handle< GeneralizedBlackScholesProcess > process_
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