• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lballabio / QuantLib / 16769468566

06 Aug 2025 06:37AM UTC coverage: 73.865% (-0.002%) from 73.867%
16769468566

push

github

web-flow
Deprecate `growthOnly` parameter in CPI bond and helper (#2287)

3 of 8 new or added lines in 2 files covered. (37.5%)

3 existing lines in 1 file now uncovered.

56679 of 76733 relevant lines covered (73.87%)

8780485.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

43.4
/ql/termstructures/yield/bondhelpers.cpp
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2

3
/*
4
 Copyright (C) 2008, 2009 Ferdinando Ametrano
5
 Copyright (C) 2005 Toyin Akin
6
 Copyright (C) 2007 StatPro Italia srl
7

8
 This file is part of QuantLib, a free-software/open-source library
9
 for financial quantitative analysts and developers - http://quantlib.org/
10

11
 QuantLib is free software: you can redistribute it and/or modify it
12
 under the terms of the QuantLib license.  You should have received a
13
 copy of the license along with this program; if not, please email
14
 <quantlib-dev@lists.sf.net>. The license is also available online at
15
 <http://quantlib.org/license.shtml>.
16

17
 This program is distributed in the hope that it will be useful, but WITHOUT
18
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19
 FOR A PARTICULAR PURPOSE.  See the license for more details.
20
*/
21

22
#include <ql/termstructures/yield/bondhelpers.hpp>
23
#include <ql/pricingengines/bond/discountingbondengine.hpp>
24
#include <ql/time/schedule.hpp>
25
#include <ql/settings.hpp>
26
#include <ql/utilities/null_deleter.hpp>
27

28
namespace QuantLib {
29

30
    BondHelper::BondHelper(const Handle<Quote>& price,
144✔
31
                           const ext::shared_ptr<Bond>& bond,
32
                           const Bond::Price::Type priceType)
144✔
33
    : RateHelper(price), bond_(ext::make_shared<Bond>(*bond)), priceType_(priceType) {
288✔
34

35
        // the bond's last cashflow date, which can be later than
36
        // bond's maturity date because of adjustment
37
        latestDate_ = bond_->cashflows().back()->date();
144✔
38
        earliestDate_ = bond_->nextCashFlowDate();
144✔
39

40
        bond_->setPricingEngine(
432✔
41
             ext::make_shared<DiscountingBondEngine>(termStructureHandle_));
144✔
42
    }
144✔
43

44
    void BondHelper::setTermStructure(YieldTermStructure* t) {
963✔
45
        // do not set the relinkable handle as an observer -
46
        // force recalculation when needed
47
        termStructureHandle_.linkTo(
963✔
48
            ext::shared_ptr<YieldTermStructure>(t, null_deleter()), false);
963✔
49

50
        BootstrapHelper<YieldTermStructure>::setTermStructure(t);
963✔
51
    }
963✔
52

53
    Real BondHelper::impliedQuote() const {
746,351✔
54
        QL_REQUIRE(termStructure_ != nullptr, "term structure not set");
746,351✔
55
        // we didn't register as observers - force calculation
56
        bond_->recalculate();
746,351✔
57

58
        switch (priceType_) {
746,351✔
59
            case Bond::Price::Clean:
746,351✔
60
                return bond_->cleanPrice();
746,351✔
61
                break;
62

63
            case Bond::Price::Dirty:
×
64
                return bond_->dirtyPrice();
×
65
                break;
66

67
            default:
×
68
                QL_FAIL("This price type isn't implemented.");
×
69
        }
70
    }
71

72
    void BondHelper::accept(AcyclicVisitor& v) {
×
73
        auto* v1 = dynamic_cast<Visitor<BondHelper>*>(&v);
×
74
        if (v1 != nullptr)
×
75
            v1->visit(*this);
×
76
        else
77
            BootstrapHelper<YieldTermStructure>::accept(v);
×
78
    }
×
79

80

81
    FixedRateBondHelper::FixedRateBondHelper(
130✔
82
                                    const Handle<Quote>& price,
83
                                    Natural settlementDays,
84
                                    Real faceAmount,
85
                                    Schedule schedule,
86
                                    const std::vector<Rate>& coupons,
87
                                    const DayCounter& dayCounter,
88
                                    BusinessDayConvention paymentConvention,
89
                                    Real redemption,
90
                                    const Date& issueDate,
91
                                    const Calendar& paymentCalendar,
92
                                    const Period& exCouponPeriod,
93
                                    const Calendar& exCouponCalendar,
94
                                    const BusinessDayConvention exCouponConvention,
95
                                    bool exCouponEndOfMonth,
96
                                    const Bond::Price::Type priceType)
130✔
97
    : BondHelper(price,
98
                 ext::make_shared<FixedRateBond>(settlementDays, faceAmount, std::move(schedule),
260✔
99
                                                 coupons, dayCounter, paymentConvention,
100
                                                 redemption, issueDate, paymentCalendar,
101
                                                 exCouponPeriod, exCouponCalendar,
102
                                                 exCouponConvention, exCouponEndOfMonth),
103
                 priceType) {}
260✔
104

UNCOV
105
    void FixedRateBondHelper::accept(AcyclicVisitor& v) {
×
UNCOV
106
        auto* v1 = dynamic_cast<Visitor<FixedRateBondHelper>*>(&v);
×
107
        if (v1 != nullptr)
×
108
            v1->visit(*this);
×
109
        else
110
            BondHelper::accept(v);
×
111
    }
×
112

113

114
    QL_DEPRECATED_DISABLE_WARNING
115

NEW
116
    CPIBondHelper::CPIBondHelper(
×
117
                            const Handle<Quote>& price,
118
                            Natural settlementDays,
119
                            Real faceAmount,
120
                            Real baseCPI,
121
                            const Period& observationLag,
122
                            const ext::shared_ptr<ZeroInflationIndex>& cpiIndex,
123
                            CPI::InterpolationType observationInterpolation,
124
                            Schedule schedule,
125
                            const std::vector<Rate>& fixedRate,
126
                            const DayCounter& accrualDayCounter,
127
                            BusinessDayConvention paymentConvention,
128
                            const Date& issueDate,
129
                            const Calendar& paymentCalendar,
130
                            const Period& exCouponPeriod,
131
                            const Calendar& exCouponCalendar,
132
                            const BusinessDayConvention exCouponConvention,
133
                            bool exCouponEndOfMonth,
NEW
134
                            const Bond::Price::Type priceType)
×
135
    : CPIBondHelper(price, settlementDays, faceAmount, false, baseCPI, observationLag,
136
                    cpiIndex, observationInterpolation, std::move(schedule), fixedRate,
137
                    accrualDayCounter, paymentConvention, issueDate, paymentCalendar,
138
                    exCouponPeriod, exCouponCalendar, exCouponConvention, exCouponEndOfMonth,
NEW
139
                    priceType) {}
×
140

UNCOV
141
    CPIBondHelper::CPIBondHelper(
×
142
                            const Handle<Quote>& price,
143
                            Natural settlementDays,
144
                            Real faceAmount,
145
                            const bool growthOnly,
146
                            Real baseCPI,
147
                            const Period& observationLag,
148
                            const ext::shared_ptr<ZeroInflationIndex>& cpiIndex,
149
                            CPI::InterpolationType observationInterpolation,
150
                            Schedule schedule,
151
                            const std::vector<Rate>& fixedRate,
152
                            const DayCounter& accrualDayCounter,
153
                            BusinessDayConvention paymentConvention,
154
                            const Date& issueDate,
155
                            const Calendar& paymentCalendar,
156
                            const Period& exCouponPeriod,
157
                            const Calendar& exCouponCalendar,
158
                            const BusinessDayConvention exCouponConvention,
159
                            bool exCouponEndOfMonth,
160
                            const Bond::Price::Type priceType)
×
161
    : BondHelper(price,
162
                 // make_shared and deprecation interfere; restore later
NEW
163
                 ext::shared_ptr<Bond>(new CPIBond(settlementDays, faceAmount, growthOnly, baseCPI,
×
164
                                           observationLag, cpiIndex, observationInterpolation,
165
                                           std::move(schedule), fixedRate, accrualDayCounter, paymentConvention,
166
                                           issueDate, paymentCalendar, exCouponPeriod, exCouponCalendar,
NEW
167
                                           exCouponConvention, exCouponEndOfMonth)),
×
168
                 priceType) {}
×
169

170
    QL_DEPRECATED_ENABLE_WARNING
171

172
    void CPIBondHelper::accept(AcyclicVisitor& v) {
×
173
        auto* v1 = dynamic_cast<Visitor<CPIBondHelper>*>(&v);
×
174
        if (v1 != nullptr)
×
175
            v1->visit(*this);
×
176
        else
177
            BondHelper::accept(v);
×
178
    }
×
179

180
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc