/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Copyright (C) 2007 Giorgio Facchinetti Copyright (C) 2007 Cristina Duminuco 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 couponpricer.hpp \brief Coupon pricers */ #ifndef quantlib_coupon_pricer_hpp #define quantlib_coupon_pricer_hpp #include #include #include #include namespace QuantLib { class FloatingRateCoupon; class IborCoupon; //! generic pricer for floating-rate coupons class FloatingRateCouponPricer: public virtual Observer, public virtual Observable { public: virtual ~FloatingRateCouponPricer() {} //! \name required interface //@{ virtual Real swapletPrice() const = 0; virtual Rate swapletRate() const = 0; virtual Real capletPrice(Rate effectiveCap) const = 0; virtual Rate capletRate(Rate effectiveCap) const = 0; virtual Real floorletPrice(Rate effectiveFloor) const = 0; virtual Rate floorletRate(Rate effectiveFloor) const = 0; virtual void initialize(const FloatingRateCoupon& coupon) = 0; //@} //! \name Observer interface //@{ void update(){notifyObservers();} //@} }; //! base pricer for capped/floored Ibor coupons class IborCouponPricer: public FloatingRateCouponPricer { public: IborCouponPricer(const Handle& capletVol) : capletVol_(capletVol) { registerWith(capletVol_);}; Handle capletVolatility() const{ return capletVol_; } void setCapletVolatility( const Handle& capletVol) { unregisterWith(capletVol_); capletVol_ = capletVol; QL_REQUIRE(!capletVol_.empty(), "no adequate capletVol given"); registerWith(capletVol_); update(); } private: Handle capletVol_; }; //! Black-formula pricer for capped/floored Ibor coupons class BlackIborCouponPricer: public IborCouponPricer { public: BlackIborCouponPricer( const Handle& capletVol = Handle()) : IborCouponPricer(capletVol) {}; void initialize(const FloatingRateCoupon& coupon); /* */ Real swapletPrice() const; Rate swapletRate() const; Real capletPrice(Rate effectiveCap) const; Rate capletRate(Rate effectiveCap) const; Real floorletPrice(Rate effectiveFloor) const; Rate floorletRate(Rate effectiveFloor) const; protected: Real optionletPrice(Option::Type optionType, Real effStrike) const; private: Rate adjustedFixing() const; const IborCoupon* coupon_; Real discount_; Real gearing_; Spread spread_; Real spreadLegValue_; }; //! base pricer for vanilla CMS coupons class CmsCouponPricer: public FloatingRateCouponPricer { public: CmsCouponPricer(const Handle& swaptionVol) : swaptionVol_(swaptionVol) {registerWith(swaptionVol_);} Handle swaptionVolatility() const { return swaptionVol_; } void setSwaptionVolatility( const Handle& swaptionVol) { unregisterWith(swaptionVol_); swaptionVol_ = swaptionVol; QL_REQUIRE(!swaptionVol_.empty(), "no adequate swaptionVol given"); registerWith(swaptionVol_); update(); } private: Handle swaptionVol_; }; void setCouponPricer(const Leg& leg, const boost::shared_ptr&); void setCouponPricers( const Leg& leg, const std::vector >&); } #endif