25#ifndef quantlib_mc_european_basket_engine_hpp
26#define quantlib_mc_european_basket_engine_hpp
43 template <
class RNG = PseudoRandom,
class S = Statistics>
56 Size timeStepsPerYear,
58 bool antitheticVariate,
60 Real requiredTolerance,
68 if (RNG::allowsErrorEstimate)
70 this->
mcModel_->sampleAccumulator().errorEstimate();
78 ext::shared_ptr<BasketPayoff>
payoff =
79 ext::dynamic_pointer_cast<BasketPayoff>(
86 typename RNG::rsg_type gen =
87 RNG::make_sequence_generator(numAssets*(grid.
size()-1),
seed_);
89 return ext::shared_ptr<path_generator_type>(
93 ext::shared_ptr<path_pricer_type>
pathPricer()
const override;
106 template <
class RNG = PseudoRandom,
class S = Statistics>
120 operator ext::shared_ptr<PricingEngine>()
const;
143 template <
class RNG,
class S>
145 ext::shared_ptr<StochasticProcessArray> processes,
147 Size timeStepsPerYear,
149 bool antitheticVariate,
150 Size requiredSamples,
151 Real requiredTolerance,
155 processes_(
std::move(processes)), timeSteps_(timeSteps), timeStepsPerYear_(timeStepsPerYear),
156 requiredSamples_(requiredSamples), maxSamples_(maxSamples),
157 requiredTolerance_(requiredTolerance), brownianBridge_(brownianBridge), seed_(seed) {
160 "no time steps provided");
163 "both time steps and time steps per year were provided");
165 "timeSteps must be positive, " << timeSteps <<
168 "timeStepsPerYear must be positive, " << timeStepsPerYear <<
173 template <
class RNG,
class S>
176 Time residualTime = processes_->time(
177 this->arguments_.exercise->lastDate());
179 return TimeGrid(residualTime, timeSteps_);
180 }
else if (timeStepsPerYear_ !=
Null<Size>()) {
181 Size steps =
static_cast<Size>(timeStepsPerYear_*residualTime);
182 return TimeGrid(residualTime, std::max<Size>(steps, 1));
184 QL_FAIL(
"time steps not specified");
188 template <
class RNG,
class S>
190 ext::shared_ptr<typename MCEuropeanBasketEngine<RNG,S>::path_pricer_type>
193 ext::shared_ptr<BasketPayoff>
payoff =
194 ext::dynamic_pointer_cast<BasketPayoff>(arguments_.payoff);
197 ext::shared_ptr<GeneralizedBlackScholesProcess> process =
198 ext::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
199 processes_->process(0));
200 QL_REQUIRE(process,
"Black-Scholes process required");
202 return ext::shared_ptr<
205 process->riskFreeRate()->discount(
206 arguments_.exercise->lastDate())));
210 template <
class RNG,
class S>
212 ext::shared_ptr<StochasticProcessArray> process)
216 template <
class RNG,
class S>
223 template <
class RNG,
class S>
226 stepsPerYear_ = steps;
230 template <
class RNG,
class S>
233 brownianBridge_ = brownianBridge;
237 template <
class RNG,
class S>
244 template <
class RNG,
class S>
248 "tolerance already set");
253 template <
class RNG,
class S>
257 "number of samples already set");
259 "chosen random generator policy "
260 "does not allow an error estimate");
261 tolerance_ = tolerance;
265 template <
class RNG,
class S>
268 maxSamples_ = samples;
272 template <
class RNG,
class S>
279 template <
class RNG,
class S>
282 ext::shared_ptr<PricingEngine>()
const {
284 "number of steps not given");
286 "number of steps overspecified");
287 return ext::shared_ptr<PricingEngine>(
new
293 samples_, tolerance_,
Basket option on a number of assets.
Basket-option engine base class
ext::shared_ptr< BasketPayoff > payoff_
Real operator()(const MultiPath &multiPath) const override
BasketOption::results results_
BasketOption::arguments arguments_
Pricing engine for European basket options using Monte Carlo simulation.
MCEuropeanBasketEngine(ext::shared_ptr< StochasticProcessArray >, Size timeSteps, Size timeStepsPerYear, 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
ext::shared_ptr< path_pricer_type > pathPricer() const override
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 basket-option engine factory.
MakeMCEuropeanBasketEngine & withAbsoluteTolerance(Real tolerance)
MakeMCEuropeanBasketEngine & withSeed(BigNatural seed)
MakeMCEuropeanBasketEngine & withSamples(Size samples)
MakeMCEuropeanBasketEngine & withStepsPerYear(Size steps)
MakeMCEuropeanBasketEngine & withAntitheticVariate(bool b=true)
MakeMCEuropeanBasketEngine & withBrownianBridge(bool b=true)
MakeMCEuropeanBasketEngine & withMaxSamples(Size samples)
ext::shared_ptr< StochasticProcessArray > process_
MakeMCEuropeanBasketEngine & withSteps(Size steps)
MakeMCEuropeanBasketEngine(ext::shared_ptr< StochasticProcessArray >)
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 > &)
ext::shared_ptr< Payoff > payoff
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)
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
ext::shared_ptr< QuantLib::Payoff > payoff
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