Coverage Report

Created: 2026-02-03 07:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/instruments/bonds/cpibond.cpp
Line
Count
Source
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
 <https://www.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
    QL_DEPRECATED_DISABLE_WARNING
37
38
    CPIBond::CPIBond(Natural settlementDays,
39
                     Real faceAmount,
40
                     Real baseCPI,
41
                     const Period& observationLag,
42
                     ext::shared_ptr<ZeroInflationIndex> cpiIndex,
43
                     CPI::InterpolationType observationInterpolation,
44
                     Schedule schedule,
45
                     const std::vector<Rate>& fixedRate,
46
                     const DayCounter& accrualDayCounter,
47
                     BusinessDayConvention paymentConvention,
48
                     const Date& issueDate,
49
                     const Calendar& paymentCalendar,
50
                     const Period& exCouponPeriod,
51
                     const Calendar& exCouponCalendar,
52
                     const BusinessDayConvention exCouponConvention,
53
                     bool exCouponEndOfMonth)
54
0
    : CPIBond(settlementDays, faceAmount, false, baseCPI, observationLag, std::move(cpiIndex),
55
0
              observationInterpolation, std::move(schedule), fixedRate, accrualDayCounter,
56
0
              paymentConvention, issueDate, paymentCalendar, exCouponPeriod,
57
0
              exCouponCalendar, exCouponConvention, exCouponEndOfMonth) {}
Unexecuted instantiation: QuantLib::CPIBond::CPIBond(unsigned int, double, double, QuantLib::Period const&, boost::shared_ptr<QuantLib::ZeroInflationIndex>, QuantLib::CPI::InterpolationType, QuantLib::Schedule, std::__1::vector<double, std::__1::allocator<double> > const&, QuantLib::DayCounter const&, QuantLib::BusinessDayConvention, QuantLib::Date const&, QuantLib::Calendar const&, QuantLib::Period const&, QuantLib::Calendar const&, QuantLib::BusinessDayConvention, bool)
Unexecuted instantiation: QuantLib::CPIBond::CPIBond(unsigned int, double, double, QuantLib::Period const&, boost::shared_ptr<QuantLib::ZeroInflationIndex>, QuantLib::CPI::InterpolationType, QuantLib::Schedule, std::__1::vector<double, std::__1::allocator<double> > const&, QuantLib::DayCounter const&, QuantLib::BusinessDayConvention, QuantLib::Date const&, QuantLib::Calendar const&, QuantLib::Period const&, QuantLib::Calendar const&, QuantLib::BusinessDayConvention, bool)
58
59
    CPIBond::CPIBond(Natural settlementDays,
60
                     Real faceAmount,
61
                     bool growthOnly,
62
                     Real baseCPI,
63
                     const Period& observationLag,
64
                     ext::shared_ptr<ZeroInflationIndex> cpiIndex,
65
                     CPI::InterpolationType observationInterpolation,
66
                     Schedule schedule,
67
                     const std::vector<Rate>& fixedRate,
68
                     const DayCounter& accrualDayCounter,
69
                     BusinessDayConvention paymentConvention,
70
                     const Date& issueDate,
71
                     const Calendar& paymentCalendar,
72
                     const Period& exCouponPeriod,
73
                     const Calendar& exCouponCalendar,
74
                     const BusinessDayConvention exCouponConvention,
75
                     bool exCouponEndOfMonth)
76
0
    : Bond(settlementDays,
77
0
           paymentCalendar == Calendar() ? schedule.calendar() : paymentCalendar,
78
0
           issueDate),
79
0
      frequency_(schedule.tenor().frequency()), dayCounter_(accrualDayCounter),
80
0
      growthOnly_(growthOnly), baseCPI_(baseCPI), observationLag_(observationLag),
81
0
      cpiIndex_(std::move(cpiIndex)), observationInterpolation_(observationInterpolation) {
82
83
0
        maturityDate_ = schedule.endDate();
84
85
0
        cashflows_ = CPILeg(std::move(schedule), cpiIndex_,
86
0
                            baseCPI_, observationLag_)
87
0
            .withNotionals(faceAmount)
88
0
            .withFixedRates(fixedRate)
89
0
            .withPaymentDayCounter(accrualDayCounter)
90
0
            .withPaymentAdjustment(paymentConvention)
91
0
            .withPaymentCalendar(calendar_)
92
0
            .withObservationInterpolation(observationInterpolation_)
93
0
            .withSubtractInflationNominal(growthOnly_)
94
0
            .withExCouponPeriod(exCouponPeriod,
95
0
                                exCouponCalendar,
96
0
                                exCouponConvention,
97
0
                                exCouponEndOfMonth);
98
99
100
0
        calculateNotionalsFromCashflows();
101
102
0
        redemptions_.push_back(cashflows_.back());
103
104
0
        registerWith(cpiIndex_);
105
0
        Leg::const_iterator i;
106
0
        for (i = cashflows_.begin(); i < cashflows_.end(); ++i) {
107
0
            registerWith(*i);
108
0
        }
109
0
    }
Unexecuted instantiation: QuantLib::CPIBond::CPIBond(unsigned int, double, bool, double, QuantLib::Period const&, boost::shared_ptr<QuantLib::ZeroInflationIndex>, QuantLib::CPI::InterpolationType, QuantLib::Schedule, std::__1::vector<double, std::__1::allocator<double> > const&, QuantLib::DayCounter const&, QuantLib::BusinessDayConvention, QuantLib::Date const&, QuantLib::Calendar const&, QuantLib::Period const&, QuantLib::Calendar const&, QuantLib::BusinessDayConvention, bool)
Unexecuted instantiation: QuantLib::CPIBond::CPIBond(unsigned int, double, bool, double, QuantLib::Period const&, boost::shared_ptr<QuantLib::ZeroInflationIndex>, QuantLib::CPI::InterpolationType, QuantLib::Schedule, std::__1::vector<double, std::__1::allocator<double> > const&, QuantLib::DayCounter const&, QuantLib::BusinessDayConvention, QuantLib::Date const&, QuantLib::Calendar const&, QuantLib::Period const&, QuantLib::Calendar const&, QuantLib::BusinessDayConvention, bool)
110
111
    QL_DEPRECATED_ENABLE_WARNING
112
113
}