20#ifndef quantlib_american_path_montecarlo_engine_hpp
21#define quantlib_american_path_montecarlo_engine_hpp
39 template <
class RNG = PseudoRandom>
42 PathMultiAssetOption::engine,MultiVariate,RNG> {
46 Size timeStepsPerYear,
48 bool antitheticVariate,
51 Real requiredTolerance,
56 ext::shared_ptr<LongstaffSchwartzMultiPathPricer>
62 template <
class RNG = PseudoRandom>
78 operator ext::shared_ptr<PricingEngine>()
const;
80 ext::shared_ptr<StochasticProcessArray>
process_;
88 template <
class RNG>
inline
90 const ext::shared_ptr<StochasticProcessArray>& processes,
92 Size timeStepsPerYear,
94 bool antitheticVariate,
97 Real requiredTolerance,
100 Size nCalibrationSamples)
112 nCalibrationSamples) {}
115 inline ext::shared_ptr<LongstaffSchwartzMultiPathPricer>
118 ext::shared_ptr<StochasticProcessArray> processArray =
119 ext::dynamic_pointer_cast<StochasticProcessArray>(this->process_);
120 QL_REQUIRE(processArray && processArray->size()>0,
121 "Stochastic process array required");
123 ext::shared_ptr<GeneralizedBlackScholesProcess> process =
124 ext::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
125 processArray->process(0));
126 QL_REQUIRE(process,
"generalized Black-Scholes process required");
128 const TimeGrid theTimeGrid = this->timeGrid();
131 const Size numberOfTimes = times.size();
133 const std::vector<Date> & fixings = this->arguments_.fixingDates;
135 QL_REQUIRE(fixings.size() == numberOfTimes,
"Invalid dates/times");
137 std::vector<Size> timePositions(numberOfTimes);
138 Array discountFactors(numberOfTimes);
139 std::vector<Handle<YieldTermStructure> > forwardTermStructures(numberOfTimes);
143 for (
Size i = 0; i < numberOfTimes; ++i) {
144 timePositions[i] = theTimeGrid.
index(times[i]);
145 discountFactors[i] = riskFreeRate->discount(times[i]);
147 ext::make_shared<ImpliedTermStructure>(riskFreeRate,
151 const Size polynomialOrder = 2;
154 return ext::make_shared<LongstaffSchwartzMultiPathPricer> (
155 this->arguments_.payoff,
157 forwardTermStructures,
166 ext::shared_ptr<StochasticProcessArray> process)
167 : process_(
std::move(process)), brownianBridge_(false), antithetic_(false),
170 tolerance_(
Null<
Real>()), seed_(0) {}
182 stepsPerYear_ = steps;
189 brownianBridge_ = brownianBridge;
211 "tolerance already set");
220 "number of samples already set");
222 "chosen random generator policy "
223 "does not allow an error estimate");
224 tolerance_ = tolerance;
231 maxSamples_ = samples;
245 calibrationSamples_ = samples;
252 ext::shared_ptr<PricingEngine>()
const {
254 "number of steps not given");
256 "number of steps overspecified");
257 return ext::shared_ptr<PricingEngine>(
new
268 calibrationSamples_));
1-D array used in linear algebra.
Shared handle to an observable.
least-square Monte Carlo engine
MCAmericanPathEngine(const ext::shared_ptr< StochasticProcessArray > &, Size timeSteps, Size timeStepsPerYear, bool brownianBridge, bool antitheticVariate, bool controlVariate, Size requiredSamples, Real requiredTolerance, Size maxSamples, BigNatural seed, Size nCalibrationSamples=Null< Size >())
ext::shared_ptr< LongstaffSchwartzMultiPathPricer > lsmPathPricer() const
Longstaff-Schwarz Monte Carlo engine for early exercise options.
Monte Carlo American basket-option engine factory.
MakeMCAmericanPathEngine & withSteps(Size steps)
MakeMCAmericanPathEngine & withControlVariate(bool b=true)
MakeMCAmericanPathEngine & withSeed(BigNatural seed)
MakeMCAmericanPathEngine & withBrownianBridge(bool b=true)
MakeMCAmericanPathEngine & withAntitheticVariate(bool b=true)
MakeMCAmericanPathEngine & withCalibrationSamples(Size samples)
MakeMCAmericanPathEngine & withAbsoluteTolerance(Real tolerance)
ext::shared_ptr< StochasticProcessArray > process_
MakeMCAmericanPathEngine & withMaxSamples(Size samples)
MakeMCAmericanPathEngine & withSamples(Size samples)
MakeMCAmericanPathEngine(ext::shared_ptr< StochasticProcessArray >)
MakeMCAmericanPathEngine & withStepsPerYear(Size steps)
template class providing a null value for a given type.
Base class for path-dependent options on multiple assets.
Size index(Time t) const
returns the index i such that grid[i] = t
const std::vector< Time > & mandatoryTimes() const
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
ext::function< Real(Real)> b
std::size_t Size
size of a container
unsigned QL_BIG_INTEGER BigNatural
large positive integer
Option on multiple assets.
Array of correlated 1-D stochastic processes.
default Monte Carlo traits for multi-variate models