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 (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 for (
Size i=0; i<arguments_.resetDates.size(); i++)
144 fixingTimes.push_back(process_->time(arguments_.resetDates[i]));
145 fixingTimes.push_back(process_->time(arguments_.exercise->lastDate()));
147 return TimeGrid(fixingTimes.begin(), fixingTimes.end());
151 template <
class RNG,
class S>
153 ext::shared_ptr<typename MCPerformanceEngine<RNG,S>::path_pricer_type>
156 ext::shared_ptr<PercentageStrikePayoff>
payoff =
157 ext::dynamic_pointer_cast<PercentageStrikePayoff>(
158 this->arguments_.payoff);
161 ext::shared_ptr<EuropeanExercise> exercise =
162 ext::dynamic_pointer_cast<EuropeanExercise>(
163 this->arguments_.exercise);
166 std::vector<DiscountFactor> discounts;
168 for (
Size k=0;k<arguments_.resetDates.size();k++) {
169 discounts.push_back(this->process_->riskFreeRate()->discount(
170 arguments_.resetDates[k]));
172 discounts.push_back(this->process_->riskFreeRate()->discount(
173 arguments_.exercise->lastDate()));
175 return ext::shared_ptr<
183 template <
class RNG,
class S>
185 ext::shared_ptr<GeneralizedBlackScholesProcess> process)
189 template <
class RNG,
class S>
192 brownianBridge_ = brownianBridge;
196 template <
class RNG,
class S>
203 template <
class RNG,
class S>
207 "tolerance already set");
212 template <
class RNG,
class S>
216 "number of samples already set");
218 "chosen random generator policy "
219 "does not allow an error estimate");
220 tolerance_ = tolerance;
224 template <
class RNG,
class S>
227 maxSamples_ = samples;
231 template <
class RNG,
class S>
238 template <
class RNG,
class S>
242 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.
ext::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