20#ifndef quantlib_mc_performance_engine_hpp
21#define quantlib_mc_performance_engine_hpp
32 template<
class RNG = PseudoRandom,
class S = Statistics>
46 bool antitheticVariate,
48 Real requiredTolerance,
56 if constexpr (RNG::allowsErrorEstimate)
58 this->mcModel_->sampleAccumulator().errorEstimate();
67 typename RNG::rsg_type gen =
68 RNG::make_sequence_generator(grid.
size()-1,
seed_);
69 return ext::shared_ptr<path_generator_type>(
73 ext::shared_ptr<path_pricer_type>
pathPricer()
const override;
75 ext::shared_ptr<GeneralizedBlackScholesProcess>
process_;
84 template <
class RNG = PseudoRandom,
class S = Statistics>
96 operator ext::shared_ptr<PricingEngine>()
const;
98 ext::shared_ptr<GeneralizedBlackScholesProcess>
process_;
111 std::vector<DiscountFactor> discounts);
123 template <
class RNG,
class S>
125 ext::shared_ptr<GeneralizedBlackScholesProcess> process,
127 bool antitheticVariate,
128 Size requiredSamples,
129 Real requiredTolerance,
133 requiredSamples_(requiredSamples), maxSamples_(maxSamples),
134 requiredTolerance_(requiredTolerance), brownianBridge_(brownianBridge), seed_(seed) {
139 template <
class RNG,
class S>
142 std::vector<Time> fixingTimes;
143 fixingTimes.reserve(arguments_.resetDates.size());
144 for (
Size i=0; i<arguments_.resetDates.size(); i++)
145 fixingTimes.push_back(process_->time(arguments_.resetDates[i]));
146 fixingTimes.push_back(process_->time(arguments_.exercise->lastDate()));
148 return TimeGrid(fixingTimes.begin(), fixingTimes.end());
152 template <
class RNG,
class S>
154 ext::shared_ptr<typename MCPerformanceEngine<RNG,S>::path_pricer_type>
157 ext::shared_ptr<PercentageStrikePayoff>
payoff =
158 ext::dynamic_pointer_cast<PercentageStrikePayoff>(
159 this->arguments_.payoff);
162 ext::shared_ptr<EuropeanExercise> exercise =
163 ext::dynamic_pointer_cast<EuropeanExercise>(
164 this->arguments_.exercise);
167 std::vector<DiscountFactor> discounts;
169 discounts.reserve(arguments_.resetDates.size());
170 for (
Size k=0;k<arguments_.resetDates.size();k++) {
171 discounts.push_back(this->process_->riskFreeRate()->discount(
172 arguments_.resetDates[k]));
174 discounts.push_back(this->process_->riskFreeRate()->discount(
175 arguments_.exercise->lastDate()));
177 return ext::shared_ptr<
185 template <
class RNG,
class S>
187 ext::shared_ptr<GeneralizedBlackScholesProcess> process)
191 template <
class RNG,
class S>
194 brownianBridge_ = brownianBridge;
198 template <
class RNG,
class S>
205 template <
class RNG,
class S>
209 "tolerance already set");
214 template <
class RNG,
class S>
218 "number of samples already set");
220 "chosen random generator policy "
221 "does not allow an error estimate");
222 tolerance_ = tolerance;
226 template <
class RNG,
class S>
229 maxSamples_ = samples;
233 template <
class RNG,
class S>
240 template <
class RNG,
class S>
244 return ext::shared_ptr<PricingEngine>(
new
Cliquet engine base class.
CliquetOption::results results_
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
template class providing a null value for a given type.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
single-factor random walk
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.
std::function< Real(Real)> b
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
default Monte Carlo traits for single-variate models