QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fdhestonrebateengine.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 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
31#include <utility>
32
33namespace QuantLib {
34
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)
47 BarrierOption::results>(model),
48 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)
62 BarrierOption::results>(model),
63 dividends_(std::move(dividends)),
64 tGrid_(tGrid), xGrid_(xGrid), vGrid_(vGrid), dampingSteps_(dampingSteps),
65 schemeDesc_(schemeDesc), leverageFct_(std::move(leverageFct)), mixingFactor_(mixingFactor) {}
66
68
70
71 // 1. Mesher
72 const ext::shared_ptr<HestonProcess>& process = model_->process();
73 const Time maturity = process->time(arguments_.exercise->lastDate());
74
75 // 1.1 The variance mesher
76 const Size tGridMin = 5;
77 const Size tGridAvgSteps = std::max(tGridMin, tGrid_/50);
78
79 const ext::shared_ptr<FdmHestonLocalVolatilityVarianceMesher> vMesher
80 = ext::make_shared<FdmHestonLocalVolatilityVarianceMesher>(
81 vGrid_, process, leverageFct_, maturity, tGridAvgSteps, 0.0001, mixingFactor_);
82
83 // 1.2 The equity mesher
84 const ext::shared_ptr<StrikedTypePayoff> payoff =
85 ext::dynamic_pointer_cast<StrikedTypePayoff>(arguments_.payoff);
86
87 Real xMin=Null<Real>();
88 Real xMax=Null<Real>();
89 if ( arguments_.barrierType == Barrier::DownIn
90 || arguments_.barrierType == Barrier::DownOut) {
91 xMin = std::log(arguments_.barrier);
92 }
93 if ( arguments_.barrierType == Barrier::UpIn
94 || arguments_.barrierType == Barrier::UpOut) {
95 xMax = std::log(arguments_.barrier);
96 }
97
98 const ext::shared_ptr<Fdm1dMesher> equityMesher(
100 xGrid_,
102 process->s0(), process->dividendYield(),
103 process->riskFreeRate(), vMesher->volaEstimate()),
104 maturity, payoff->strike(),
105 xMin, xMax, 0.0001, 1.5,
106 std::make_pair(Null<Real>(), Null<Real>()),
107 dividends_));
108
109 const ext::shared_ptr<FdmMesher> mesher (
110 new FdmMesherComposite(equityMesher, vMesher));
111
112 // 2. Calculator
113 const ext::shared_ptr<StrikedTypePayoff> rebatePayoff(
115 const ext::shared_ptr<FdmInnerValueCalculator> calculator(
116 new FdmLogInnerValue(rebatePayoff, mesher, 0));
117
118 // 3. Step conditions
119 QL_REQUIRE(arguments_.exercise->type() == Exercise::European,
120 "only european style option are supported");
121
122 const ext::shared_ptr<FdmStepConditionComposite> conditions =
124 dividends_, arguments_.exercise,
125 mesher, calculator,
126 process->riskFreeRate()->referenceDate(),
127 process->riskFreeRate()->dayCounter());
128
129 // 4. Boundary conditions
130 FdmBoundaryConditionSet boundaries;
131 if ( arguments_.barrierType == Barrier::DownIn
132 || arguments_.barrierType == Barrier::DownOut) {
133 boundaries.push_back(FdmBoundaryConditionSet::value_type(
134 new FdmDirichletBoundary(mesher, arguments_.rebate, 0,
136
137 }
138 if ( arguments_.barrierType == Barrier::UpIn
139 || arguments_.barrierType == Barrier::UpOut) {
140 boundaries.push_back(FdmBoundaryConditionSet::value_type(
141 new FdmDirichletBoundary(mesher, arguments_.rebate, 0,
143 }
144
145 // 5. Solver
146 FdmSolverDesc solverDesc = { mesher, boundaries, conditions,
147 calculator, maturity,
149
150 ext::shared_ptr<FdmHestonSolver> solver(new FdmHestonSolver(
151 Handle<HestonProcess>(process), solverDesc, schemeDesc_,
153
154 const Real spot = process->s0()->value();
155 results_.value = solver->valueAt(spot, process->v0());
156 results_.delta = solver->deltaAt(spot, process->v0());
157 results_.gamma = solver->gammaAt(spot, process->v0());
158 results_.theta = solver->thetaAt(spot, process->v0());
159 }
160}
Barrier option on a single asset.
Binary cash-or-nothing payoff.
Definition: payoffs.hpp:152
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
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Finite-differences Heston barrier-option rebate helper engine.
1-d mesher for the Black-Scholes process (in ln(S))
Dirichlet boundary conditions for differential operators.
One-dimensional grid mesher for the variance part of the Heston model.
layer of abstraction to calculate the inner value
memory layout of a fdm linear operator
FdmMesher which is a composite of Fdm1dMesher.
composite of fdm step conditions
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
ext::shared_ptr< QuantLib::Payoff > payoff
Definition: any.hpp:35
std::vector< ext::shared_ptr< Dividend > > DividendSchedule
OperatorTraits< FdmLinearOp >::bc_set FdmBoundaryConditionSet
STL namespace.
#define QL_DEPRECATED_DISABLE_WARNING
Definition: qldefines.hpp:216
#define QL_DEPRECATED_ENABLE_WARNING
Definition: qldefines.hpp:217