Logo Search packages:      
Sourcecode: quantlib version File versions  Download package


/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

 Copyright (C) 2002, 2003 Ferdinando Ametrano

 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
 <quantlib-dev@lists.sf.net>. 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.

#include <ql/Pricers/mcperformanceoption.hpp>
#include <ql/Instruments/payoffs.hpp>
#include <ql/TermStructures/flatforward.hpp>
#include <ql/Processes/blackscholesprocess.hpp>

namespace QuantLib {

    namespace {

        class PerformanceOptionPathPricer : public PathPricer<Path> {
                                 Option::Type type,
                                 Real moneyness,
                                 const std::vector<DiscountFactor>& discounts)
            : discounts_(discounts), payoff_(type, moneyness) {
                           "moneyness less/equal zero not allowed");

            Real operator()(const Path& path) const {
                Size n = path.length();
                           "at least one option is required");
                           "only one option for the time being");
                           "discounts/options mismatch");

                std::vector<Real> result(n-1);
                std::vector<Real> assetValue(n-1);
                assetValue[0] = path[1];
                // removing first option
                result[0] = 0.0;
                for (Size i = 1 ; i < n-1; i++) {
                    assetValue[i] = path[i+1];
                    result[i] = discounts_[i] *

                return result[1];

            std::vector<DiscountFactor> discounts_;
            PlainVanillaPayoff payoff_;


                              Option::Type type,
                              Real underlying,
                              Real moneyness,
                              const Handle<YieldTermStructure>& dividendYield,
                              const Handle<YieldTermStructure>& riskFreeRate,
                              const Handle<BlackVolTermStructure>& volatility,
                              const std::vector<Time>& times,
                              BigNatural seed) {

        std::vector<DiscountFactor> discounts(times.size());
        for (Size i = 0; i<times.size(); i++)
            discounts[i] = riskFreeRate->discount(times[i]);

        // Initialize the path generator
        Handle<Quote> u(boost::shared_ptr<Quote>(new SimpleQuote(underlying)));
        boost::shared_ptr<StochasticProcess1D> diffusion(
                                      new BlackScholesProcess(u,
        TimeGrid grid(times.begin(), times.end());
        PseudoRandom::rsg_type rsg =

        bool brownianBridge = false;

        typedef SingleVariate<PseudoRandom>::path_generator_type generator;
        boost::shared_ptr<generator> pathGenerator(new
            generator(diffusion, grid, rsg, brownianBridge));

        // Initialize the pricer on the single Path
        boost::shared_ptr<PathPricer<Path> > performancePathPricer(
                 new PerformanceOptionPathPricer(type, moneyness, discounts));

        // Initialize the one-factor Monte Carlo
        mcModel_ = boost::shared_ptr<MonteCarloModel<SingleVariate<
                                          PseudoRandom> > > (
            new MonteCarloModel<SingleVariate<PseudoRandom> > (
                pathGenerator, performancePathPricer,
                Statistics(), false));


Generated by  Doxygen 1.6.0   Back to index