QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fdmcirsolver.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) 2020 Lew Wei Hao
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
24#include <utility>
25
26namespace QuantLib {
27
30 FdmSolverDesc solverDesc,
31 const FdmSchemeDesc& schemeDesc,
32 const Real rho,
33 const Real strike)
34 : bsProcess_(std::move(bsProcess)), cirProcess_(std::move(cirProcess)),
35 solverDesc_(std::move(solverDesc)), schemeDesc_(schemeDesc), rho_(rho), strike_(strike) {
38 }
39
41 ext::shared_ptr<FdmLinearOpComposite> op(
42 ext::make_shared<FdmCIROp>(
44 cirProcess_.currentLink(),
45 bsProcess_.currentLink(),
46 rho_,
47 strike_));
48
49 solver_ = ext::make_shared<Fdm2DimSolver>(solverDesc_, schemeDesc_, op);
50 }
51
53 calculate();
54 return solver_->interpolateAt(std::log(s), r);
55 }
56
58 calculate();
59 return solver_->derivativeX(std::log(s), r)/s;
60 }
61
63 calculate();
64 const Real x = std::log(s);
65 return (solver_->derivativeXX(x, r)-solver_->derivativeX(x, r))/(s*s);
66 }
67
69 calculate();
70 return solver_->thetaAt(std::log(s), r);
71 }
72}
ext::shared_ptr< Fdm2DimSolver > solver_
const Handle< CoxIngersollRossProcess > cirProcess_
void performCalculations() const override
Real thetaAt(Real s, Real v) const
const Handle< GeneralizedBlackScholesProcess > bsProcess_
const FdmSolverDesc solverDesc_
Real gammaAt(Real s, Real v) const
Real valueAt(Real s, Real v) const
Real deltaAt(Real s, Real v) const
FdmCIRSolver(Handle< CoxIngersollRossProcess > process, Handle< GeneralizedBlackScholesProcess > bsProcess, FdmSolverDesc solverDesc, const FdmSchemeDesc &schemeDesc=FdmSchemeDesc::Hundsdorfer(), Real rho=1.0, Real strike=1.0)
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
CIR linear operator.
QL_REAL Real
real number
Definition: types.hpp:50
Heston stochastic process.
Real rho
Definition: any.hpp:35
STL namespace.
ext::shared_ptr< YieldTermStructure > r
const ext::shared_ptr< FdmMesher > mesher