/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Copyright (C) 2006 Banca Profilo S.p.A. Copyright (C) 2006 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 mchullwhiteengine.hpp \brief Monte Carlo Hull-White engine for cap/floors */ #ifndef quantlib_mc_hull_white_cap_floor_engine_hpp #define quantlib_mc_hull_white_cap_floor_engine_hpp #include #include #include #include namespace QuantLib { class HullWhiteCapFloorPricer : public PathPricer { public: HullWhiteCapFloorPricer(const CapFloor::arguments&, const boost::shared_ptr&, Time forwardMeasureTime); Real operator()(const Path& path) const; private: CapFloor::arguments args_; boost::shared_ptr model_; Time forwardMeasureTime_; DiscountFactor endDiscount_; }; //! Monte Carlo Hull-White engine for cap/floors /*! \ingroup capfloorengines */ template class MCHullWhiteCapFloorEngine : public CapFloor::engine, public McSimulation, public Observer { private: typedef McSimulation simulation; boost::shared_ptr model_; Size requiredSamples_, maxSamples_; Real requiredTolerance_; bool brownianBridge_; BigNatural seed_; public: typedef typename simulation::path_generator_type path_generator_type; typedef typename simulation::path_pricer_type path_pricer_type; typedef typename simulation::stats_type stats_type; MCHullWhiteCapFloorEngine(const boost::shared_ptr& model, bool brownianBridge, bool antitheticVariate, Size requiredSamples, Real requiredTolerance, Size maxSamples, BigNatural seed) : McSimulation(antitheticVariate, false), model_(model), requiredSamples_(requiredSamples), maxSamples_(maxSamples), requiredTolerance_(requiredTolerance), brownianBridge_(brownianBridge), seed_(seed) { registerWith(model_); } void calculate() const { simulation::calculate(requiredTolerance_, requiredSamples_, maxSamples_); results_.value = this->mcModel_->sampleAccumulator().mean(); if (RNG::allowsErrorEstimate) results_.errorEstimate = this->mcModel_->sampleAccumulator().errorEstimate(); } void update() { notifyObservers(); } protected: boost::shared_ptr pathPricer() const { Time forwardMeasureTime = arguments_.endTimes.back(); return boost::shared_ptr( new HullWhiteCapFloorPricer(arguments_, model_, forwardMeasureTime)); } TimeGrid timeGrid() const { // only add future fixing times... std::vector