24#ifndef quantlib_mc_everest_engine_hpp
25#define quantlib_mc_everest_engine_hpp
36 template <
class RNG = PseudoRandom,
class S = Statistics>
48 Size timeStepsPerYear,
50 bool antitheticVariate,
52 Real requiredTolerance,
62 if (RNG::allowsErrorEstimate) {
64 this->
mcModel_->sampleAccumulator().errorEstimate();
81 typename RNG::rsg_type gen =
82 RNG::make_sequence_generator(numAssets*(grid.
size()-1),
seed_);
84 return ext::shared_ptr<path_generator_type>(
88 ext::shared_ptr<path_pricer_type>
pathPricer()
const override;
102 template <
class RNG = PseudoRandom,
class S = Statistics>
116 operator ext::shared_ptr<PricingEngine>()
const;
142 template <
class RNG,
class S>
144 ext::shared_ptr<StochasticProcessArray> processes,
146 Size timeStepsPerYear,
148 bool antitheticVariate,
149 Size requiredSamples,
150 Real requiredTolerance,
154 processes_(
std::move(processes)), timeSteps_(timeSteps), timeStepsPerYear_(timeStepsPerYear),
155 requiredSamples_(requiredSamples), maxSamples_(maxSamples),
156 requiredTolerance_(requiredTolerance), brownianBridge_(brownianBridge), seed_(seed) {
159 "no time steps provided");
162 "both time steps and time steps per year were provided");
164 "timeSteps must be positive, " << timeSteps <<
167 "timeStepsPerYear must be positive, " << timeStepsPerYear <<
172 template <
class RNG,
class S>
174 Time residualTime = processes_->time(
175 this->arguments_.exercise->lastDate());
177 return TimeGrid(residualTime, timeSteps_);
178 }
else if (timeStepsPerYear_ !=
Null<Size>()) {
179 Size steps =
static_cast<Size>(timeStepsPerYear_*residualTime);
180 return TimeGrid(residualTime, std::max<Size>(steps, 1));
182 QL_FAIL(
"time steps not specified");
186 template <
class RNG,
class S>
188 ext::shared_ptr<GeneralizedBlackScholesProcess> process =
189 ext::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
190 processes_->process(0));
191 QL_REQUIRE(process,
"Black-Scholes process required");
193 return process->riskFreeRate()->discount(
194 arguments_.exercise->lastDate());
197 template <
class RNG,
class S>
198 inline ext::shared_ptr<typename MCEverestEngine<RNG,S>::path_pricer_type>
201 return ext::shared_ptr<
204 arguments_.guarantee,
209 template <
class RNG,
class S>
211 ext::shared_ptr<StochasticProcessArray> process)
215 template <
class RNG,
class S>
222 template <
class RNG,
class S>
225 stepsPerYear_ = steps;
229 template <
class RNG,
class S>
232 brownianBridge_ = brownianBridge;
236 template <
class RNG,
class S>
243 template <
class RNG,
class S>
247 "tolerance already set");
252 template <
class RNG,
class S>
256 "number of samples already set");
258 "chosen random generator policy "
259 "does not allow an error estimate");
260 tolerance_ = tolerance;
264 template <
class RNG,
class S>
267 maxSamples_ = samples;
271 template <
class RNG,
class S>
278 template <
class RNG,
class S>
281 ext::shared_ptr<PricingEngine>()
const {
283 "number of steps not given");
285 "number of steps overspecified");
286 return ext::shared_ptr<PricingEngine>(
new
292 samples_, tolerance_,
Real operator()(const MultiPath &multiPath) const override
EverestOption::results results_
EverestOption::arguments arguments_
DiscountFactor endDiscount() const
MCEverestEngine(ext::shared_ptr< StochasticProcessArray >, Size timeSteps, Size timeStepsPerYear, bool brownianBridge, bool antitheticVariate, Size requiredSamples, Real requiredTolerance, Size maxSamples, BigNatural seed)
ext::shared_ptr< path_pricer_type > pathPricer() const override
ext::shared_ptr< path_generator_type > pathGenerator() const override
void calculate() const override
McSimulation< MultiVariate, RNG, S >::path_pricer_type path_pricer_type
McSimulation< MultiVariate, RNG, S >::stats_type stats_type
McSimulation< MultiVariate, RNG, S >::path_generator_type path_generator_type
ext::shared_ptr< StochasticProcessArray > processes_
TimeGrid timeGrid() const override
Monte Carlo Everest-option engine factory.
MakeMCEverestEngine & withSamples(Size samples)
MakeMCEverestEngine & withSeed(BigNatural seed)
MakeMCEverestEngine & withStepsPerYear(Size steps)
MakeMCEverestEngine(ext::shared_ptr< StochasticProcessArray >)
MakeMCEverestEngine & withMaxSamples(Size samples)
ext::shared_ptr< StochasticProcessArray > process_
MakeMCEverestEngine & withBrownianBridge(bool b=true)
MakeMCEverestEngine & withAntitheticVariate(bool b=true)
MakeMCEverestEngine & withAbsoluteTolerance(Real tolerance)
MakeMCEverestEngine & withSteps(Size steps)
base class for Monte Carlo engines
MonteCarloModel< MC, RNG, S >::path_generator_type path_generator_type
ext::shared_ptr< MonteCarloModel< MC, RNG, S > > mcModel_
void calculate(Real requiredTolerance, Size requiredSamples, Size maxSamples) const
basic calculate method provided to inherited pricing engines
MonteCarloModel< MC, RNG, S >::path_pricer_type path_pricer_type
Correlated multiple asset paths.
template class providing a null value for a given type.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
base class for path pricers
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Everest option on a number of assets.
Option exercise classes and payoff function.
ext::function< Real(Real)> b
Real Time
continuous quantity with 1-year units
Real DiscountFactor
discount factor between dates
std::size_t Size
size of a container
framework for Monte Carlo engines
unsigned QL_BIG_INTEGER BigNatural
large positive integer
Array of correlated 1-D stochastic processes.
default Monte Carlo traits for multi-variate models