1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 /*
4  Copyright (C) 2007 Roland Lichters
5  Copyright (C) 2007 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 averagebmacoupon.hpp
22     \brief coupon paying a weighted average of BMA-index fixings
23 */
24 
25 #ifndef quantlib_bma_coupon_hpp
26 #define quantlib_bma_coupon_hpp
27 
28 #include <ql/cashflows/floatingratecoupon.hpp>
29 #include <ql/indexes/bmaindex.hpp>
30 
31 namespace QuantLib {
32 
33     //! Average BMA coupon
34     /*! %Coupon paying a BMA index, where the coupon rate is a
35         weighted average of relevant fixings.
36 
37         The weighted average is computed based on the
38         actual calendar days for which a given fixing is valid and
39         contributing to the given interest period.
40 
41         Before weights are computed, the fixing schedule is adjusted
42         for the index's fixing day gap. See rate() method for details.
43     */
44     class AverageBMACoupon : public FloatingRateCoupon {
45       public:
46         AverageBMACoupon(const Date& paymentDate,
47                          Real nominal,
48                          const Date& startDate,
49                          const Date& endDate,
50                          const ext::shared_ptr<BMAIndex>& index,
51                          Real gearing = 1.0,
52                          Spread spread = 0.0,
53                          const Date& refPeriodStart = Date(),
54                          const Date& refPeriodEnd = Date(),
55                          const DayCounter& dayCounter = DayCounter());
56 
57         //! \name FloatingRateCoupon interface
58         //@{
59         //! not applicable here; use fixingDates() instead
60         Date fixingDate() const;
61         //! fixing dates of the rates to be averaged
62         std::vector<Date> fixingDates() const;
63 
64         //! not applicable here; use indexFixings() instead
65         Rate indexFixing() const;
66         //! fixings of the underlying index to be averaged
67         std::vector<Rate> indexFixings() const;
68 
69         //! not applicable here
70         Rate convexityAdjustment() const;
71         //@}
72 
73         //! \name Visitability
74         //@{
75         void accept(AcyclicVisitor&);
76         //@}
77       private:
78         Schedule fixingSchedule_;
79     };
80 
81 
82     //! helper class building a sequence of average BMA coupons
83     class AverageBMALeg {
84       public:
85         AverageBMALeg(const Schedule& schedule,
86                       const ext::shared_ptr<BMAIndex>& index);
87         AverageBMALeg& withNotionals(Real notional);
88         AverageBMALeg& withNotionals(const std::vector<Real>& notionals);
89         AverageBMALeg& withPaymentDayCounter(const DayCounter&);
90         AverageBMALeg& withPaymentAdjustment(BusinessDayConvention);
91         AverageBMALeg& withGearings(Real gearing);
92         AverageBMALeg& withGearings(const std::vector<Real>& gearings);
93         AverageBMALeg& withSpreads(Spread spread);
94         AverageBMALeg& withSpreads(const std::vector<Spread>& spreads);
95         operator Leg() const;
96       private:
97         Schedule schedule_;
98         ext::shared_ptr<BMAIndex> index_;
99         std::vector<Real> notionals_;
100         DayCounter paymentDayCounter_;
101         BusinessDayConvention paymentAdjustment_;
102         std::vector<Real> gearings_;
103         std::vector<Spread> spreads_;
104     };
105 
106 }
107 
108 
109 #endif
110