24#ifndef quantlib_mc_pagoda_engine_hpp
25#define quantlib_mc_pagoda_engine_hpp
37 template <
class RNG = PseudoRandom,
class S = Statistics>
50 bool antitheticVariate,
52 Real requiredTolerance,
60 if (RNG::allowsErrorEstimate)
62 this->
mcModel_->sampleAccumulator().errorEstimate();
73 typename RNG::rsg_type gen =
74 RNG::make_sequence_generator(numAssets*(grid.
size()-1),
seed_);
76 return ext::shared_ptr<path_generator_type>(
80 ext::shared_ptr<path_pricer_type>
pathPricer()
const override;
93 template <
class RNG = PseudoRandom,
class S = Statistics>
105 operator ext::shared_ptr<PricingEngine>()
const;
129 template <
class RNG,
class S>
132 bool antitheticVariate,
133 Size requiredSamples,
134 Real requiredTolerance,
138 processes_(
std::move(processes)), requiredSamples_(requiredSamples), maxSamples_(maxSamples),
139 requiredTolerance_(requiredTolerance), brownianBridge_(brownianBridge), seed_(seed) {
143 template <
class RNG,
class S>
146 std::vector<Time> fixingTimes;
147 for (
Size i=0; i<arguments_.fixingDates.size(); i++) {
148 Time t = processes_->time(arguments_.fixingDates[i]);
149 QL_REQUIRE(
t >= 0.0,
"seasoned options are not handled");
151 QL_REQUIRE(
t > fixingTimes.back(),
"fixing dates not sorted");
153 fixingTimes.push_back(
t);
156 return TimeGrid(fixingTimes.begin(), fixingTimes.end());
160 template <
class RNG,
class S>
162 ext::shared_ptr<typename MCPagodaEngine<RNG,S>::path_pricer_type>
165 ext::shared_ptr<GeneralizedBlackScholesProcess> process =
166 ext::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
167 processes_->process(0));
168 QL_REQUIRE(process,
"Black-Scholes process required");
170 return ext::shared_ptr<
173 process->riskFreeRate()->discount(
174 arguments_.exercise->lastDate())));
178 template <
class RNG,
class S>
180 ext::shared_ptr<StochasticProcessArray> process)
184 template <
class RNG,
class S>
187 brownianBridge_ = brownianBridge;
191 template <
class RNG,
class S>
198 template <
class RNG,
class S>
202 "tolerance already set");
207 template <
class RNG,
class S>
211 "number of samples already set");
213 "chosen random generator policy "
214 "does not allow an error estimate");
215 tolerance_ = tolerance;
219 template <
class RNG,
class S>
222 maxSamples_ = samples;
226 template <
class RNG,
class S>
233 template <
class RNG,
class S>
236 ext::shared_ptr<PricingEngine>()
const {
237 return ext::shared_ptr<PricingEngine>(
new
241 samples_, tolerance_,
PagodaOption::results results_
Pricing engine for pagoda options using Monte Carlo simulation.
MCPagodaEngine(ext::shared_ptr< StochasticProcessArray >, bool brownianBridge, bool antitheticVariate, Size requiredSamples, Real requiredTolerance, Size maxSamples, BigNatural seed)
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< path_pricer_type > pathPricer() const override
ext::shared_ptr< StochasticProcessArray > processes_
TimeGrid timeGrid() const override
Monte Carlo pagoda-option engine factory.
MakeMCPagodaEngine & withMaxSamples(Size samples)
MakeMCPagodaEngine & withAntitheticVariate(bool b=true)
MakeMCPagodaEngine & withBrownianBridge(bool b=true)
MakeMCPagodaEngine & withSamples(Size samples)
MakeMCPagodaEngine & withAbsoluteTolerance(Real tolerance)
MakeMCPagodaEngine(ext::shared_ptr< StochasticProcessArray >)
ext::shared_ptr< StochasticProcessArray > process_
MakeMCPagodaEngine & withSeed(BigNatural seed)
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 > &)
Real operator()(const MultiPath &multiPath) const override
Pagoda-option engine base class
base class for path pricers
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
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
Roofed Asian option on a number of assets.
Array of correlated 1-D stochastic processes.
default Monte Carlo traits for multi-variate models