Logo Search packages:      
Sourcecode: quantlib version File versions


Go to the documentation of this file.
 Copyright (C) 2006 Mario Pucci
 Copyright (C) 2006 Giorgio Facchinetti

 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. */

/*! \file conundrumpricer.hpp

#ifndef quantlib_conundrum_pricer_hpp
#define quantlib_conundrum_pricer_hpp

#include <ql/CashFlows/cmscoupon.hpp>
#include <ql/PricingEngines/blackmodel.hpp>
#include <ql/Volatilities/swaptionvolcube.hpp>

namespace QuantLib {

    class VanillaOptionPricer {
        virtual ~VanillaOptionPricer() {};
        virtual Real operator()(Real strike,
                                Option::Type optionType,
                                Real deflator) const = 0;

    class BlackVanillaOptionPricer : public VanillaOptionPricer {
                Rate forwardValue,
                Date expiryDate,
                const Period& swapTenor,
                const boost::shared_ptr<SwaptionVolatilityStructure>&

        Real operator()(Real strike,
                        Option::Type optionType,
                        Real deflator) const;
        Rate forwardValue_;
        Date expiryDate_;
        Period swapTenor_;
        boost::shared_ptr<SwaptionVolatilityStructure> volatilityStructure_;
        boost::shared_ptr<SmileSection> smile_;

    class GFunction {
        virtual ~GFunction() {};
        virtual Real operator()(Real x) = 0;
        virtual Real firstDerivative(Real x) = 0;
        virtual Real secondDerivative(Real x) = 0;

    class GFunctionFactory {
        enum ModelOfYieldCurve { standard,
                                 nonParallelShifts };

        static boost::shared_ptr<GFunction>
        newGFunctionStandard(Size q,
                             Real delta,
                             Size swapLength);
        static boost::shared_ptr<GFunction>
        newGFunctionExactYield(const CMSCoupon& coupon);
        static boost::shared_ptr<GFunction>
        newGFunctionWithShifts(const CMSCoupon& coupon,
                               Real meanReversion);

        /*! Corresponds to Standard Model in Hagan's paper */
00088         class GFunctionStandard : public GFunction {
            GFunctionStandard(Size q,
                              Real delta,
                              Size swapLength)
            : q_(q), delta_(delta), swapLength_(swapLength) {};
            Real operator()(Real x) ;
            Real firstDerivative(Real x);
            Real secondDerivative(Real x);
            /* number of period per year */
            const int q_;
            /* fraction of a period between the swap start date and
               the pay date  */
            Real delta_;
            /* length of swap*/
            Size swapLength_;

        class GFunctionExactYield : public GFunction {
            GFunctionExactYield(const CMSCoupon& coupon);
            Real operator()(Real x) ;
            Real firstDerivative(Real x);
            Real secondDerivative(Real x);
            /* fraction of a period between the swap start date and
               the pay date  */
            Real delta_;
            /* accruals fraction*/
            std::vector<Time> accruals_;

        class GFunctionWithShifts : public GFunction {

            Time swapStartTime_;

            Time shapedPaymentTime_;
            std::vector<Time> shapedSwapPaymentTimes_;

            std::vector<Time> accruals_;
            std::vector<Real> swapPaymentDiscounts_;
            Real discountAtStart_, discountRatio_;

            Real swapRateValue_;
            Real meanReversion_;

            Real calibratedShift_, tmpRs_;
            const Real accuracy_;

            //* function describing the non-parallel shape of the curve shift*/
            Real shapeOfShift(Real s) const;
            //* calibration of shift*/
            Real calibrationOfShift(Real Rs);
            Real functionZ(Real x);
            Real derRs_derX(Real x);
            Real derZ_derX(Real x);
            Real der2Rs_derX2(Real x);
            Real der2Z_derX2(Real x);

            class ObjectiveFunction;
            friend class ObjectiveFunction;
            class ObjectiveFunction : public std::unary_function<Real, Real> {
                const GFunctionWithShifts& o_;
                Real Rs_;
                virtual ~ObjectiveFunction() {}
                ObjectiveFunction(const GFunctionWithShifts& o,
                                  const Real Rs)
                : o_(o), Rs_(Rs) {}
                virtual Real operator()(const Real& x) const;
                void setSwapRateValue(Real x);

            boost::shared_ptr<ObjectiveFunction> objectiveFunction_;
            GFunctionWithShifts(const CMSCoupon& coupon,
                                Real meanReversion);
            Real operator()(Real x) ;
            Real firstDerivative(Real x);
            Real secondDerivative(Real x);


    // forward declaration
    class CMSCoupon;

    //! ConundrumPricer
    /*! Base class for the pricing of a CMS coupon via static replication
        as in Hagan's "Conundrums..." article

00181     class ConundrumPricer: public VanillaCMSCouponPricer {
        Real price() const;
        Real rate() const;

                 const GFunctionFactory::ModelOfYieldCurve modelOfYieldCurve);
        void initialize(const CMSCoupon& coupon);

        virtual Real optionLetPrice(Option::Type optionType,
                                    Real strike) const = 0;
        virtual Real swapLetPrice() const = 0;

        boost::shared_ptr<YieldTermStructure> rateCurve_;
        GFunctionFactory::ModelOfYieldCurve modelOfYieldCurve_;
        boost::shared_ptr<GFunction> gFunction_;
        const CMSCoupon* coupon_;
        Date paymentDate_, fixingDate_;
        Real swapRateValue_;
        Real discount_, annuity_, min_, max_, gearing_, spread_;
        const Real cutoffForCaplet_, cutoffForFloorlet_;
        Period swapTenor_;
        boost::shared_ptr<VanillaOptionPricer> vanillaOptionPricer_;

    //! ConundrumPricerByNumericalIntegration
    /*! Prices a CMS coupon via static replication as in Hagan's
        "Conundrums..." article via numerical integration based on
        prices of vanilla swaptions
00213     class ConundrumPricerByNumericalIntegration : public ConundrumPricer {
            const GFunctionFactory::ModelOfYieldCurve modelOfYieldCurve =
            Real lowerLimit = 0.0,
            Real upperLimit = 1.0);
        class Function : public std::unary_function<Real, Real> {
            virtual ~Function() {};
            virtual Real operator()(Real x) const = 0;
        //! ConundrumIntegrand
        /*! Base class for the definition of the integrand for Hagan's
            integral */
00229         class ConundrumIntegrand : public Function {
            friend class ConundrumPricerByNumericalIntegration;
                       const boost::shared_ptr<VanillaOptionPricer>& o,
                       const boost::shared_ptr<YieldTermStructure>& rateCurve,
                       const boost::shared_ptr<GFunction>& gFunction,
                       Date fixingDate,
                       Date paymentDate,
                       Real annuity,
                       Real forwardValue,
                       Real strike,
                       Option::Type optionType);
            Real operator()(Real x) const;
            Real functionF(const Real x) const;
            Real firstDerivativeOfF(const Real x) const;
            Real secondDerivativeOfF(const Real x) const;

            Real strike() const;
            Real annuity() const;
            Date fixingDate() const;
            void setStrike(Real strike);

            const boost::shared_ptr<VanillaOptionPricer> vanillaOptionPricer_;
            const Real forwardValue_, annuity_;
            const Date fixingDate_, paymentDate_;
            Real strike_;
            const Option::Type optionType_;
            boost::shared_ptr<GFunction> gFunction_;

        Real integrate(Real a,
                       Real b,
                       const ConundrumIntegrand& Integrand) const;
        virtual Real optionLetPrice(Option::Type optionType,
                                    Real strike) const;
        virtual Real swapLetPrice() const;

        const Real upperLimit_, lowerLimit_;

    class ConundrumPricerByBlack : public ConundrumPricer {
                    GFunctionFactory::ModelOfYieldCurve modelOfYieldCurve =
        Real optionLetPrice(Option::Type optionType,
                            Real strike) const;
        Real swapLetPrice() const;



Generated by  Doxygen 1.6.0   Back to index