24#ifndef quantlib_mc_himalaya_engine_hpp
25#define quantlib_mc_himalaya_engine_hpp
36 template <
class RNG = PseudoRandom,
class S = Statistics>
48 bool antitheticVariate,
50 Real requiredTolerance,
60 if (RNG::allowsErrorEstimate)
62 this->
mcModel_->sampleAccumulator().errorEstimate();
73 typename RNG::rsg_type gen =
74 RNG::make_sequence_generator(numAssets*(grid.
size()-1),
seed_);
76 return ext::shared_ptr<path_generator_type>(
80 ext::shared_ptr<path_pricer_type>
pathPricer()
const override;
93 template <
class RNG = PseudoRandom,
class S = Statistics>
105 operator ext::shared_ptr<PricingEngine>()
const;
127 template <
class RNG,
class S>
129 ext::shared_ptr<StochasticProcessArray> processes,
131 bool antitheticVariate,
132 Size requiredSamples,
133 Real requiredTolerance,
137 processes_(
std::move(processes)), requiredSamples_(requiredSamples), maxSamples_(maxSamples),
138 requiredTolerance_(requiredTolerance), brownianBridge_(brownianBridge), seed_(seed) {
142 template <
class RNG,
class S>
145 std::vector<Time> fixingTimes;
146 for (
Size i=0; i<arguments_.fixingDates.size(); i++) {
147 Time t = processes_->time(arguments_.fixingDates[i]);
148 QL_REQUIRE(
t >= 0.0,
"seasoned options are not handled");
150 QL_REQUIRE(
t > fixingTimes.back(),
"fixing dates not sorted");
152 fixingTimes.push_back(
t);
155 return TimeGrid(fixingTimes.begin(), fixingTimes.end());
158 template <
class RNG,
class S>
160 ext::shared_ptr<typename MCHimalayaEngine<RNG,S>::path_pricer_type>
163 ext::shared_ptr<GeneralizedBlackScholesProcess> process =
164 ext::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
165 processes_->process(0));
166 QL_REQUIRE(process,
"Black-Scholes process required");
168 return ext::shared_ptr<
171 process->riskFreeRate()->discount(
172 arguments_.exercise->lastDate())));
176 template <
class RNG,
class S>
178 ext::shared_ptr<StochasticProcessArray> process)
182 template <
class RNG,
class S>
185 brownianBridge_ = brownianBridge;
189 template <
class RNG,
class S>
196 template <
class RNG,
class S>
200 "tolerance already set");
205 template <
class RNG,
class S>
209 "number of samples already set");
211 "chosen random generator policy "
212 "does not allow an error estimate");
213 tolerance_ = tolerance;
217 template <
class RNG,
class S>
220 maxSamples_ = samples;
224 template <
class RNG,
class S>
231 template <
class RNG,
class S>
235 return ext::shared_ptr<PricingEngine>(
new
HimalayaOption::results results_
ext::shared_ptr< Payoff > payoff_
Real operator()(const MultiPath &multiPath) const override
ext::shared_ptr< path_pricer_type > pathPricer() const override
ext::shared_ptr< path_generator_type > pathGenerator() const override
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
ext::shared_ptr< StochasticProcessArray > processes_
MCHimalayaEngine(ext::shared_ptr< StochasticProcessArray >, bool brownianBridge, bool antitheticVariate, Size requiredSamples, Real requiredTolerance, Size maxSamples, BigNatural seed)
TimeGrid timeGrid() const override
Monte Carlo Himalaya-option engine factory.
MakeMCHimalayaEngine & withMaxSamples(Size samples)
MakeMCHimalayaEngine & withAntitheticVariate(bool b=true)
MakeMCHimalayaEngine & withSamples(Size samples)
MakeMCHimalayaEngine & withAbsoluteTolerance(Real tolerance)
MakeMCHimalayaEngine(ext::shared_ptr< StochasticProcessArray >)
MakeMCHimalayaEngine & withSeed(BigNatural seed)
ext::shared_ptr< StochasticProcessArray > process_
MakeMCHimalayaEngine & 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
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
#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
Real Time
continuous quantity with 1-year units
Real DiscountFactor
discount factor between dates
std::size_t Size
size of a container
Himalaya option on a number of assets.
ext::shared_ptr< QuantLib::Payoff > payoff
framework for Monte Carlo engines
unsigned QL_BIG_INTEGER BigNatural
large positive integer
Array of correlated 1-D stochastic processes.
default Monte Carlo traits for multi-variate models