QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
cpibond.cpp
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
34namespace 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_,
65 .withNotionals(faceAmount)
66 .withFixedRates(fixedRate)
67 .withPaymentDayCounter(accrualDayCounter)
68 .withPaymentAdjustment(paymentConvention)
72 .withExCouponPeriod(exCouponPeriod,
73 exCouponCalendar,
74 exCouponConvention,
75 exCouponEndOfMonth);
76
77
79
80 redemptions_.push_back(cashflows_.back());
81
83 Leg::const_iterator i;
84 for (i = cashflows_.begin(); i < cashflows_.end(); ++i) {
85 registerWith(*i);
86 }
87 }
88}
89
Base bond class.
Definition: bond.hpp:59
Calendar calendar_
Definition: bond.hpp:285
Leg redemptions_
Definition: bond.hpp:289
Leg cashflows_
Definition: bond.hpp:288
Date maturityDate_
Definition: bond.hpp:291
void calculateNotionalsFromCashflows()
Definition: bond.cpp:363
Period observationLag_
Definition: cpibond.hpp:76
ext::shared_ptr< ZeroInflationIndex > cpiIndex_
Definition: cpibond.hpp:77
CPI::InterpolationType observationInterpolation_
Definition: cpibond.hpp:78
CPIBond(Natural settlementDays, Real faceAmount, bool growthOnly, Real baseCPI, const Period &observationLag, ext::shared_ptr< ZeroInflationIndex > cpiIndex, CPI::InterpolationType observationInterpolation, const Schedule &schedule, const std::vector< Rate > &coupons, const DayCounter &accrualDayCounter, BusinessDayConvention paymentConvention=ModifiedFollowing, const Date &issueDate=Date(), const Calendar &paymentCalendar=Calendar(), const Period &exCouponPeriod=Period(), const Calendar &exCouponCalendar=Calendar(), BusinessDayConvention exCouponConvention=Unadjusted, bool exCouponEndOfMonth=false)
Definition: cpibond.cpp:36
Helper class building a sequence of capped/floored CPI coupons.
Definition: cpicoupon.hpp:277
CPILeg & withNotionals(Real notional)
Definition: cpicoupon.cpp:285
CPILeg & withPaymentAdjustment(BusinessDayConvention)
Definition: cpicoupon.cpp:305
CPILeg & withSubtractInflationNominal(bool)
Definition: cpicoupon.cpp:295
CPILeg & withFixedRates(Real fixedRate)
Definition: cpicoupon.cpp:275
CPILeg & withExCouponPeriod(const Period &, const Calendar &, BusinessDayConvention, bool endOfMonth=false)
Definition: cpicoupon.cpp:345
CPILeg & withPaymentDayCounter(const DayCounter &)
Definition: cpicoupon.cpp:300
CPILeg & withPaymentCalendar(const Calendar &)
Definition: cpicoupon.cpp:310
CPILeg & withObservationInterpolation(CPI::InterpolationType)
Definition: cpicoupon.cpp:269
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
Payment schedule.
Definition: schedule.hpp:40
const Date & endDate() const
Definition: schedule.hpp:184
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Definition: any.hpp:35
STL namespace.
InterpolationType
when you observe an index, how do you interpolate between fixings?