1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 /*
4  Copyright (C) 2009 Chris Kenyon
5 
6  This file is part of QuantLib, a free-software/open-source library
7  for financial quantitative analysts and developers - http://quantlib.org/
8 
9  QuantLib is free software: you can redistribute it and/or modify it
10  under the terms of the QuantLib license.  You should have received a
11  copy of the license along with this program; if not, please email
12  <quantlib-dev@lists.sf.net>. The license is also available online at
13  <http://quantlib.org/license.shtml>.
14 
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE.  See the license for more details.
18  */
19 
20 /*! \file yoyinflationcoupon.hpp
21  \brief Coupon paying a yoy inflation index
22  */
23 
24 #ifndef quantlib_newyoy_coupon_hpp
25 #define quantlib_newyoy_coupon_hpp
26 
27 #include <ql/cashflows/inflationcoupon.hpp>
28 #include <ql/indexes/inflationindex.hpp>
29 #include <ql/time/schedule.hpp>
30 
31 namespace QuantLib {
32     class YoYInflationCouponPricer;
33 
34     //! %Coupon paying a YoY-inflation type index
35     class YoYInflationCoupon : public InflationCoupon {
36     public:
37         YoYInflationCoupon(const Date& paymentDate,
38                         Real nominal,
39                         const Date& startDate,
40                         const Date& endDate,
41                         Natural fixingDays,
42                         const ext::shared_ptr<YoYInflationIndex>& index,
43                         const Period& observationLag,
44                         const DayCounter& dayCounter,
45                         Real gearing = 1.0,
46                         Spread spread = 0.0,
47                         const Date& refPeriodStart = Date(),
48                         const Date& refPeriodEnd = Date()
49                         );
50 
51         //! \name Inspectors
52         //@{
53         //! index gearing, i.e. multiplicative coefficient for the index
gearing() const54         Real gearing() const { return gearing_; }
55         //! spread paid over the fixing of the underlying index
spread() const56         Spread spread() const { return spread_; }
57 
58         Rate adjustedFixing() const;
59 
60         const ext::shared_ptr<YoYInflationIndex>& yoyIndex() const;
61 
62         //@}
63         //! \name Visitability
64         //@{
65         virtual void accept(AcyclicVisitor&);
66         //@}
67 
68     private:
69         ext::shared_ptr<YoYInflationIndex> yoyIndex_;
70     protected:
71 
72         Real gearing_;
73         Spread spread_;
74         bool checkPricerImpl(const ext::shared_ptr<InflationCouponPricer>&) const;
75     };
76 
77     inline const ext::shared_ptr<YoYInflationIndex>&
yoyIndex() const78     YoYInflationCoupon::yoyIndex() const {
79         return yoyIndex_;
80     }
81 
adjustedFixing() const82     inline Rate YoYInflationCoupon::adjustedFixing() const {
83         return (rate()-spread())/gearing();
84     }
85 
86 
87 
88 
89     //! Helper class building a sequence of capped/floored yoy inflation coupons
90     //! payoff is: spread + gearing x index
91     class yoyInflationLeg {
92     public:
93         yoyInflationLeg(const Schedule& schedule, const Calendar& cal,
94                         const ext::shared_ptr<YoYInflationIndex>& index,
95                         const Period& observationLag);
96         yoyInflationLeg& withNotionals(Real notional);
97         yoyInflationLeg& withNotionals(const std::vector<Real>& notionals);
98         yoyInflationLeg& withPaymentDayCounter(const DayCounter&);
99         yoyInflationLeg& withPaymentAdjustment(BusinessDayConvention);
100         yoyInflationLeg& withFixingDays(Natural fixingDays);
101         yoyInflationLeg& withFixingDays(const std::vector<Natural>& fixingDays);
102         yoyInflationLeg& withGearings(Real gearing);
103         yoyInflationLeg& withGearings(const std::vector<Real>& gearings);
104         yoyInflationLeg& withSpreads(Spread spread);
105         yoyInflationLeg& withSpreads(const std::vector<Spread>& spreads);
106         yoyInflationLeg& withCaps(Rate cap);
107         yoyInflationLeg& withCaps(const std::vector<Rate>& caps);
108         yoyInflationLeg& withFloors(Rate floor);
109         yoyInflationLeg& withFloors(const std::vector<Rate>& floors);
110         operator Leg() const;
111     private:
112         Schedule schedule_;
113         ext::shared_ptr<YoYInflationIndex> index_;
114         Period observationLag_;
115         std::vector<Real> notionals_;
116         DayCounter paymentDayCounter_;
117         BusinessDayConvention paymentAdjustment_;
118         Calendar paymentCalendar_;
119         std::vector<Natural> fixingDays_;
120         std::vector<Real> gearings_;
121         std::vector<Spread> spreads_;
122         std::vector<Rate> caps_, floors_;
123     };
124 
125 
126 
127 }
128 
129 #endif
130 
131