1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | |
3 | /* |
4 | Copyright (C) 2010, 2011 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 | #include <ql/cashflows/cashflows.hpp> |
21 | #include <ql/cashflows/cashflowvectors.hpp> |
22 | #include <ql/cashflows/couponpricer.hpp> |
23 | #include <ql/cashflows/cpicoupon.hpp> |
24 | #include <ql/cashflows/fixedratecoupon.hpp> |
25 | #include <ql/cashflows/iborcoupon.hpp> |
26 | #include <ql/cashflows/simplecashflow.hpp> |
27 | #include <ql/indexes/inflationindex.hpp> |
28 | #include <ql/instruments/bonds/cpibond.hpp> |
29 | #include <ql/termstructures/yieldtermstructure.hpp> |
30 | #include <ql/time/schedule.hpp> |
31 | #include <utility> |
32 | |
33 | |
34 | namespace QuantLib { |
35 | |
36 | CPIBond::CPIBond(Natural settlementDays, |
37 | Real faceAmount, |
38 | bool growthOnly, |
39 | Real baseCPI, |
40 | const Period& observationLag, |
41 | ext::shared_ptr<ZeroInflationIndex> cpiIndex, |
42 | CPI::InterpolationType observationInterpolation, |
43 | const Schedule& schedule, |
44 | const std::vector<Rate>& fixedRate, |
45 | const DayCounter& accrualDayCounter, |
46 | BusinessDayConvention paymentConvention, |
47 | const Date& issueDate, |
48 | const Calendar& paymentCalendar, |
49 | const Period& exCouponPeriod, |
50 | const Calendar& exCouponCalendar, |
51 | const BusinessDayConvention exCouponConvention, |
52 | bool exCouponEndOfMonth) |
53 | : Bond(settlementDays, |
54 | paymentCalendar == Calendar() ? schedule.calendar() : paymentCalendar, |
55 | issueDate), |
56 | frequency_(schedule.tenor().frequency()), dayCounter_(accrualDayCounter), |
57 | growthOnly_(growthOnly), baseCPI_(baseCPI), observationLag_(observationLag), |
58 | cpiIndex_(std::move(cpiIndex)), observationInterpolation_(observationInterpolation) { |
59 | |
60 | maturityDate_ = schedule.endDate(); |
61 | |
62 | // a CPIleg know about zero legs and inclusion of base inflation notional |
63 | cashflows_ = CPILeg(schedule, cpiIndex_, |
64 | baseCPI_, observationLag_) |
65 | .withNotionals(notional: faceAmount) |
66 | .withFixedRates(fixedRates: fixedRate) |
67 | .withPaymentDayCounter(accrualDayCounter) |
68 | .withPaymentAdjustment(paymentConvention) |
69 | .withPaymentCalendar(calendar_) |
70 | .withObservationInterpolation(observationInterpolation_) |
71 | .withSubtractInflationNominal(growthOnly_) |
72 | .withExCouponPeriod(exCouponPeriod, |
73 | exCouponCalendar, |
74 | exCouponConvention, |
75 | endOfMonth: exCouponEndOfMonth); |
76 | |
77 | |
78 | calculateNotionalsFromCashflows(); |
79 | |
80 | redemptions_.push_back(x: cashflows_.back()); |
81 | |
82 | registerWith(h: cpiIndex_); |
83 | Leg::const_iterator i; |
84 | for (i = cashflows_.begin(); i < cashflows_.end(); ++i) { |
85 | registerWith(h: *i); |
86 | } |
87 | } |
88 | } |
89 | |
90 | |