QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
mc_discr_geom_av_price_heston.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2020 Jack Gillett
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#ifndef quantlib_mc_discrete_geometric_average_price_asian_heston_engine_hpp
25#define quantlib_mc_discrete_geometric_average_price_asian_heston_engine_hpp
26
27#include <ql/exercise.hpp>
28#include <ql/pricingengines/asian/mcdiscreteasianenginebase.hpp>
29#include <ql/processes/hestonprocess.hpp>
30#include <utility>
31
32namespace QuantLib {
33
35
46 template <class RNG = PseudoRandom,
47 class S = Statistics, class P = HestonProcess>
49 : public MCDiscreteAveragingAsianEngineBase<MultiVariate,RNG,S> {
50 public:
54 // constructor
55 MCDiscreteGeometricAPHestonEngine(const ext::shared_ptr<P>& process,
56 bool antitheticVariate,
57 Size requiredSamples,
58 Real requiredTolerance,
59 Size maxSamples,
60 BigNatural seed,
61 Size timeSteps = Null<Size>(),
62 Size timeStepsPerYear = Null<Size>());
63 protected:
64 ext::shared_ptr<path_pricer_type> pathPricer() const override;
65 };
66
67
68 template <class RNG = PseudoRandom,
69 class S = Statistics, class P = HestonProcess>
71 public:
72 explicit MakeMCDiscreteGeometricAPHestonEngine(ext::shared_ptr<P> process);
73 // named parameters
81 // conversion to pricing engine
82 operator ext::shared_ptr<PricingEngine>() const;
83 private:
84 ext::shared_ptr<P> process_;
85 bool antithetic_ = false;
89 };
90
91 class GeometricAPOHestonPathPricer : public PathPricer<MultiPath> {
92 public:
94 Real strike,
95 DiscountFactor discount,
96 std::vector<Size> fixingIndices,
97 Real runningProduct = 1.0,
98 Size pastFixings = 0);
99 Real operator()(const MultiPath& multiPath) const override;
100
101 private:
104 std::vector<Size> fixingIndices_;
107 };
108
109
110 // inline definitions
111
112 template <class RNG, class S, class P>
113 inline
115 const ext::shared_ptr<P>& process,
116 bool antitheticVariate,
117 Size requiredSamples,
118 Real requiredTolerance,
119 Size maxSamples,
120 BigNatural seed,
121 Size timeSteps,
122 Size timeStepsPerYear)
124 false,
125 antitheticVariate,
126 false,
127 requiredSamples,
128 requiredTolerance,
129 maxSamples,
130 seed,
131 timeSteps,
132 timeStepsPerYear) {
133 QL_REQUIRE(timeSteps == Null<Size>() || timeStepsPerYear == Null<Size>(),
134 "both time steps and time steps per year were provided");
135 }
136
137 template <class RNG, class S, class P>
138 inline ext::shared_ptr<
141
142 // Keep track of the fixing indices, the path pricer will need to sum only these
143 TimeGrid timeGrid = this->timeGrid();
144 std::vector<Time> fixingTimes = timeGrid.mandatoryTimes();
145 std::vector<Size> fixingIndexes;
146 fixingIndexes.reserve(fixingTimes.size());
147 for (Real fixingTime : fixingTimes) {
148 fixingIndexes.push_back(timeGrid.closestIndex(fixingTime));
149 }
150
151 ext::shared_ptr<PlainVanillaPayoff> payoff =
152 ext::dynamic_pointer_cast<PlainVanillaPayoff>(
153 this->arguments_.payoff);
154 QL_REQUIRE(payoff, "non-plain payoff given");
155
156 ext::shared_ptr<EuropeanExercise> exercise =
157 ext::dynamic_pointer_cast<EuropeanExercise>(
158 this->arguments_.exercise);
159 QL_REQUIRE(exercise, "wrong exercise given");
160
161 ext::shared_ptr<P> process =
162 ext::dynamic_pointer_cast<P>(this->process_);
163 QL_REQUIRE(process, "Heston like process required");
164
165 return ext::shared_ptr<typename
168 payoff->optionType(),
169 payoff->strike(),
170 process->riskFreeRate()->discount(exercise->lastDate()),
171 fixingIndexes,
172 this->arguments_.runningAccumulator,
173 this->arguments_.pastFixings));
174 }
175
176 template <class RNG, class S, class P>
178 ext::shared_ptr<P> process)
179 : process_(std::move(process)), samples_(Null<Size>()), maxSamples_(Null<Size>()),
180 steps_(Null<Size>()), stepsPerYear_(Null<Size>()), tolerance_(Null<Real>()) {}
181
182 template<class RNG, class S, class P>
185 QL_REQUIRE(tolerance_ == Null<Real>(),
186 "tolerance already set");
187 samples_ = samples;
188 return *this;
189 }
190
191 template <class RNG, class S, class P>
194 Real tolerance) {
195 QL_REQUIRE(samples_ == Null<Size>(),
196 "number of samples already set");
197 QL_REQUIRE(RNG::allowsErrorEstimate,
198 "chosen random generator policy "
199 "does not allow an error estimate");
200 tolerance_ = tolerance;
201 return *this;
202 }
203
204 template <class RNG, class S, class P>
207 maxSamples_ = samples;
208 return *this;
209 }
210
211 template <class RNG, class S, class P>
214 seed_ = seed;
215 return *this;
216 }
217
218 template <class RNG, class S, class P>
221 antithetic_ = b;
222 return *this;
223 }
224
225 template<class RNG, class S, class P>
228 QL_REQUIRE(stepsPerYear_ == Null<Size>(),
229 "number of steps per year already set");
230 steps_ = steps;
231 return *this;
232 }
233
234 template<class RNG, class S, class P>
237 QL_REQUIRE(steps_ == Null<Size>(),
238 "number of steps already set");
239 stepsPerYear_ = steps;
240 return *this;
241 }
242
243 template <class RNG, class S, class P>
244 inline MakeMCDiscreteGeometricAPHestonEngine<RNG,S,P>::operator ext::shared_ptr<PricingEngine>() const {
245 return ext::shared_ptr<PricingEngine>(new
247 antithetic_,
248 samples_,
249 tolerance_,
250 maxSamples_,
251 seed_,
252 steps_,
253 stepsPerYear_));
254 }
255}
256
257#endif
Real operator()(const MultiPath &multiPath) const override
Square-root stochastic-volatility Heston process.
Pricing engine for discrete average Asians using Monte Carlo simulation.
McSimulation< MC, RNG, S >::path_generator_type path_generator_type
McSimulation< MC, RNG, S >::path_pricer_type path_pricer_type
Heston MC pricing engine for discrete geometric average price Asian.
MCDiscreteAveragingAsianEngineBase< MultiVariate, RNG, S >::path_generator_type path_generator_type
ext::shared_ptr< path_pricer_type > pathPricer() const override
MCDiscreteAveragingAsianEngineBase< MultiVariate, RNG, S >::path_pricer_type path_pricer_type
MCDiscreteAveragingAsianEngineBase< MultiVariate, RNG, S >::stats_type stats_type
MCDiscreteGeometricAPHestonEngine(const ext::shared_ptr< P > &process, bool antitheticVariate, Size requiredSamples, Real requiredTolerance, Size maxSamples, BigNatural seed, Size timeSteps=Null< Size >(), Size timeStepsPerYear=Null< Size >())
MakeMCDiscreteGeometricAPHestonEngine & withSteps(Size steps)
MakeMCDiscreteGeometricAPHestonEngine & withAbsoluteTolerance(Real tolerance)
MakeMCDiscreteGeometricAPHestonEngine & withAntitheticVariate(bool b=true)
MakeMCDiscreteGeometricAPHestonEngine & withSeed(BigNatural seed)
MakeMCDiscreteGeometricAPHestonEngine & withStepsPerYear(Size steps)
MakeMCDiscreteGeometricAPHestonEngine & withMaxSamples(Size samples)
MakeMCDiscreteGeometricAPHestonEngine & withSamples(Size samples)
Correlated multiple asset paths.
Definition: multipath.hpp:39
template class providing a null value for a given type.
Definition: null.hpp:76
base class for path pricers
Definition: pathpricer.hpp:40
Plain-vanilla payoff.
Definition: payoffs.hpp:105
time grid class
Definition: timegrid.hpp:43
Size closestIndex(Time t) const
returns the index i such that grid[i] is closest to t
Definition: timegrid.cpp:80
const std::vector< Time > & mandatoryTimes() const
Definition: timegrid.hpp:151
QL_REAL Real
real number
Definition: types.hpp:50
Real DiscountFactor
discount factor between dates
Definition: types.hpp:66
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
RiskStatistics Statistics
default statistics tool
Definition: statistics.hpp:35
unsigned QL_BIG_INTEGER BigNatural
large positive integer
Definition: types.hpp:46
GenericPseudoRandom< MersenneTwisterUniformRng, InverseCumulativeNormal > PseudoRandom
default traits for pseudo-random number generation
Definition: rngtraits.hpp:71
STL namespace.
default Monte Carlo traits for multi-variate models
Definition: mctraits.hpp:50