QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdhestonrebateengine.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/meshers/fdmblackscholesmesher.hpp>
23#include <ql/methods/finitedifferences/meshers/fdmhestonvariancemesher.hpp>
24#include <ql/methods/finitedifferences/meshers/fdmmeshercomposite.hpp>
25#include <ql/methods/finitedifferences/operators/fdmlinearoplayout.hpp>
26#include <ql/methods/finitedifferences/solvers/fdmbackwardsolver.hpp>
27#include <ql/methods/finitedifferences/stepconditions/fdmstepconditioncomposite.hpp>
28#include <ql/methods/finitedifferences/utilities/fdmdirichletboundary.hpp>
29#include <ql/methods/finitedifferences/utilities/fdminnervaluecalculator.hpp>
30#include <ql/pricingengines/barrier/fdhestonrebateengine.hpp>
31#include <utility>
32
33namespace QuantLib {
34
35 QL_DEPRECATED_DISABLE_WARNING
36
37 FdHestonRebateEngine::FdHestonRebateEngine(const ext::shared_ptr<HestonModel>& model,
38 Size tGrid,
39 Size xGrid,
40 Size vGrid,
41 Size dampingSteps,
42 const FdmSchemeDesc& schemeDesc,
43 ext::shared_ptr<LocalVolTermStructure> leverageFct,
44 const Real mixingFactor)
48 explicitDividends_(false), tGrid_(tGrid), xGrid_(xGrid), vGrid_(vGrid), dampingSteps_(dampingSteps),
49 schemeDesc_(schemeDesc), leverageFct_(std::move(leverageFct)), mixingFactor_(mixingFactor) {}
50
51 FdHestonRebateEngine::FdHestonRebateEngine(const ext::shared_ptr<HestonModel>& model,
52 DividendSchedule dividends,
53 Size tGrid,
54 Size xGrid,
55 Size vGrid,
56 Size dampingSteps,
57 const FdmSchemeDesc& schemeDesc,
58 ext::shared_ptr<LocalVolTermStructure> leverageFct,
59 const Real mixingFactor)
63 dividends_(std::move(dividends)), explicitDividends_(true),
64 tGrid_(tGrid), xGrid_(xGrid), vGrid_(vGrid), dampingSteps_(dampingSteps),
65 schemeDesc_(schemeDesc), leverageFct_(std::move(leverageFct)), mixingFactor_(mixingFactor) {}
66
67 QL_DEPRECATED_ENABLE_WARNING
68
70
71 // dividends will eventually be moved out of arguments, but for now we need the switch
72 QL_DEPRECATED_DISABLE_WARNING
73 const DividendSchedule& dividendSchedule = explicitDividends_ ? dividends_ : arguments_.cashFlow;
74 QL_DEPRECATED_ENABLE_WARNING
75
76 // 1. Mesher
77 const ext::shared_ptr<HestonProcess>& process = model_->process();
78 const Time maturity = process->time(arguments_.exercise->lastDate());
79
80 // 1.1 The variance mesher
81 const Size tGridMin = 5;
82 const Size tGridAvgSteps = std::max(tGridMin, tGrid_/50);
83
84 const ext::shared_ptr<FdmHestonLocalVolatilityVarianceMesher> vMesher
85 = ext::make_shared<FdmHestonLocalVolatilityVarianceMesher>(
86 vGrid_, process, leverageFct_, maturity, tGridAvgSteps, 0.0001, mixingFactor_);
87
88 // 1.2 The equity mesher
89 const ext::shared_ptr<StrikedTypePayoff> payoff =
90 ext::dynamic_pointer_cast<StrikedTypePayoff>(arguments_.payoff);
91
92 Real xMin=Null<Real>();
93 Real xMax=Null<Real>();
94 if ( arguments_.barrierType == Barrier::DownIn
95 || arguments_.barrierType == Barrier::DownOut) {
96 xMin = std::log(arguments_.barrier);
97 }
98 if ( arguments_.barrierType == Barrier::UpIn
99 || arguments_.barrierType == Barrier::UpOut) {
100 xMax = std::log(arguments_.barrier);
101 }
102
103 const ext::shared_ptr<Fdm1dMesher> equityMesher(
105 xGrid_,
107 process->s0(), process->dividendYield(),
108 process->riskFreeRate(), vMesher->volaEstimate()),
109 maturity, payoff->strike(),
110 xMin, xMax, 0.0001, 1.5,
111 std::make_pair(Null<Real>(), Null<Real>()),
112 dividendSchedule));
113
114 const ext::shared_ptr<FdmMesher> mesher (
115 new FdmMesherComposite(equityMesher, vMesher));
116
117 // 2. Calculator
118 const ext::shared_ptr<StrikedTypePayoff> rebatePayoff(
120 const ext::shared_ptr<FdmInnerValueCalculator> calculator(
121 new FdmLogInnerValue(rebatePayoff, mesher, 0));
122
123 // 3. Step conditions
124 QL_REQUIRE(arguments_.exercise->type() == Exercise::European,
125 "only european style option are supported");
126
127 const ext::shared_ptr<FdmStepConditionComposite> conditions =
129 dividendSchedule, arguments_.exercise,
130 mesher, calculator,
131 process->riskFreeRate()->referenceDate(),
132 process->riskFreeRate()->dayCounter());
133
134 // 4. Boundary conditions
135 FdmBoundaryConditionSet boundaries;
136 if ( arguments_.barrierType == Barrier::DownIn
137 || arguments_.barrierType == Barrier::DownOut) {
138 boundaries.push_back(FdmBoundaryConditionSet::value_type(
139 new FdmDirichletBoundary(mesher, arguments_.rebate, 0,
141
142 }
143 if ( arguments_.barrierType == Barrier::UpIn
144 || arguments_.barrierType == Barrier::UpOut) {
145 boundaries.push_back(FdmBoundaryConditionSet::value_type(
146 new FdmDirichletBoundary(mesher, arguments_.rebate, 0,
148 }
149
150 // 5. Solver
151 FdmSolverDesc solverDesc = { mesher, boundaries, conditions,
152 calculator, maturity,
154
155 ext::shared_ptr<FdmHestonSolver> solver(new FdmHestonSolver(
156 Handle<HestonProcess>(process), solverDesc, schemeDesc_,
158
159 const Real spot = process->s0()->value();
160 results_.value = solver->valueAt(spot, process->v0());
161 results_.delta = solver->deltaAt(spot, process->v0());
162 results_.gamma = solver->gammaAt(spot, process->v0());
163 results_.theta = solver->thetaAt(spot, process->v0());
164 }
165}
Binary cash-or-nothing payoff.
Definition: payoffs.hpp:152
Single-asset barrier option with discrete dividends.
FdHestonRebateEngine(const ext::shared_ptr< HestonModel > &model, Size tGrid=100, Size xGrid=100, Size vGrid=50, Size dampingSteps=0, const FdmSchemeDesc &schemeDesc=FdmSchemeDesc::Hundsdorfer(), ext::shared_ptr< LocalVolTermStructure > leverageFct={}, Real mixingFactor=1.0)
const ext::shared_ptr< LocalVolTermStructure > leverageFct_
static ext::shared_ptr< GeneralizedBlackScholesProcess > processHelper(const Handle< Quote > &s0, const Handle< YieldTermStructure > &rTS, const Handle< YieldTermStructure > &qTS, Volatility vol)
static ext::shared_ptr< FdmStepConditionComposite > vanillaComposite(const DividendSchedule &schedule, const ext::shared_ptr< Exercise > &exercise, const ext::shared_ptr< FdmMesher > &mesher, const ext::shared_ptr< FdmInnerValueCalculator > &calculator, const Date &refDate, const DayCounter &dayCounter)
Base class for some pricing engine on a particular model.
Shared handle to an observable.
Definition: handle.hpp:41
Heston model for the stochastic volatility of an asset.
Definition: hestonmodel.hpp:42
template class providing a null value for a given type.
Definition: null.hpp:76
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
std::vector< ext::shared_ptr< Dividend > > DividendSchedule
OperatorTraits< FdmLinearOp >::bc_set FdmBoundaryConditionSet
STL namespace.