20#ifndef quantlib_mcforwardvanilla_engine_hpp
21#define quantlib_mcforwardvanilla_engine_hpp
33 template<
template <
class>
class MC,
36 VanillaOption::results>,
49 Size timeStepsPerYear,
51 bool antitheticVariate,
53 Real requiredTolerance,
56 bool controlVariate =
false);
62 if (RNG::allowsErrorEstimate)
64 this->
mcModel_->sampleAccumulator().errorEstimate();
75 typename RNG::rsg_type gen =
76 RNG::make_sequence_generator(dimensions*(grid.
size()-1),
seed_);
77 return ext::shared_ptr<path_generator_type>(
89 template <
template <
class>
class MC,
class RNG,
class S>
91 ext::shared_ptr<StochasticProcess> process,
93 Size timeStepsPerYear,
95 bool antitheticVariate,
97 Real requiredTolerance,
101 :
McSimulation<MC, RNG,
S>(antitheticVariate, controlVariate), process_(
std::move(process)),
102 timeSteps_(timeSteps), timeStepsPerYear_(timeStepsPerYear), requiredSamples_(requiredSamples),
103 maxSamples_(maxSamples), requiredTolerance_(requiredTolerance),
104 brownianBridge_(brownianBridge), seed_(seed) {
107 "no time steps provided");
110 "both time steps and time steps per year were provided");
112 "timeSteps must be positive, " << timeSteps <<
115 "timeStepsPerYear must be positive, " << timeStepsPerYear <<
120 template <
template <
class>
class MC,
class RNG,
class S>
123 Date resetDate = arguments_.resetDate;
124 Date lastExerciseDate = arguments_.exercise->lastDate();
126 Time t1 = process_->time(resetDate);
127 Time t2 = process_->time(lastExerciseDate);
131 totalSteps = timeSteps_;
132 }
else if (this->timeStepsPerYear_ !=
Null<Size>()) {
133 totalSteps =
static_cast<Size>(this->timeStepsPerYear_*t2);
136 std::vector<Time> fixingTimes;
137 fixingTimes.push_back(t1);
138 fixingTimes.push_back(t2);
140 return TimeGrid(fixingTimes.begin(), fixingTimes.end(), totalSteps);
143 template <
template <
class>
class MC,
class RNG,
class S>
146 ext::shared_ptr<PricingEngine> controlPE =
147 this->controlPricingEngine();
148 QL_REQUIRE(controlPE,
"engine does not provide "
149 "control variation pricing engine");
153 ext::shared_ptr<StrikedTypePayoff>
payoff =
154 ext::dynamic_pointer_cast<StrikedTypePayoff>(
155 this->arguments_.payoff);
158 Real spot = this->process_->initialValues()[0];
159 Real moneyness = this->arguments_.moneyness;
160 Real strike = moneyness * spot;
162 ext::shared_ptr<StrikedTypePayoff> newPayoff(
new
167 controlArguments->
payoff = newPayoff;
168 controlArguments->exercise = this->arguments_.exercise;
169 controlPE->calculate();
171 const auto* controlResults =
174 return controlResults->
value;
template base class for option pricing engines
VanillaOption::results results_
Monte Carlo engine for forward-starting vanilla options.
ext::shared_ptr< StochasticProcess > process_
McSimulation< MC, RNG, S >::path_generator_type path_generator_type
ext::shared_ptr< path_generator_type > pathGenerator() const override
void calculate() const override
McSimulation< MC, RNG, S >::path_pricer_type path_pricer_type
McSimulation< MC, RNG, S >::stats_type stats_type
Real controlVariateValue() const override
MCForwardVanillaEngine(ext::shared_ptr< StochasticProcess > process, Size timeSteps, Size timeStepsPerYear, bool brownianBridge, bool antitheticVariate, Size requiredSamples, Real requiredTolerance, Size maxSamples, BigNatural seed, bool controlVariate=false)
TimeGrid timeGrid() const override
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.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
ext::shared_ptr< Payoff > payoff
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Forward version of a vanilla option.
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
ext::shared_ptr< QuantLib::Payoff > payoff
framework for Monte Carlo engines
RiskStatistics Statistics
default statistics tool
unsigned QL_BIG_INTEGER BigNatural
large positive integer
GenericPseudoRandom< MersenneTwisterUniformRng, InverseCumulativeNormal > PseudoRandom
default traits for pseudo-random number generation
Vanilla option on a single asset.