26#ifndef quantlib_american_basket_montecarlo_engine_hpp
27#define quantlib_american_basket_montecarlo_engine_hpp
47 template <
class RNG = PseudoRandom>
54 Size timeStepsPerYear,
56 bool antitheticVariate,
58 Real requiredTolerance,
62 Size polynomialOrder = 2,
65 ext::shared_ptr<LongstaffSchwartzPathPricer<MultiPath> >
lsmPathPricer()
const override;
74 template <
class RNG = PseudoRandom>
92 operator ext::shared_ptr<PricingEngine>()
const;
94 ext::shared_ptr<StochasticProcessArray>
process_;
109 ext::shared_ptr<Payoff>
payoff,
110 Size polynomialOrder = 2,
128 template <
class RNG>
inline
130 const ext::shared_ptr<StochasticProcessArray>& processes,
132 Size timeStepsPerYear,
134 bool antitheticVariate,
135 Size requiredSamples,
136 Real requiredTolerance,
139 Size nCalibrationSamples,
140 Size polynomialOrder,
153 nCalibrationSamples),
154 polynomialOrder_(polynomialOrder), polynomialType_(polynomialType) {}
157 inline ext::shared_ptr<LongstaffSchwartzPathPricer<MultiPath> >
160 ext::shared_ptr<StochasticProcessArray> processArray =
161 ext::dynamic_pointer_cast<StochasticProcessArray>(
163 QL_REQUIRE(processArray && processArray->size()>0,
164 "Stochastic process array required");
166 ext::shared_ptr<GeneralizedBlackScholesProcess> process =
167 ext::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
168 processArray->process(0));
169 QL_REQUIRE(process,
"generalized Black-Scholes process required");
171 ext::shared_ptr<EarlyExercise> exercise =
172 ext::dynamic_pointer_cast<EarlyExercise>(
173 this->arguments_.exercise);
176 "payoff at expiry not handled");
178 ext::shared_ptr<AmericanBasketPathPricer> earlyExercisePathPricer(
180 this->arguments_.payoff,
184 return ext::make_shared<LongstaffSchwartzPathPricer<MultiPath> > (
187 earlyExercisePathPricer,
188 *(process->riskFreeRate()));
194 ext::shared_ptr<StochasticProcessArray> process)
209 stepsPerYear_ = steps;
216 brownianBridge_ = brownianBridge;
231 "tolerance already set");
240 "number of samples already set");
242 "chosen random generator policy "
243 "does not allow an error estimate");
244 tolerance_ = tolerance;
251 maxSamples_ = samples;
265 calibrationSamples_ = samples;
272 polynomialOrder_ = polynomialOrder;
279 polynomialType_ = polynomialType;
286 ext::shared_ptr<PricingEngine>()
const {
288 "number of steps not given");
290 "number of steps overspecified");
291 return ext::shared_ptr<PricingEngine>(
new
Basket option on a number of assets.
Real operator()(const MultiPath &path, Size t) const override
Array state(const MultiPath &path, Size t) const override
std::vector< ext::function< Real(Array)> > basisSystem() const override
std::vector< ext::function< Real(Array)> > v_
const ext::shared_ptr< Payoff > payoff_
1-D array used in linear algebra.
Basket option on a number of assets.
base class for early exercise path pricers
least-square Monte Carlo engine
const LsmBasisSystem::PolynomialType polynomialType_
const Size polynomialOrder_
ext::shared_ptr< LongstaffSchwartzPathPricer< MultiPath > > lsmPathPricer() const override
MCAmericanBasketEngine(const ext::shared_ptr< StochasticProcessArray > &, Size timeSteps, Size timeStepsPerYear, bool brownianBridge, bool antitheticVariate, Size requiredSamples, Real requiredTolerance, Size maxSamples, BigNatural seed, Size nCalibrationSamples=Null< Size >(), Size polynomialOrder=2, LsmBasisSystem::PolynomialType polynomialType=LsmBasisSystem::Monomial)
Longstaff-Schwarz Monte Carlo engine for early exercise options.
Monte Carlo American basket-option engine factory.
MakeMCAmericanBasketEngine & withSamples(Size samples)
MakeMCAmericanBasketEngine & withCalibrationSamples(Size samples)
MakeMCAmericanBasketEngine & withBrownianBridge(bool b=true)
MakeMCAmericanBasketEngine & withBasisSystem(LsmBasisSystem::PolynomialType polynomialType)
LsmBasisSystem::PolynomialType polynomialType_
MakeMCAmericanBasketEngine & withMaxSamples(Size samples)
MakeMCAmericanBasketEngine & withAntitheticVariate(bool b=true)
MakeMCAmericanBasketEngine(ext::shared_ptr< StochasticProcessArray >)
MakeMCAmericanBasketEngine & withPolynomialOrder(Size polynmOrder)
MakeMCAmericanBasketEngine & withSeed(BigNatural seed)
ext::shared_ptr< StochasticProcessArray > process_
MakeMCAmericanBasketEngine & withStepsPerYear(Size steps)
MakeMCAmericanBasketEngine & withAbsoluteTolerance(Real tolerance)
MakeMCAmericanBasketEngine & withSteps(Size steps)
Correlated multiple asset paths.
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
Option exercise classes and payoff function.
ext::function< Real(Real)> b
Maps function, bind and cref to either the boost or std implementation.
std::size_t Size
size of a container
ext::shared_ptr< QuantLib::Payoff > payoff
utility classes for Longstaff-Schwartz early-exercise Monte Carlo
Longstaff Schwartz Monte Carlo engine for early exercise options.
unsigned QL_BIG_INTEGER BigNatural
large positive integer
Global definitions and compiler switches.
Array of correlated 1-D stochastic processes.
default Monte Carlo traits for multi-variate models