QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
mcforwardeuropeanbsengine.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 This file is part of QuantLib, a free-software/open-source library
5 for financial quantitative analysts and developers - http://quantlib.org/
6 QuantLib is free software: you can redistribute it and/or modify it
7 under the terms of the QuantLib license. You should have received a
8 copy of the license along with this program; if not, please email
9 <quantlib-dev@lists.sf.net>. The license is also available online at
10 <http://quantlib.org/license.shtml>.
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the license for more details.
14*/
15
20#ifndef quantlib_mc_forward_european_bs_engine_hpp
21#define quantlib_mc_forward_european_bs_engine_hpp
22
23#include <ql/pricingengines/forward/mcforwardvanillaengine.hpp>
24#include <ql/processes/blackscholesprocess.hpp>
25#include <utility>
26
27namespace QuantLib {
28
35 template <class RNG = PseudoRandom, class S = Statistics>
37 : public MCForwardVanillaEngine<SingleVariate,RNG,S> {
38 public:
39 typedef
42 typedef
47 // constructor
49 const ext::shared_ptr<GeneralizedBlackScholesProcess>& process,
50 Size timeSteps,
51 Size timeStepsPerYear,
52 bool brownianBridge,
53 bool antitheticVariate,
54 Size requiredSamples,
55 Real requiredTolerance,
56 Size maxSamples,
57 BigNatural seed);
58 protected:
59 ext::shared_ptr<path_pricer_type> pathPricer() const override;
60 };
61
62
63 template <class RNG = PseudoRandom, class S = Statistics>
65 public:
67 ext::shared_ptr<GeneralizedBlackScholesProcess> process);
68 // named parameters
77 // conversion to pricing engine
78 operator ext::shared_ptr<PricingEngine>() const;
79 private:
80 ext::shared_ptr<GeneralizedBlackScholesProcess> process_;
81 bool antithetic_ = false;
84 bool brownianBridge_ = false;
86 };
87
88
90 public:
92 Real moneyness,
93 Size resetIndex,
94 DiscountFactor discount);
95 Real operator()(const Path& path) const override;
96
97 private:
102 };
103
104
105 // inline definitions
106
107 template <class RNG, class S>
108 inline
110 const ext::shared_ptr<GeneralizedBlackScholesProcess>& process,
111 Size timeSteps,
112 Size timeStepsPerYear,
113 bool brownianBridge,
114 bool antitheticVariate,
115 Size requiredSamples,
116 Real requiredTolerance,
117 Size maxSamples,
118 BigNatural seed)
120 timeSteps,
121 timeStepsPerYear,
122 brownianBridge,
123 antitheticVariate,
124 requiredSamples,
125 requiredTolerance,
126 maxSamples,
127 seed) {}
128
129
130 template <class RNG, class S>
131 inline
132 ext::shared_ptr<typename MCForwardEuropeanBSEngine<RNG,S>::path_pricer_type>
134
135 TimeGrid timeGrid = this->timeGrid();
136
137 Time resetTime = this->process_->time(this->arguments_.resetDate);
138 Size resetIndex = timeGrid.closestIndex(resetTime);
139
140 ext::shared_ptr<PlainVanillaPayoff> payoff =
141 ext::dynamic_pointer_cast<PlainVanillaPayoff>(
142 this->arguments_.payoff);
143 QL_REQUIRE(payoff, "non-plain payoff given");
144
145 ext::shared_ptr<EuropeanExercise> exercise =
146 ext::dynamic_pointer_cast<EuropeanExercise>(
147 this->arguments_.exercise);
148 QL_REQUIRE(exercise, "wrong exercise given");
149
150 ext::shared_ptr<GeneralizedBlackScholesProcess> process =
151 ext::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
152 this->process_);
153 QL_REQUIRE(process, "Black-Scholes process required");
154
155 return ext::shared_ptr<typename
158 payoff->optionType(),
159 this->arguments_.moneyness,
160 resetIndex,
161 process->riskFreeRate()->discount(
162 timeGrid.back())));
163 }
164
165
166 template <class RNG, class S>
168 ext::shared_ptr<GeneralizedBlackScholesProcess> process)
169 : process_(std::move(process)), steps_(Null<Size>()), stepsPerYear_(Null<Size>()),
170 samples_(Null<Size>()), maxSamples_(Null<Size>()), tolerance_(Null<Real>()) {}
171
172 template <class RNG, class S>
175 steps_ = steps;
176 return *this;
177 }
178
179 template <class RNG, class S>
182 stepsPerYear_ = steps;
183 return *this;
184 }
185
186 template <class RNG, class S>
189 QL_REQUIRE(tolerance_ == Null<Real>(),
190 "tolerance already set");
191 samples_ = samples;
192 return *this;
193 }
194
195 template <class RNG, class S>
198 Real tolerance) {
199 QL_REQUIRE(samples_ == Null<Size>(),
200 "number of samples already set");
201 QL_REQUIRE(RNG::allowsErrorEstimate,
202 "chosen random generator policy "
203 "does not allow an error estimate");
204 tolerance_ = tolerance;
205 return *this;
206 }
207
208 template <class RNG, class S>
211 maxSamples_ = samples;
212 return *this;
213 }
214
215 template <class RNG, class S>
218 seed_ = seed;
219 return *this;
220 }
221
222 template <class RNG, class S>
225 brownianBridge_ = b;
226 return *this;
227 }
228
229 template <class RNG, class S>
232 antithetic_ = b;
233 return *this;
234 }
235
236 template <class RNG, class S>
237 inline
238 MakeMCForwardEuropeanBSEngine<RNG,S>::operator ext::shared_ptr<PricingEngine>()
239 const {
240 QL_REQUIRE(steps_ != Null<Size>() || stepsPerYear_ != Null<Size>(),
241 "number of steps not given");
242 QL_REQUIRE(steps_ == Null<Size>() || stepsPerYear_ == Null<Size>(),
243 "number of steps overspecified - set EITHER steps OR stepsPerYear");
244 return ext::shared_ptr<PricingEngine>(new
246 steps_,
247 stepsPerYear_,
248 brownianBridge_,
249 antithetic_,
250 samples_, tolerance_,
251 maxSamples_,
252 seed_));
253 }
254
255}
256
257
258#endif
Real operator()(const Path &path) const override
MCForwardVanillaEngine< SingleVariate, RNG, S >::path_generator_type path_generator_type
MCForwardEuropeanBSEngine(const ext::shared_ptr< GeneralizedBlackScholesProcess > &process, Size timeSteps, Size timeStepsPerYear, bool brownianBridge, bool antitheticVariate, Size requiredSamples, Real requiredTolerance, Size maxSamples, BigNatural seed)
MCForwardVanillaEngine< SingleVariate, RNG, S >::stats_type stats_type
ext::shared_ptr< path_pricer_type > pathPricer() const override
MCForwardVanillaEngine< SingleVariate, RNG, S >::path_pricer_type path_pricer_type
Monte Carlo engine for forward-starting vanilla options.
McSimulation< MC, RNG, S >::path_generator_type path_generator_type
McSimulation< MC, RNG, S >::path_pricer_type path_pricer_type
MakeMCForwardEuropeanBSEngine & withAntitheticVariate(bool b=true)
MakeMCForwardEuropeanBSEngine & withStepsPerYear(Size steps)
MakeMCForwardEuropeanBSEngine & withSteps(Size steps)
MakeMCForwardEuropeanBSEngine & withSamples(Size samples)
MakeMCForwardEuropeanBSEngine & withAbsoluteTolerance(Real tolerance)
MakeMCForwardEuropeanBSEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > process)
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
MakeMCForwardEuropeanBSEngine & withBrownianBridge(bool b=false)
MakeMCForwardEuropeanBSEngine & withMaxSamples(Size samples)
MakeMCForwardEuropeanBSEngine & withSeed(BigNatural seed)
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
time grid class
Definition: timegrid.hpp:43
Time back() const
Definition: timegrid.hpp:171
Size closestIndex(Time t) const
returns the index i such that grid[i] is closest to t
Definition: timegrid.cpp:80
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
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