/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Copyright (C) 2003, 2004 Ferdinando Ametrano Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl Copyright (C) 2007 StatPro Italia srl This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ QuantLib is free software: you can redistribute it and/or modify it under the terms of the QuantLib license. You should have received a copy of the license along with this program; if not, please email . The license is also available online at . This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */ /*! \file mcdiscreteasianengine.hpp \brief Monte Carlo pricing engine for discrete average Asians */ #ifndef quantlib_mcdiscreteasian_engine_hpp #define quantlib_mcdiscreteasian_engine_hpp #include #include #include namespace QuantLib { //! Pricing engine for discrete average Asians using Monte Carlo simulation /*! \warning control-variate calculation is disabled under VC++6. \ingroup asianengines */ template class MCDiscreteAveragingAsianEngine : public DiscreteAveragingAsianOption::engine, public McSimulation { public: typedef typename McSimulation::path_generator_type path_generator_type; typedef typename McSimulation::path_pricer_type path_pricer_type; typedef typename McSimulation::stats_type stats_type; // constructor MCDiscreteAveragingAsianEngine(Size maxTimeStepsPerYear, bool brownianBridge, bool antitheticVariate, bool controlVariate, Size requiredSamples, Real requiredTolerance, Size maxSamples, BigNatural seed); void calculate() const { McSimulation::calculate(requiredTolerance_, requiredSamples_, maxSamples_); results_.value = this->mcModel_->sampleAccumulator().mean(); if (RNG::allowsErrorEstimate) results_.errorEstimate = this->mcModel_->sampleAccumulator().errorEstimate(); } protected: // McSimulation implementation TimeGrid timeGrid() const; boost::shared_ptr pathGenerator() const { boost::shared_ptr process = boost::dynamic_pointer_cast( arguments_.stochasticProcess); QL_REQUIRE(process, "Black-Scholes process required"); TimeGrid grid = this->timeGrid(); typename RNG::rsg_type gen = RNG::make_sequence_generator(grid.size()-1,seed_); return boost::shared_ptr( new path_generator_type(process, grid, gen, brownianBridge_)); } Real controlVariateValue() const; // data members Size maxTimeStepsPerYear_; Size requiredSamples_, maxSamples_; Real requiredTolerance_; bool brownianBridge_; BigNatural seed_; }; // template definitions template inline MCDiscreteAveragingAsianEngine::MCDiscreteAveragingAsianEngine( Size maxTimeStepsPerYear, bool brownianBridge, bool antitheticVariate, bool controlVariate, Size requiredSamples, Real requiredTolerance, Size maxSamples, BigNatural seed) : McSimulation(antitheticVariate, controlVariate), maxTimeStepsPerYear_(maxTimeStepsPerYear), requiredSamples_(requiredSamples), maxSamples_(maxSamples), requiredTolerance_(requiredTolerance), brownianBridge_(brownianBridge), seed_(seed) {} template inline TimeGrid MCDiscreteAveragingAsianEngine::timeGrid() const { boost::shared_ptr process = boost::dynamic_pointer_cast( arguments_.stochasticProcess); QL_REQUIRE(process, "Black-Scholes process required"); Date referenceDate = process->riskFreeRate()->referenceDate(); DayCounter voldc = process->blackVolatility()->dayCounter(); std::vector