25#ifndef quantlib_mcvanilla_engine_hpp
26#define quantlib_mcvanilla_engine_hpp
35 template <
template <
class>
class MC,
class RNG,
45 if (RNG::allowsErrorEstimate)
47 this->
mcModel_->sampleAccumulator().errorEstimate();
62 Size timeStepsPerYear,
64 bool antitheticVariate,
67 Real requiredTolerance,
76 typename RNG::rsg_type generator =
77 RNG::make_sequence_generator(dimensions*(grid.
size()-1),
seed_);
78 return ext::shared_ptr<path_generator_type>(
95 template <
template <
class>
class MC,
class RNG,
class S,
class Inst>
97 ext::shared_ptr<StochasticProcess> process,
99 Size timeStepsPerYear,
101 bool antitheticVariate,
103 Size requiredSamples,
104 Real requiredTolerance,
107 :
McSimulation<MC, RNG,
S>(antitheticVariate, controlVariate), process_(
std::move(process)),
108 timeSteps_(timeSteps), timeStepsPerYear_(timeStepsPerYear), requiredSamples_(requiredSamples),
109 maxSamples_(maxSamples), requiredTolerance_(requiredTolerance),
110 brownianBridge_(brownianBridge), seed_(seed) {
113 "no time steps provided");
116 "both time steps and time steps per year were provided");
118 "timeSteps must be positive, " << timeSteps <<
121 "timeStepsPerYear must be positive, " << timeStepsPerYear <<
126 template <
template <
class>
class MC,
class RNG,
class S,
class Inst>
130 ext::shared_ptr<PricingEngine> controlPE =
131 this->controlPricingEngine();
133 "engine does not provide "
134 "control variation pricing engine");
136 auto* controlArguments =
dynamic_cast<typename Inst::arguments*
>(controlPE->getArguments());
138 QL_REQUIRE(controlArguments,
"engine is using inconsistent arguments");
140 *controlArguments = this->arguments_;
141 controlPE->calculate();
143 const auto* controlResults =
144 dynamic_cast<const typename Inst::results*
>(controlPE->getResults());
146 "engine returns an inconsistent result type");
152 template <
template <
class>
class MC,
class RNG,
class S,
class Inst>
154 Date lastExerciseDate = this->arguments_.exercise->lastDate();
155 Time t = process_->time(lastExerciseDate);
158 }
else if (this->timeStepsPerYear_ !=
Null<Size>()) {
159 Size steps =
static_cast<Size>(this->timeStepsPerYear_*
t);
160 return TimeGrid(
t, std::max<Size>(steps, 1));
162 QL_FAIL(
"time steps not specified");
const Instrument::results * results_
Pricing engine for vanilla options using Monte Carlo simulation.
McSimulation< MC, RNG, S >::result_type result_type
ext::shared_ptr< StochasticProcess > process_
McSimulation< MC, RNG, S >::path_generator_type path_generator_type
result_type controlVariateValue() const override
ext::shared_ptr< path_generator_type > pathGenerator() const override
void calculate() const override
McSimulation< MC, RNG, S >::path_pricer_type path_pricer_type
McSimulation< MC, RNG, S >::stats_type stats_type
MCVanillaEngine(ext::shared_ptr< StochasticProcess >, Size timeSteps, Size timeStepsPerYear, bool brownianBridge, bool antitheticVariate, bool controlVariate, Size requiredSamples, Real requiredTolerance, Size maxSamples, BigNatural seed)
TimeGrid timeGrid() const override
base class for Monte Carlo engines
MonteCarloModel< MC, RNG, S >::path_generator_type path_generator_type
MonteCarloModel< MC, RNG, S >::result_type result_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
template class providing a null value for a given type.
#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)
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
framework for Monte Carlo engines
RiskStatistics Statistics
default statistics tool
unsigned QL_BIG_INTEGER BigNatural
large positive integer
Vanilla option on a single asset.