24#ifndef quantlib_mc_lookback_engines_hpp
25#define quantlib_mc_lookback_engines_hpp
36 template <
class I,
class RNG = PseudoRandom,
class S = Statistics>
47 Size timeStepsPerYear,
51 Real requiredTolerance,
56 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_;
90 template <
class I,
class RNG = PseudoRandom,
class S = Statistics>
104 operator ext::shared_ptr<PricingEngine>()
const;
106 ext::shared_ptr<GeneralizedBlackScholesProcess>
process_;
116 template <
class I,
class RNG,
class S>
118 ext::shared_ptr<GeneralizedBlackScholesProcess> process,
120 Size timeStepsPerYear,
122 bool antitheticVariate,
123 Size requiredSamples,
124 Real requiredTolerance,
128 timeSteps_(timeSteps), timeStepsPerYear_(timeStepsPerYear), requiredSamples_(requiredSamples),
129 maxSamples_(maxSamples), requiredTolerance_(requiredTolerance),
130 brownianBridge_(brownianBridge), seed_(seed) {
133 "no time steps provided");
136 "both time steps and time steps per year were provided");
138 "timeSteps must be positive, " << timeSteps <<
141 "timeStepsPerYear must be positive, " << timeStepsPerYear <<
147 template <
class I,
class RNG,
class S>
150 Time residualTime = process_->time(this->arguments_.exercise->lastDate());
152 return TimeGrid(residualTime, timeSteps_);
153 }
else if (timeStepsPerYear_ !=
Null<Size>()) {
154 Size steps =
static_cast<Size>(timeStepsPerYear_*residualTime);
155 return TimeGrid(residualTime, std::max<Size>(steps, 1));
157 QL_FAIL(
"time steps not specified");
166 ext::shared_ptr<PathPricer<Path> >
172 ext::shared_ptr<PathPricer<Path> >
178 ext::shared_ptr<PathPricer<Path> >
184 ext::shared_ptr<PathPricer<Path> >
193 template <
class I,
class RNG,
class S>
194 inline ext::shared_ptr<typename MCLookbackEngine<I,RNG,S>::path_pricer_type>
205 template <
class I,
class RNG,
class S>
207 ext::shared_ptr<GeneralizedBlackScholesProcess> process)
211 template <
class I,
class RNG,
class S>
218 template <
class I,
class RNG,
class S>
221 stepsPerYear_ = steps;
225 template <
class I,
class RNG,
class S>
228 brownianBridge_ = brownianBridge;
232 template <
class I,
class RNG,
class S>
239 template <
class I,
class RNG,
class S>
243 "tolerance already set");
248 template <
class I,
class RNG,
class S>
252 "number of samples already set");
254 "chosen random generator policy "
255 "does not allow an error estimate");
256 tolerance_ = tolerance;
260 template <
class I,
class RNG,
class S>
263 maxSamples_ = samples;
267 template <
class I,
class RNG,
class S>
274 template <
class I,
class RNG,
class S>
277 "number of steps not given");
279 "number of steps overspecified");
281 return ext::shared_ptr<PricingEngine>(
const Instrument::results * results_
Arguments for continuous fixed lookback option calculation
Arguments for continuous floating lookback option calculation
Arguments for continuous partial fixed lookback option calculation
Arguments for continuous partial floating lookback option calculation
Generalized Black-Scholes stochastic process.
Monte Carlo lookback-option engine.
McSimulation< SingleVariate, RNG, S >::path_generator_type path_generator_type
ext::shared_ptr< path_generator_type > pathGenerator() const override
void calculate() const override
ext::shared_ptr< path_pricer_type > pathPricer() const override
MCLookbackEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > process, Size timeSteps, Size timeStepsPerYear, bool brownianBridge, bool antithetic, Size requiredSamples, Real requiredTolerance, Size maxSamples, BigNatural seed)
McSimulation< SingleVariate, RNG, S >::path_pricer_type path_pricer_type
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
TimeGrid timeGrid() const override
Monte Carlo lookback-option engine factory.
MakeMCLookbackEngine & withSeed(BigNatural seed)
MakeMCLookbackEngine & withMaxSamples(Size samples)
MakeMCLookbackEngine & withAntitheticVariate(bool b=true)
MakeMCLookbackEngine & withStepsPerYear(Size steps)
MakeMCLookbackEngine & withSamples(Size samples)
MakeMCLookbackEngine(ext::shared_ptr< GeneralizedBlackScholesProcess >)
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
MakeMCLookbackEngine & withAbsoluteTolerance(Real tolerance)
MakeMCLookbackEngine & withSteps(Size steps)
MakeMCLookbackEngine & withBrownianBridge(bool b=true)
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.
#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
Lookback option on a single asset.
framework for Monte Carlo engines
ext::shared_ptr< PathPricer< Path > > mc_lookback_path_pricer(const ContinuousFixedLookbackOption::arguments &args, const GeneralizedBlackScholesProcess &process, DiscountFactor discount)
unsigned QL_BIG_INTEGER BigNatural
large positive integer
default Monte Carlo traits for single-variate models