QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdhestondoublebarrierengine.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2016 Klaus Spanderen
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
20#include <ql/methods/finitedifferences/meshers/fdmblackscholesmesher.hpp>
21#include <ql/methods/finitedifferences/meshers/fdmhestonvariancemesher.hpp>
22#include <ql/methods/finitedifferences/meshers/fdmmeshercomposite.hpp>
23#include <ql/methods/finitedifferences/operators/fdmlinearoplayout.hpp>
24#include <ql/methods/finitedifferences/stepconditions/fdmstepconditioncomposite.hpp>
25#include <ql/methods/finitedifferences/utilities/fdmdirichletboundary.hpp>
26#include <ql/methods/finitedifferences/utilities/fdmdividendhandler.hpp>
27#include <ql/methods/finitedifferences/utilities/fdminnervaluecalculator.hpp>
28#include <ql/pricingengines/barrier/fdhestonrebateengine.hpp>
29#include <ql/pricingengines/barrier/fdhestondoublebarrierengine.hpp>
30#include <ql/pricingengines/vanilla/fdhestonvanillaengine.hpp>
31#include <utility>
32
33namespace QuantLib {
34
36 const ext::shared_ptr<HestonModel>& model,
37 Size tGrid,
38 Size xGrid,
39 Size vGrid,
40 Size dampingSteps,
41 const FdmSchemeDesc& schemeDesc,
42 ext::shared_ptr<LocalVolTermStructure> leverageFct,
43 const Real mixingFactor)
45 model),
46 tGrid_(tGrid), xGrid_(xGrid), vGrid_(vGrid), dampingSteps_(dampingSteps),
47 schemeDesc_(schemeDesc), leverageFct_(std::move(leverageFct)), mixingFactor_(mixingFactor) {}
48
50
51 QL_REQUIRE(arguments_.barrierType == DoubleBarrier::KnockOut,
52 "only Knock-Out double barrier options are supported");
53
54 // 1. Mesher
55 const ext::shared_ptr<HestonProcess>& process = model_->process();
56 const Time maturity = process->time(arguments_.exercise->lastDate());
57
58 // 1.1 The variance mesher
59 const Size tGridMin = 5;
60 const Size tGridAvgSteps = std::max(tGridMin, tGrid_/50);
61
62 const ext::shared_ptr<FdmHestonLocalVolatilityVarianceMesher> vMesher
63 = ext::make_shared<FdmHestonLocalVolatilityVarianceMesher>(
64 vGrid_, process, leverageFct_, maturity, tGridAvgSteps, 0.0001, mixingFactor_);
65
66 // 1.2 The equity mesher
67 const ext::shared_ptr<StrikedTypePayoff> payoff =
68 ext::dynamic_pointer_cast<StrikedTypePayoff>(arguments_.payoff);
69
70 Real xMin = std::log(arguments_.barrier_lo);
71 Real xMax = std::log(arguments_.barrier_hi);
72
73 const ext::shared_ptr<Fdm1dMesher> equityMesher(
75 xGrid_,
77 process->s0(), process->dividendYield(),
78 process->riskFreeRate(), vMesher->volaEstimate()),
79 maturity, payoff->strike(), xMin, xMax));
80
81 const ext::shared_ptr<FdmMesher> mesher (
82 new FdmMesherComposite(equityMesher, vMesher));
83
84 // 2. Calculator
85 const ext::shared_ptr<FdmInnerValueCalculator> calculator(
86 new FdmLogInnerValue(payoff, mesher, 0));
87
88 // 3. Step conditions
89 std::list<ext::shared_ptr<StepCondition<Array> > > stepConditions;
90 std::list<std::vector<Time> > stoppingTimes;
91
92 QL_REQUIRE(arguments_.exercise->type() == Exercise::European,
93 "only european style option are supported");
94
95 ext::shared_ptr<FdmStepConditionComposite> conditions(
96 new FdmStepConditionComposite(stoppingTimes, stepConditions));
97
98 // 4. Boundary conditions
99 FdmBoundaryConditionSet boundaries;
100 boundaries.push_back(FdmBoundaryConditionSet::value_type(
101 new FdmDirichletBoundary(mesher, arguments_.rebate, 0,
103
104 boundaries.push_back(FdmBoundaryConditionSet::value_type(
105 new FdmDirichletBoundary(mesher, arguments_.rebate, 0,
107
108 // 5. Solver
109 FdmSolverDesc solverDesc = { mesher, boundaries, conditions,
110 calculator, maturity,
112
113 ext::shared_ptr<FdmHestonSolver> solver(new FdmHestonSolver(
114 Handle<HestonProcess>(process), solverDesc, schemeDesc_,
116
117 const Real spot = process->s0()->value();
118 results_.value = solver->valueAt(spot, process->v0());
119 results_.delta = solver->deltaAt(spot, process->v0());
120 results_.gamma = solver->gammaAt(spot, process->v0());
121 results_.theta = solver->thetaAt(spot, process->v0());
122 }
123}
Double Barrier option on a single asset.
const ext::shared_ptr< LocalVolTermStructure > leverageFct_
FdHestonDoubleBarrierEngine(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=ext::shared_ptr< LocalVolTermStructure >(), Real mixingFactor=1.0)
static ext::shared_ptr< GeneralizedBlackScholesProcess > processHelper(const Handle< Quote > &s0, const Handle< YieldTermStructure > &rTS, const Handle< YieldTermStructure > &qTS, Volatility vol)
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
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
OperatorTraits< FdmLinearOp >::bc_set FdmBoundaryConditionSet
STL namespace.