24#ifndef quantlib_mc_double_barrier_engines_hpp
25#define quantlib_mc_double_barrier_engines_hpp
35 template <
class RNG = PseudoRandom,
class S = Statistics>
46 Size timeStepsPerYear,
50 Real requiredTolerance,
55 QL_REQUIRE(spot > 0.0,
"negative or null underlying given");
61 if (RNG::allowsErrorEstimate)
63 this->
mcModel_->sampleAccumulator().errorEstimate();
71 typename RNG::rsg_type gen =
72 RNG::make_sequence_generator(grid.
size()-1,
seed_);
73 return ext::shared_ptr<path_generator_type>(
77 ext::shared_ptr<path_pricer_type>
pathPricer()
const override;
79 ext::shared_ptr<GeneralizedBlackScholesProcess>
process_;
89 template <
class RNG = PseudoRandom,
class S = Statistics>
103 operator ext::shared_ptr<PricingEngine>()
const;
105 ext::shared_ptr<GeneralizedBlackScholesProcess>
process_;
120 std::vector<DiscountFactor> discounts);
134 template <
class RNG,
class S>
136 ext::shared_ptr<GeneralizedBlackScholesProcess> process,
138 Size timeStepsPerYear,
140 bool antitheticVariate,
141 Size requiredSamples,
142 Real requiredTolerance,
146 timeSteps_(timeSteps), timeStepsPerYear_(timeStepsPerYear), requiredSamples_(requiredSamples),
147 maxSamples_(maxSamples), requiredTolerance_(requiredTolerance),
148 brownianBridge_(brownianBridge), seed_(seed) {
151 "no time steps provided");
154 "both time steps and time steps per year were provided");
156 "timeSteps must be positive, " << timeSteps <<
159 "timeStepsPerYear must be positive, " << timeStepsPerYear <<
164 template <
class RNG,
class S>
167 Time residualTime = process_->time(arguments_.exercise->lastDate());
169 return TimeGrid(residualTime, timeSteps_);
170 }
else if (timeStepsPerYear_ !=
Null<Size>()) {
171 Size steps =
static_cast<Size>(timeStepsPerYear_*residualTime);
172 return TimeGrid(residualTime, std::max<Size>(steps, 1));
174 QL_FAIL(
"time steps not specified");
178 template <
class RNG,
class S>
180 ext::shared_ptr<typename MCDoubleBarrierEngine<RNG,S>::path_pricer_type>
182 ext::shared_ptr<PlainVanillaPayoff>
payoff =
183 ext::dynamic_pointer_cast<PlainVanillaPayoff>(arguments_.payoff);
187 std::vector<DiscountFactor> discounts(grid.
size());
189 discounts[i] = process_->riskFreeRate()->discount(grid[i]);
191 return ext::shared_ptr<
194 arguments_.barrierType,
195 arguments_.barrier_lo,
196 arguments_.barrier_hi,
203 template <
class RNG,
class S>
205 ext::shared_ptr<GeneralizedBlackScholesProcess> process)
209 template <
class RNG,
class S>
216 template <
class RNG,
class S>
219 stepsPerYear_ = steps;
223 template <
class RNG,
class S>
226 brownianBridge_ = brownianBridge;
230 template <
class RNG,
class S>
237 template <
class RNG,
class S>
241 "tolerance already set");
246 template <
class RNG,
class S>
250 "number of samples already set");
252 "chosen random generator policy "
253 "does not allow an error estimate");
254 tolerance_ = tolerance;
258 template <
class RNG,
class S>
261 maxSamples_ = samples;
265 template <
class RNG,
class S>
272 template <
class RNG,
class S>
277 "number of steps not given");
279 "number of steps overspecified");
280 return ext::shared_ptr<PricingEngine>(
new
Double-Barrier-option engine base class
bool triggered(Real underlying) const
PlainVanillaPayoff payoff_
std::vector< DiscountFactor > discounts_
DoubleBarrier::Type barrierType_
Real operator()(const Path &path) const override
DoubleBarrierOption::results results_
McSimulation< SingleVariate, RNG, S >::path_generator_type path_generator_type
MCDoubleBarrierEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > process, Size timeSteps, Size timeStepsPerYear, bool brownianBridge, bool antithetic, Size requiredSamples, Real requiredTolerance, Size maxSamples, BigNatural seed)
ext::shared_ptr< path_generator_type > pathGenerator() const override
void calculate() const override
ext::shared_ptr< path_pricer_type > pathPricer() const override
McSimulation< SingleVariate, RNG, S >::path_pricer_type path_pricer_type
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
TimeGrid timeGrid() const override
Monte Carlo double-barrier-option engine factory.
MakeMCDoubleBarrierEngine & withAbsoluteTolerance(Real tolerance)
MakeMCDoubleBarrierEngine & withSeed(BigNatural seed)
MakeMCDoubleBarrierEngine & withSamples(Size samples)
MakeMCDoubleBarrierEngine & withBrownianBridge(bool b=true)
MakeMCDoubleBarrierEngine(ext::shared_ptr< GeneralizedBlackScholesProcess >)
MakeMCDoubleBarrierEngine & withMaxSamples(Size samples)
MakeMCDoubleBarrierEngine & withSteps(Size steps)
MakeMCDoubleBarrierEngine & withAntitheticVariate(bool b=true)
MakeMCDoubleBarrierEngine & withStepsPerYear(Size steps)
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
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
double Barrier european option on a single asset
#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
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