25#ifndef quantlib_montecarlo_model_hpp
26#define quantlib_montecarlo_model_hpp
51 template <
template <
class>
class MC,
class RNG,
class S =
Statistics>
58 typedef typename path_generator_type::sample_type
sample_type;
63 ext::shared_ptr<path_generator_type> pathGenerator,
64 ext::shared_ptr<path_pricer_type> pathPricer,
66 bool antitheticVariate,
67 ext::shared_ptr<path_pricer_type> cvPathPricer = ext::shared_ptr<path_pricer_type>(),
69 ext::shared_ptr<path_generator_type> cvPathGenerator =
70 ext::shared_ptr<path_generator_type>())
91 template <
template <
class>
class MC,
class RNG,
class S>
93 for(
Size j = 1; j <= samples; j++) {
98 if (isControlVariate_) {
99 if (!cvPathGenerator_) {
100 price += cvOptionValue_-(*cvPathPricer_)(path.value);
103 const sample_type& cvPath = cvPathGenerator_->next();
104 price += cvOptionValue_-(*cvPathPricer_)(cvPath.value);
108 if (isAntitheticVariate_) {
109 const sample_type& atPath = pathGenerator_->antithetic();
111 if (isControlVariate_) {
112 if (!cvPathGenerator_)
113 price2 += cvOptionValue_-(*cvPathPricer_)(atPath.value);
115 const sample_type& cvPath = cvPathGenerator_->antithetic();
116 price2 += cvOptionValue_-(*cvPathPricer_)(cvPath.value);
120 sampleAccumulator_.add((price+price2)/2.0, path.weight);
122 sampleAccumulator_.add(price, path.weight);
127 template <
template <
class>
class MC,
class RNG,
class S>
130 return sampleAccumulator_;
General-purpose Monte Carlo model for path samples.
ext::shared_ptr< path_generator_type > pathGenerator_
path_generator_type::sample_type sample_type
MC< RNG >::path_pricer_type path_pricer_type
const stats_type & sampleAccumulator() const
ext::shared_ptr< path_pricer_type > pathPricer_
result_type cvOptionValue_
void addSamples(Size samples)
stats_type sampleAccumulator_
MonteCarloModel(ext::shared_ptr< path_generator_type > pathGenerator, ext::shared_ptr< path_pricer_type > pathPricer, stats_type sampleAccumulator, bool antitheticVariate, ext::shared_ptr< path_pricer_type > cvPathPricer=ext::shared_ptr< path_pricer_type >(), result_type cvOptionValue=result_type(), ext::shared_ptr< path_generator_type > cvPathGenerator=ext::shared_ptr< path_generator_type >())
MC< RNG >::path_generator_type path_generator_type
bool isAntitheticVariate_
path_pricer_type::result_type result_type
ext::shared_ptr< path_generator_type > cvPathGenerator_
ext::shared_ptr< path_pricer_type > cvPathPricer_
std::size_t Size
size of a container
RiskStatistics Statistics
default statistics tool
Maps shared_ptr to either the boost or std implementation.
statistics tool with risk measures