/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl Copyright (C) 2003, 2004, 2005, 2006, 2007 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 ratehelpers.hpp \brief deposit, FRA, futures, and swap rate helpers */ #ifndef quantlib_ratehelpers_hpp #define quantlib_ratehelpers_hpp #include #include namespace QuantLib { //! Rate helper for bootstrapping over interest-rate futures prices /*! \todo implement/refactor constructors with: Index instead of (nMonths, calendar, convention, dayCounter), IMM code */ class FuturesRateHelper : public RateHelper { public: FuturesRateHelper(const Handle& price, const Date& immDate, Size nMonths, const Calendar& calendar, BusinessDayConvention convention, const DayCounter& dayCounter, const Handle& convexityAdjustment); FuturesRateHelper(const Handle& price, const Date& immDate, Size nMonths, const Calendar& calendar, BusinessDayConvention convention, const DayCounter& dayCounter, Rate convexityAdjustment = 0.0); FuturesRateHelper(Real price, const Date& immDate, Size nMonths, const Calendar& calendar, BusinessDayConvention convention, const DayCounter& dayCounter, Rate convexityAdjustment = 0.0); Real impliedQuote() const; DiscountFactor discountGuess() const; Real convexityAdjustment() const { return convAdj_->value(); } private: Time yearFraction_; Handle convAdj_; }; //! Rate helper with date schedule relative to the global evaluation date /*! This class takes care of rebuilding the date schedule when the global evaluation date changes */ class RelativeDateRateHelper : public RateHelper { public: RelativeDateRateHelper(const Handle& quote); RelativeDateRateHelper(Real quote); void update(); protected: virtual void initializeDates() = 0; Date evaluationDate_; }; //! Rate helper for bootstrapping over deposit rates class DepositRateHelper : public RelativeDateRateHelper { public: DepositRateHelper(const Handle& rate, const Period& tenor, Natural settlementDays, const Calendar& calendar, BusinessDayConvention convention, bool endOfMonth, Natural fixingDays, const DayCounter& dayCounter); DepositRateHelper(Rate rate, const Period& tenor, Natural settlementDays, const Calendar& calendar, BusinessDayConvention convention, bool endOfMonth, Natural fixingDays, const DayCounter& dayCounter); Real impliedQuote() const; DiscountFactor discountGuess() const; void setTermStructure(YieldTermStructure*); private: void initializeDates(); Date fixingDate_; Natural settlementDays_; boost::shared_ptr index_; RelinkableHandle termStructureHandle_; }; //! Rate helper for bootstrapping over %FRA rates class FraRateHelper : public RelativeDateRateHelper { public: FraRateHelper(const Handle& rate, Natural monthsToStart, Natural monthsToEnd, Natural settlementDays, const Calendar& calendar, BusinessDayConvention convention, bool endOfMonth, Natural fixingDays, const DayCounter& dayCounter); FraRateHelper(Rate rate, Natural monthsToStart, Natural monthsToEnd, Natural settlementDays, const Calendar& calendar, BusinessDayConvention convention, bool endOfMonth, Natural fixingDays, const DayCounter& dayCounter); Real impliedQuote() const; DiscountFactor discountGuess() const; void setTermStructure(YieldTermStructure*); private: void initializeDates(); Date fixingDate_; Natural monthsToStart_; Natural settlementDays_; boost::shared_ptr index_; RelinkableHandle termStructureHandle_; }; //! Rate helper for bootstrapping over swap rates class SwapRateHelper : public RelativeDateRateHelper { public: SwapRateHelper(const Handle& rate, const Period& tenor, Natural settlementDays, const Calendar& calendar, // fixed leg Frequency fixedFrequency, BusinessDayConvention fixedConvention, const DayCounter& fixedDayCount, // floating leg const boost::shared_ptr& index); SwapRateHelper(Rate rate, const Period& tenor, Natural settlementDays, const Calendar& calendar, // fixed leg Frequency fixedFrequency, BusinessDayConvention fixedConvention, const DayCounter& fixedDayCount, // floating leg const boost::shared_ptr& index); Real impliedQuote() const; // implementing discountGuess() is not worthwhile, // and may not avoid the root-finding process void setTermStructure(YieldTermStructure*); protected: void initializeDates(); Period tenor_; Natural settlementDays_; Calendar calendar_; BusinessDayConvention fixedConvention_; Frequency fixedFrequency_; DayCounter fixedDayCount_; boost::shared_ptr index_; boost::shared_ptr swap_; RelinkableHandle termStructureHandle_; }; } #endif