QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
mc_discr_geom_av_price.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
5 Copyright (C) 2003, 2004 Ferdinando Ametrano
6 Copyright (C) 2007, 2008 StatPro Italia srl
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
26#ifndef quantlib_mc_discrete_geometric_average_price_asian_engine_h
27#define quantlib_mc_discrete_geometric_average_price_asian_engine_h
28
29#include <ql/exercise.hpp>
30#include <ql/pricingengines/asian/mcdiscreteasianenginebase.hpp>
31#include <ql/processes/blackscholesprocess.hpp>
32#include <ql/termstructures/volatility/equityfx/blackconstantvol.hpp>
33#include <ql/termstructures/volatility/equityfx/blackvariancecurve.hpp>
34#include <utility>
35
36namespace QuantLib {
37
39
44 template <class RNG = PseudoRandom, class S = Statistics>
46 : public MCDiscreteAveragingAsianEngineBase<SingleVariate,RNG,S> {
47 public:
48 typedef
51 typedef
56 // constructor
58 const ext::shared_ptr<GeneralizedBlackScholesProcess>& process,
59 bool brownianBridge,
60 bool antitheticVariate,
61 Size requiredSamples,
62 Real requiredTolerance,
63 Size maxSamples,
64 BigNatural seed);
65 protected:
66 ext::shared_ptr<path_pricer_type> pathPricer() const override;
67 };
68
69
70 class GeometricAPOPathPricer : public PathPricer<Path> {
71 public:
73 Real strike,
74 DiscountFactor discount,
75 Real runningProduct = 1.0,
76 Size pastFixings = 0);
77 Real operator()(const Path& path) const override;
78
79 private:
84 };
85
86
87 // inline definitions
88
89 template <class RNG, class S>
90 inline
92 const ext::shared_ptr<GeneralizedBlackScholesProcess>& process,
93 bool brownianBridge,
94 bool antitheticVariate,
95 Size requiredSamples,
96 Real requiredTolerance,
97 Size maxSamples,
98 BigNatural seed)
100 brownianBridge,
101 antitheticVariate,
102 false,
103 requiredSamples,
104 requiredTolerance,
105 maxSamples,
106 seed) {}
107
108
109
110 template <class RNG, class S>
111 inline
112 ext::shared_ptr<
115
116 ext::shared_ptr<PlainVanillaPayoff> payoff =
117 ext::dynamic_pointer_cast<PlainVanillaPayoff>(
118 this->arguments_.payoff);
119 QL_REQUIRE(payoff, "non-plain payoff given");
120
121 ext::shared_ptr<EuropeanExercise> exercise =
122 ext::dynamic_pointer_cast<EuropeanExercise>(
123 this->arguments_.exercise);
124 QL_REQUIRE(exercise, "wrong exercise given");
125
126 ext::shared_ptr<GeneralizedBlackScholesProcess> process =
127 ext::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
128 this->process_);
129 QL_REQUIRE(process, "Black-Scholes process required");
130
131 return ext::shared_ptr<typename
134 payoff->optionType(),
135 payoff->strike(),
136 process->riskFreeRate()->discount(exercise->lastDate()),
137 this->arguments_.runningAccumulator,
138 this->arguments_.pastFixings));
139 }
140
141
142 template <class RNG = PseudoRandom, class S = Statistics>
144 public:
146 ext::shared_ptr<GeneralizedBlackScholesProcess> process);
147 // named parameters
154 // conversion to pricing engine
155 operator ext::shared_ptr<PricingEngine>() const;
156 private:
157 ext::shared_ptr<GeneralizedBlackScholesProcess> process_;
158 bool antithetic_ = false;
161 bool brownianBridge_ = true;
163 };
164
165 template <class RNG, class S>
167 ext::shared_ptr<GeneralizedBlackScholesProcess> process)
168 : process_(std::move(process)), samples_(Null<Size>()), maxSamples_(Null<Size>()),
169 tolerance_(Null<Real>()) {}
170
171 template <class RNG, class S>
174 QL_REQUIRE(tolerance_ == Null<Real>(),
175 "tolerance already set");
176 samples_ = samples;
177 return *this;
178 }
179
180 template <class RNG, class S>
183 Real tolerance) {
184 QL_REQUIRE(samples_ == Null<Size>(),
185 "number of samples already set");
186 QL_REQUIRE(RNG::allowsErrorEstimate,
187 "chosen random generator policy "
188 "does not allow an error estimate");
189 tolerance_ = tolerance;
190 return *this;
191 }
192
193 template <class RNG, class S>
196 maxSamples_ = samples;
197 return *this;
198 }
199
200 template <class RNG, class S>
203 seed_ = seed;
204 return *this;
205 }
206
207 template <class RNG, class S>
210 brownianBridge_ = b;
211 return *this;
212 }
213
214 template <class RNG, class S>
217 antithetic_ = b;
218 return *this;
219 }
220
221 template <class RNG, class S>
222 inline
224 const {
225 return ext::shared_ptr<PricingEngine>(new
227 brownianBridge_,
228 antithetic_,
229 samples_, tolerance_,
230 maxSamples_,
231 seed_));
232 }
233
234}
235
236
237#endif
Real operator()(const Path &path) const override
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
Monte Carlo pricing engine for discrete geometric average price Asian.
MCDiscreteAveragingAsianEngineBase< SingleVariate, RNG, S >::path_pricer_type path_pricer_type
MCDiscreteAveragingAsianEngineBase< SingleVariate, RNG, S >::path_generator_type path_generator_type
ext::shared_ptr< path_pricer_type > pathPricer() const override
MCDiscreteAveragingAsianEngineBase< SingleVariate, RNG, S >::stats_type stats_type
MCDiscreteGeometricAPEngine(const ext::shared_ptr< GeneralizedBlackScholesProcess > &process, bool brownianBridge, bool antitheticVariate, Size requiredSamples, Real requiredTolerance, Size maxSamples, BigNatural seed)
MakeMCDiscreteGeometricAPEngine & withBrownianBridge(bool b=true)
MakeMCDiscreteGeometricAPEngine & withSeed(BigNatural seed)
MakeMCDiscreteGeometricAPEngine & withAntitheticVariate(bool b=true)
MakeMCDiscreteGeometricAPEngine & withAbsoluteTolerance(Real tolerance)
MakeMCDiscreteGeometricAPEngine & withSamples(Size samples)
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
MakeMCDiscreteGeometricAPEngine & withMaxSamples(Size samples)
MakeMCDiscreteGeometricAPEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > process)
template class providing a null value for a given type.
Definition: null.hpp:76
single-factor random walk
Definition: path.hpp:40
base class for path pricers
Definition: pathpricer.hpp:40
Plain-vanilla payoff.
Definition: payoffs.hpp:105
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
unsigned QL_BIG_INTEGER BigNatural
large positive integer
Definition: types.hpp:46
STL namespace.
default Monte Carlo traits for single-variate models
Definition: mctraits.hpp:39