1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 3 /* 4 Copyright (C) 2007, 2009 Chris Kenyon 5 Copyright (C) 2009 StatPro Italia srl 6 7 This file is part of QuantLib, a free-software/open-source library 8 for financial quantitative analysts and developers - http://quantlib.org/ 9 10 QuantLib is free software: you can redistribute it and/or modify it 11 under the terms of the QuantLib license. You should have received a 12 copy of the license along with this program; if not, please email 13 <quantlib-dev@lists.sf.net>. The license is also available online at 14 <http://quantlib.org/license.shtml>. 15 16 This program is distributed in the hope that it will be useful, but WITHOUT 17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 18 FOR A PARTICULAR PURPOSE. See the license for more details. 19 */ 20 21 /*! \file zerocouponinflationswap.hpp 22 \brief Zero-coupon inflation-indexed swap 23 */ 24 25 #ifndef quantlib_xxxzciis_hpp 26 #define quantlib_xxxzciis_hpp 27 28 #include <ql/instruments/swap.hpp> 29 #include <ql/time/calendar.hpp> 30 #include <ql/time/daycounter.hpp> 31 32 33 34 namespace QuantLib { 35 class ZeroInflationIndex; 36 37 //! Zero-coupon inflation-indexed swap 38 /*! Quoted as a fixed rate \f$ K \f$. At start: 39 \f[ 40 P_n(0,T) N [(1+K)^{T}-1] = 41 P_n(0,T) N \left[ \frac{I(T)}{I(0)} -1 \right] 42 \f] 43 where \f$ T \f$ is the maturity time, \f$ P_n(0,t) \f$ is the 44 nominal discount factor at time \f$ t \f$, \f$ N \f$ is the 45 notional, and \f$ I(t) \f$ is the inflation index value at 46 time \f$ t \f$. 47 48 This inherits from swap and has two very simple legs: a fixed 49 leg, from the quote (K); and an indexed leg. At maturity the 50 two single cashflows are swapped. These are the notional 51 versus the inflation-indexed notional Because the coupons are 52 zero there are no accruals (and no coupons). 53 54 Inflation is generally available on every day, including 55 holidays and weekends. Hence there is a variable to state 56 whether the observe/fix dates for inflation are adjusted or 57 not. The default is not to adjust. 58 59 A zero inflation swap is a simple enough instrument that the 60 standard discounting pricing engine that works for a vanilla 61 swap also works. 62 63 \note we do not need Schedules on the legs because they use 64 one or two dates only per leg. 65 */ 66 class ZeroCouponInflationSwap : public Swap { 67 public: 68 enum Type { Receiver = -1, Payer = 1 }; 69 class arguments; 70 class engine; 71 ZeroCouponInflationSwap(Type type, 72 Real nominal, 73 const Date& startDate, // start date of contract (only) 74 const Date& maturity, // this is pre-adjustment! 75 const Calendar& fixCalendar, 76 BusinessDayConvention fixConvention, 77 const DayCounter& dayCounter, 78 Rate fixedRate, 79 const ext::shared_ptr<ZeroInflationIndex> &infIndex, 80 const Period& observationLag, 81 bool adjustInfObsDates = false, 82 const Calendar& infCalendar = Calendar(), 83 BusinessDayConvention infConvention = BusinessDayConvention()); 84 85 //! \name Inspectors 86 //@{ 87 //! "payer" or "receiver" refer to the inflation-indexed leg type() const88 Type type() const { return type_; } nominal() const89 Real nominal() const { return nominal_; } startDate() const90 Date startDate() const { return startDate_; } maturityDate() const91 Date maturityDate() const { return maturityDate_; } fixedCalendar() const92 Calendar fixedCalendar() const { return fixCalendar_; } fixedConvention() const93 BusinessDayConvention fixedConvention() const { 94 return fixConvention_; 95 } dayCounter() const96 DayCounter dayCounter() const { return dayCounter_; } 97 //! \f$ K \f$ in the above formula. fixedRate() const98 Rate fixedRate() const { return fixedRate_; } inflationIndex() const99 ext::shared_ptr<ZeroInflationIndex> inflationIndex() const { 100 return infIndex_; 101 } observationLag() const102 Period observationLag() const { return observationLag_; } adjustObservationDates() const103 bool adjustObservationDates() const { return adjustInfObsDates_; } inflationCalendar() const104 Calendar inflationCalendar() const { return infCalendar_; } inflationConvention() const105 BusinessDayConvention inflationConvention() const { 106 return infConvention_; 107 } 108 //! just one cashflow (that is not a coupon) in each leg 109 const Leg& fixedLeg() const; 110 //! just one cashflow (that is not a coupon) in each leg 111 const Leg& inflationLeg() const; 112 //@} 113 114 //! \name Instrument interface 115 //@{ 116 void setupArguments(PricingEngine::arguments*) const; 117 void fetchResults(const PricingEngine::results* r) const; 118 //@} 119 120 //! \name Results 121 //@{ 122 Real fixedLegNPV() const; 123 Real inflationLegNPV() const; 124 Real fairRate() const; 125 //@} 126 127 protected: 128 Type type_; 129 Real nominal_; 130 Date startDate_, maturityDate_; 131 Calendar fixCalendar_; 132 BusinessDayConvention fixConvention_; 133 Rate fixedRate_; 134 ext::shared_ptr<ZeroInflationIndex> infIndex_; 135 Period observationLag_; 136 bool adjustInfObsDates_; 137 Calendar infCalendar_; 138 BusinessDayConvention infConvention_; 139 DayCounter dayCounter_; 140 Date baseDate_, obsDate_; 141 }; 142 143 144 class ZeroCouponInflationSwap::arguments : public Swap::arguments { 145 public: 146 Rate fixedRate; 147 void validate() const; 148 }; 149 150 151 class ZeroCouponInflationSwap::engine 152 : public GenericEngine<ZeroCouponInflationSwap::arguments, 153 ZeroCouponInflationSwap::results> {}; 154 155 } 156 157 158 #endif 159