/* Copyright (C) 2006 Giorgio Facchinetti Copyright (C) 2006 Mario Pucci 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 conundrumpricer.hpp \brief CMS-coupon pricer */ #ifndef quantlib_conundrum_pricer_hpp #define quantlib_conundrum_pricer_hpp #include #include namespace QuantLib { class CmsCoupon; class YieldTermStructure; class Quote; class VanillaOptionPricer { public: virtual ~VanillaOptionPricer() {}; virtual Real operator()(Real strike, Option::Type optionType, Real deflator) const = 0; }; class BlackVanillaOptionPricer : public VanillaOptionPricer { public: BlackVanillaOptionPricer( Rate forwardValue, Date expiryDate, const Period& swapTenor, const boost::shared_ptr& volatilityStructure); Real operator()(Real strike, Option::Type optionType, Real deflator) const; private: Rate forwardValue_; Date expiryDate_; Period swapTenor_; boost::shared_ptr volatilityStructure_; boost::shared_ptr smile_; }; class GFunction { public: virtual ~GFunction() {}; virtual Real operator()(Real x) = 0; virtual Real firstDerivative(Real x) = 0; virtual Real secondDerivative(Real x) = 0; }; class GFunctionFactory { public: enum ModelOfYieldCurve { Standard, ExactYield, ParallelShifts, NonParallelShifts }; static boost::shared_ptr newGFunctionStandard(Size q, Real delta, Size swapLength); static boost::shared_ptr newGFunctionExactYield(const CmsCoupon& coupon); static boost::shared_ptr newGFunctionWithShifts(const CmsCoupon& coupon, const Handle& meanReversion); private: GFunctionFactory(); class GFunctionStandard : public GFunction { public: 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); protected: /* 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 { public: GFunctionExactYield(const CmsCoupon& coupon); Real operator()(Real x) ; Real firstDerivative(Real x); Real secondDerivative(Real x); protected: /* fraction of a period between the swap start date and the pay date */ Real delta_; /* accruals fraction*/ std::vector