QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fdhestonvanillaengine.hpp
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 Ralph Schreyer
6 Copyright (C) 2008, 2009, 2014 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/*! \file fdhestonvanillaengine.hpp
23 \brief Finite-differences Heston vanilla option engine
24*/
25
26#ifndef quantlib_fd_heston_vanilla_engine_hpp
27#define quantlib_fd_heston_vanilla_engine_hpp
28
35
36namespace QuantLib {
37
38 class FdmQuantoHelper;
39
40 //! Finite-differences Heston vanilla option engine
41 /*! \ingroup vanillaengines
42
43 \test the correctness of the returned value is tested by
44 reproducing results available in web/literature
45 and comparison with Black pricing.
46 */
48 : public GenericModelEngine<HestonModel,
49 VanillaOption::arguments,
50 VanillaOption::results> {
51 public:
52 explicit
53 FdHestonVanillaEngine(const ext::shared_ptr<HestonModel>& model,
54 Size tGrid = 100,
55 Size xGrid = 100,
56 Size vGrid = 50,
57 Size dampingSteps = 0,
58 const FdmSchemeDesc& schemeDesc = FdmSchemeDesc::Hundsdorfer(),
59 ext::shared_ptr<LocalVolTermStructure> leverageFct = {},
60 Real mixingFactor = 1.0);
61
62 FdHestonVanillaEngine(const ext::shared_ptr<HestonModel>& model,
63 DividendSchedule dividends,
64 Size tGrid = 100,
65 Size xGrid = 100,
66 Size vGrid = 50,
67 Size dampingSteps = 0,
68 const FdmSchemeDesc& schemeDesc = FdmSchemeDesc::Hundsdorfer(),
69 ext::shared_ptr<LocalVolTermStructure> leverageFct = {},
70 Real mixingFactor = 1.0);
71
72 FdHestonVanillaEngine(const ext::shared_ptr<HestonModel>& model,
73 ext::shared_ptr<FdmQuantoHelper> quantoHelper,
74 Size tGrid = 100,
75 Size xGrid = 100,
76 Size vGrid = 50,
77 Size dampingSteps = 0,
78 const FdmSchemeDesc& schemeDesc = FdmSchemeDesc::Hundsdorfer(),
79 ext::shared_ptr<LocalVolTermStructure> leverageFct = {},
80 Real mixingFactor = 1.0);
81
82 FdHestonVanillaEngine(const ext::shared_ptr<HestonModel>& model,
83 DividendSchedule dividends,
84 ext::shared_ptr<FdmQuantoHelper> quantoHelper,
85 Size tGrid = 100,
86 Size xGrid = 100,
87 Size vGrid = 50,
88 Size dampingSteps = 0,
89 const FdmSchemeDesc& schemeDesc = FdmSchemeDesc::Hundsdorfer(),
90 ext::shared_ptr<LocalVolTermStructure> leverageFct = {},
91 Real mixingFactor = 1.0);
92
93 void calculate() const override;
94
95 // multiple strikes caching engine
96 void update() override;
97 void enableMultipleStrikesCaching(const std::vector<Real>& strikes);
98
99 // helper method for Heston like engines
100 FdmSolverDesc getSolverDesc(Real equityScaleFactor) const;
101
102 private:
106 const ext::shared_ptr<LocalVolTermStructure> leverageFct_;
107 const ext::shared_ptr<FdmQuantoHelper> quantoHelper_;
109
110 std::vector<Real> strikes_;
111 mutable std::vector<std::pair<VanillaOption::arguments,
114 };
115
117 public:
118 explicit MakeFdHestonVanillaEngine(ext::shared_ptr<HestonModel> hestonModel);
119
121 const ext::shared_ptr<FdmQuantoHelper>& quantoHelper);
122
127 Size dampingSteps);
128
130 const FdmSchemeDesc& schemeDesc);
131
133 ext::shared_ptr<LocalVolTermStructure>& leverageFct);
134
136 const std::vector<Date>& dividendDates,
137 const std::vector<Real>& dividendAmounts);
138
139 operator ext::shared_ptr<PricingEngine>() const;
140
141 private:
142 ext::shared_ptr<HestonModel> hestonModel_;
144 Size tGrid_ = 100, xGrid_ = 100, vGrid_ = 50, dampingSteps_ = 0;
145 ext::shared_ptr<FdmSchemeDesc> schemeDesc_;
146 ext::shared_ptr<LocalVolTermStructure> leverageFct_;
147 ext::shared_ptr<FdmQuantoHelper> quantoHelper_;
148 };
149
150}
151
152#endif
Finite-differences Heston vanilla option engine.
FdmSolverDesc getSolverDesc(Real equityScaleFactor) const
std::vector< std::pair< VanillaOption::arguments, VanillaOption::results > > cachedArgs2results_
const ext::shared_ptr< FdmQuantoHelper > quantoHelper_
const ext::shared_ptr< LocalVolTermStructure > leverageFct_
void enableMultipleStrikesCaching(const std::vector< Real > &strikes)
Base class for some pricing engine on a particular model.
ext::shared_ptr< HestonModel > hestonModel_
MakeFdHestonVanillaEngine & withDampingSteps(Size dampingSteps)
MakeFdHestonVanillaEngine & withQuantoHelper(const ext::shared_ptr< FdmQuantoHelper > &quantoHelper)
MakeFdHestonVanillaEngine & withTGrid(Size tGrid)
MakeFdHestonVanillaEngine & withCashDividends(const std::vector< Date > &dividendDates, const std::vector< Real > &dividendAmounts)
ext::shared_ptr< FdmQuantoHelper > quantoHelper_
MakeFdHestonVanillaEngine & withVGrid(Size vGrid)
ext::shared_ptr< FdmSchemeDesc > schemeDesc_
MakeFdHestonVanillaEngine & withFdmSchemeDesc(const FdmSchemeDesc &schemeDesc)
MakeFdHestonVanillaEngine & withLeverageFunction(ext::shared_ptr< LocalVolTermStructure > &leverageFct)
MakeFdHestonVanillaEngine & withXGrid(Size xGrid)
ext::shared_ptr< LocalVolTermStructure > leverageFct_
basic option arguments
Definition: option.hpp:57
Generic option engine based on a model.
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Heston model for the stochastic volatility of an asset.
Local volatility term structure base class.
Definition: any.hpp:35
std::vector< ext::shared_ptr< Dividend > > DividendSchedule
static FdmSchemeDesc Hundsdorfer()
Vanilla option on a single asset.