24#ifndef quantlib_mc_varianceswap_engine_hpp
25#define quantlib_mc_varianceswap_engine_hpp
47 template <
class RNG = PseudoRandom,
class S = Statistics>
62 Size timeStepsPerYear,
64 bool antitheticVariate,
66 Real requiredTolerance,
75 this->
mcModel_->sampleAccumulator().mean();
95 if (RNG::allowsErrorEstimate) {
97 this->
mcModel_->sampleAccumulator().errorEstimate();
104 ext::shared_ptr<path_pricer_type>
pathPricer()
const override;
112 typename RNG::rsg_type gen =
113 RNG::make_sequence_generator(dimensions*(grid.
size()-1),
seed_);
115 return ext::shared_ptr<path_generator_type>(
120 ext::shared_ptr<GeneralizedBlackScholesProcess>
process_;
130 template <
class RNG = PseudoRandom,
class S = Statistics>
144 operator ext::shared_ptr<PricingEngine>()
const;
146 ext::shared_ptr<GeneralizedBlackScholesProcess>
process_;
161 ext::shared_ptr<GeneralizedBlackScholesProcess>
process_;
166 template <
class RNG,
class S>
168 ext::shared_ptr<GeneralizedBlackScholesProcess> process,
170 Size timeStepsPerYear,
172 bool antitheticVariate,
173 Size requiredSamples,
174 Real requiredTolerance,
178 timeSteps_(timeSteps), timeStepsPerYear_(timeStepsPerYear), requiredSamples_(requiredSamples),
179 maxSamples_(maxSamples), requiredTolerance_(requiredTolerance),
180 brownianBridge_(brownianBridge), seed_(seed) {
183 "no time steps provided");
186 "both time steps and time steps per year were provided");
188 "timeSteps must be positive, " << timeSteps <<
191 "timeStepsPerYear must be positive, " << timeStepsPerYear <<
196 template <
class RNG,
class S>
199 Time t = this->process_->time(this->arguments_.maturityDate);
203 }
else if (timeStepsPerYear_ !=
Null<Size>()) {
204 Size steps =
static_cast<Size>(timeStepsPerYear_*
t);
205 return TimeGrid(
t, std::max<Size>(steps, 1));
207 QL_FAIL(
"time steps not specified");
212 template <
class RNG,
class S>
218 return ext::shared_ptr<
224 template <
class RNG,
class S>
226 ext::shared_ptr<GeneralizedBlackScholesProcess> process)
230 template <
class RNG,
class S>
237 template <
class RNG,
class S>
240 stepsPerYear_ = steps;
244 template <
class RNG,
class S>
248 "tolerance already set");
253 template <
class RNG,
class S>
257 "number of samples already set");
259 "chosen random generator policy "
260 "does not allow an error estimate");
261 tolerance_ = tolerance;
265 template <
class RNG,
class S>
268 maxSamples_ = samples;
272 template <
class RNG,
class S>
279 template <
class RNG,
class S>
282 brownianBridge_ = brownianBridge;
286 template <
class RNG,
class S>
293 template <
class RNG,
class S>
295 operator ext::shared_ptr<PricingEngine>()
const {
297 "number of steps not given");
299 "number of steps overspecified");
300 return ext::shared_ptr<PricingEngine>(
306 samples_, tolerance_,
316 Integrand(
Path path, ext::shared_ptr<GeneralizedBlackScholesProcess> process)
325 ext::shared_ptr<GeneralizedBlackScholesProcess>
process_;
338 return integrator(
f,t0,
t)/
t;
VarianceSwap::results results_
VarianceSwap::arguments arguments_
Variance-swap pricing engine using Monte Carlo simulation,.
McSimulation< SingleVariate, RNG, S >::path_generator_type path_generator_type
ext::shared_ptr< path_generator_type > pathGenerator() const override
void calculate() const override
McSimulation< SingleVariate, RNG, S >::stats_type stats_type
MCVarianceSwapEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > process, Size timeSteps, Size timeStepsPerYear, bool brownianBridge, bool antitheticVariate, Size requiredSamples, Real requiredTolerance, Size maxSamples, BigNatural seed)
ext::shared_ptr< path_pricer_type > pathPricer() const override
McSimulation< SingleVariate, RNG, S >::path_pricer_type path_pricer_type
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
TimeGrid timeGrid() const override
Monte Carlo variance-swap engine factory.
MakeMCVarianceSwapEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > process)
MakeMCVarianceSwapEngine & withSeed(BigNatural seed)
MakeMCVarianceSwapEngine & withAbsoluteTolerance(Real tolerance)
MakeMCVarianceSwapEngine & withSamples(Size samples)
MakeMCVarianceSwapEngine & withSteps(Size steps)
MakeMCVarianceSwapEngine & withMaxSamples(Size samples)
MakeMCVarianceSwapEngine & withStepsPerYear(Size steps)
MakeMCVarianceSwapEngine & withAntitheticVariate(bool b=true)
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
MakeMCVarianceSwapEngine & 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.
single-factor random walk
const TimeGrid & timeGrid() const
time grid
base class for path pricers
Integral of a one-dimensional function.
VariancePathPricer(ext::shared_ptr< GeneralizedBlackScholesProcess > process)
Real operator()(const Path &path) const override
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
base class for variance-swap engines
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
Real operator()(Time t) const
Integrand(Path path, ext::shared_ptr< GeneralizedBlackScholesProcess > process)
#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)
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
framework for Monte Carlo engines
unsigned QL_BIG_INTEGER BigNatural
large positive integer
Integral of a one-dimensional function using segment algorithm.
default Monte Carlo traits for single-variate models