24#ifndef quantlib_mc_path_basket_engine_hpp
25#define quantlib_mc_path_basket_engine_hpp
40 template <
class RNG = PseudoRandom,
class S = Statistics>
53 Size timeStepsPerYear,
55 bool antitheticVariate,
58 Real requiredTolerance,
67 if (RNG::allowsErrorEstimate)
69 this->
mcModel_->sampleAccumulator().errorEstimate();
77 ext::shared_ptr<path_pricer_type>
pathPricer()
const;
80 ext::shared_ptr<StochasticProcessArray>
process_;
94 std::vector<Size> timePositions,
109 template <
class RNG,
class S>
111 ext::shared_ptr<StochasticProcessArray> process,
113 Size timeStepsPerYear,
115 bool antitheticVariate,
117 Size requiredSamples,
118 Real requiredTolerance,
122 process_(
std::move(process)), timeSteps_(timeSteps), timeStepsPerYear_(timeStepsPerYear),
123 requiredSamples_(requiredSamples), maxSamples_(maxSamples),
124 requiredTolerance_(requiredTolerance), brownianBridge_(brownianBridge), seed_(seed) {
127 "no time steps provided");
130 "both time steps and time steps per year were provided");
132 "timeSteps must be positive, " << timeSteps <<
135 "timeStepsPerYear must be positive, "
136 << timeStepsPerYear <<
" not allowed");
141 template<
class RNG,
class S>
143 ext::shared_ptr<typename MCPathBasketEngine<RNG,S>::path_generator_type>
146 ext::shared_ptr<PathPayoff>
payoff = arguments_.payoff;
149 Size numAssets = process_->size();
153 typename RNG::rsg_type gen =
154 RNG::make_sequence_generator(numAssets * (grid.
size() - 1), seed_);
156 return ext::shared_ptr<path_generator_type>(
158 grid, gen, brownianBridge_));
161 template <
class RNG,
class S>
163 const std::vector<Date> & fixings = this->arguments_.fixingDates;
164 const Size numberOfFixings = fixings.
size();
166 std::vector<Time> fixingTimes(numberOfFixings);
167 for (
Size i = 0; i < numberOfFixings; ++i) {
169 this->process_->time(fixings[i]);
172 const Size numberOfTimeSteps = timeSteps_ !=
Null<Size>() ? timeSteps_ :
static_cast<Size>(timeStepsPerYear_ * fixingTimes.back());
174 return TimeGrid(fixingTimes.begin(), fixingTimes.end(), numberOfTimeSteps);
177 template <
class RNG,
class S>
179 ext::shared_ptr<typename MCPathBasketEngine<RNG,S>::path_pricer_type>
182 ext::shared_ptr<PathPayoff>
payoff = arguments_.payoff;
185 ext::shared_ptr<GeneralizedBlackScholesProcess> process =
186 ext::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
187 process_->process(0));
188 QL_REQUIRE(process,
"Black-Scholes process required");
190 const TimeGrid theTimeGrid = timeGrid();
193 const Size numberOfTimes = times.size();
195 const std::vector<Date> & fixings = this->arguments_.fixingDates;
197 QL_REQUIRE(fixings.size() == numberOfTimes,
"Invalid dates/times");
199 std::vector<Size> timePositions(numberOfTimes);
200 Array discountFactors(numberOfTimes);
201 std::vector<Handle<YieldTermStructure> > forwardTermStructures(numberOfTimes);
205 for (
Size i = 0; i < numberOfTimes; ++i) {
206 timePositions[i] = theTimeGrid.
index(times[i]);
207 discountFactors[i] = riskFreeRate->discount(times[i]);
209 ext::make_shared<ImpliedTermStructure>(riskFreeRate,
213 return ext::shared_ptr<
216 forwardTermStructures,
222 template <
class RNG = PseudoRandom,
class S = Statistics>
237 operator ext::shared_ptr<PricingEngine>()
const;
247 template <
class RNG,
class S>
249 ext::shared_ptr<StochasticProcessArray> process)
253 template <
class RNG,
class S>
260 template <
class RNG,
class S>
263 stepsPerYear_ = steps;
267 template <
class RNG,
class S>
271 "tolerance already set");
276 template <
class RNG,
class S>
280 "number of samples already set");
282 "chosen random generator policy "
283 "does not allow an error estimate");
284 tolerance_ = tolerance;
288 template <
class RNG,
class S>
291 maxSamples_ = samples;
295 template <
class RNG,
class S>
302 template <
class RNG,
class S>
305 brownianBridge_ = brownianBridge;
309 template <
class RNG,
class S>
316 template <
class RNG,
class S>
323 template <
class RNG,
class S>
327 return ext::shared_ptr<PricingEngine>(
new
1-D array used in linear algebra.
ext::shared_ptr< PathPayoff > payoff_
std::vector< Handle< YieldTermStructure > > forwardTermStructures_
std::vector< Size > timePositions_
Real operator()(const MultiPath &multiPath) const override
PathMultiAssetOption::results results_
Shared handle to an observable.
Pricing engine for path dependent basket options using.
MCPathBasketEngine(ext::shared_ptr< StochasticProcessArray >, Size timeSteps, Size timeStepsPerYear, bool brownianBridge, bool antitheticVariate, bool controlVariate, Size requiredSamples, Real requiredTolerance, Size maxSamples, BigNatural seed)
ext::shared_ptr< path_generator_type > pathGenerator() const
void calculate() const override
McSimulation< MultiVariate, RNG, S >::path_pricer_type path_pricer_type
McSimulation< MultiVariate, RNG, S >::stats_type stats_type
McSimulation< MultiVariate, RNG, S >::path_generator_type path_generator_type
TimeGrid timeGrid() const
ext::shared_ptr< path_pricer_type > pathPricer() const
ext::shared_ptr< StochasticProcessArray > process_
Monte Carlo Path Basket engine factory.
MakeMCPathBasketEngine & withSamples(Size samples)
MakeMCPathBasketEngine & withControlVariate(bool b=true)
MakeMCPathBasketEngine & withStepsPerYear(Size steps)
MakeMCPathBasketEngine & withMaxSamples(Size samples)
MakeMCPathBasketEngine & withSeed(BigNatural seed)
MakeMCPathBasketEngine & withSteps(Size steps)
MakeMCPathBasketEngine & withAbsoluteTolerance(Real tolerance)
MakeMCPathBasketEngine & withBrownianBridge(bool b=true)
ext::shared_ptr< StochasticProcessArray > process_
MakeMCPathBasketEngine & withAntitheticVariate(bool b=true)
MakeMCPathBasketEngine(ext::shared_ptr< StochasticProcessArray >)
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
Correlated multiple asset paths.
template class providing a null value for a given type.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
base class for path pricers
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
ext::shared_ptr< QuantLib::Payoff > payoff
framework for Monte Carlo engines
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