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

lballabio / QuantLib / 18905857194

29 Oct 2025 11:09AM UTC coverage: 74.32% (+0.4%) from 73.914%
18905857194

Pull #2344

github

web-flow
Merge d353587bf into d823f4ecb
Pull Request #2344: add multicurve bootstrap

99 of 103 new or added lines in 8 files covered. (96.12%)

216 existing lines in 13 files now uncovered.

57072 of 76792 relevant lines covered (74.32%)

8781066.47 hits per line

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

63.08
/ql/instruments/makeyoyinflationcapfloor.cpp
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2

3
/*
4
 Copyright (C) 2006, 2007 Ferdinando Ametrano
5
 Copyright (C) 2007 StatPro Italia srl
6
 Copyright (C) 2009 Chris Kenyon
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
 <https://www.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/cashflows/cashflows.hpp>
23
#include <ql/instruments/makeyoyinflationcapfloor.hpp>
24
#include <ql/time/daycounters/thirty360.hpp>
25
#include <utility>
26

27
namespace QuantLib {
28

29
    MakeYoYInflationCapFloor::MakeYoYInflationCapFloor(YoYInflationCapFloor::Type capFloorType,
88✔
30
                                                       ext::shared_ptr<YoYInflationIndex> index,
31
                                                       const Size& length,
32
                                                       Calendar cal,
33
                                                       const Period& observationLag,
34
                                                       CPI::InterpolationType interpolation)
88✔
35
    : capFloorType_(capFloorType), length_(length), calendar_(std::move(cal)),
88✔
36
      index_(std::move(index)), observationLag_(observationLag),
88✔
37
      interpolation_(interpolation), strike_(Null<Rate>()),
88✔
38

39
      dayCounter_(Thirty360(Thirty360::BondBasis)) {}
176✔
40

41
    MakeYoYInflationCapFloor::operator YoYInflationCapFloor() const {
×
UNCOV
42
        ext::shared_ptr<YoYInflationCapFloor> capfloor = *this;
×
UNCOV
43
        return *capfloor;
×
44
    }
45

46
    MakeYoYInflationCapFloor::operator ext::shared_ptr<YoYInflationCapFloor>() const {
88✔
47

48
        Date startDate;
88✔
49
        if (effectiveDate_ != Date()) {
88✔
50
            startDate = effectiveDate_;
×
51
        } else {
52
            Date referenceDate = Settings::instance().evaluationDate();
88✔
53
            Date spotDate = calendar_.advance(referenceDate,
88✔
54
                                              fixingDays_*Days);
88✔
55
            startDate = spotDate+forwardStart_;
88✔
56
        }
57

58
        Date endDate = calendar_.advance(startDate,length_*Years,Unadjusted);
88✔
59
        Schedule schedule(startDate, endDate, Period(Annual), calendar_,
176✔
60
                          Unadjusted, Unadjusted, // ref periods & acc periods
61
                          DateGeneration::Forward, false);
176✔
62
        Leg leg = yoyInflationLeg(schedule, calendar_, index_,
176✔
63
                                  observationLag_, interpolation_)
88✔
64
        .withPaymentAdjustment(roll_)
88✔
65
        .withPaymentDayCounter(dayCounter_)
88✔
66
        .withNotionals(nominal_)
88✔
67
        ;
68

69
        if (firstCapletExcluded_)
88✔
70
            leg.erase(leg.begin());
71

72
        // only leaves the last coupon
73
        if (asOptionlet_ && leg.size() > 1) {
88✔
74
            auto end = leg.end(); // Sun Studio needs an lvalue
75
            leg.erase(leg.begin(), --end);
76
        }
77

78
        std::vector<Rate> strikeVector(1, strike_);
88✔
79
        if (strike_ == Null<Rate>()) {
88✔
80
            // ATM on the forecasting curve
UNCOV
81
            strikeVector[0] = CashFlows::atmRate(leg, **nominalTermStructure_,
×
UNCOV
82
                                                 false, nominalTermStructure_->referenceDate());
×
83
        }
84

85
        ext::shared_ptr<YoYInflationCapFloor> capFloor(new
86
                    YoYInflationCapFloor(capFloorType_, leg, strikeVector));
88✔
87
        capFloor->setPricingEngine(engine_);
88✔
88
        return capFloor;
88✔
89
    }
88✔
90

91
    MakeYoYInflationCapFloor& MakeYoYInflationCapFloor::withNominal(Real n) {
88✔
92
        nominal_ = n;
88✔
93
        return *this;
88✔
94
    }
95

UNCOV
96
    MakeYoYInflationCapFloor& MakeYoYInflationCapFloor::withEffectiveDate(
×
97
                                            const Date& effectiveDate) {
UNCOV
98
        effectiveDate_ = effectiveDate;
×
UNCOV
99
        return *this;
×
100
    }
101

102
    MakeYoYInflationCapFloor&
103
    MakeYoYInflationCapFloor::withPaymentAdjustment(BusinessDayConvention bdc) {
×
UNCOV
104
        roll_ = bdc;
×
105
        return *this;
×
106
    }
107

108
    MakeYoYInflationCapFloor&
109
    MakeYoYInflationCapFloor::withPaymentDayCounter(const DayCounter& dc) {
77✔
110
        dayCounter_ = dc;
111
        return *this;
77✔
112
    }
113

114
    MakeYoYInflationCapFloor&
115
    MakeYoYInflationCapFloor::withFixingDays(Natural n) {
77✔
116
        fixingDays_ = n;
77✔
117
        return *this;
77✔
118
    }
119

UNCOV
120
    MakeYoYInflationCapFloor& MakeYoYInflationCapFloor::asOptionlet(bool b) {
×
UNCOV
121
        asOptionlet_ = b;
×
UNCOV
122
        return *this;
×
123
    }
124

UNCOV
125
    MakeYoYInflationCapFloor& MakeYoYInflationCapFloor::withPricingEngine(
×
126
        const ext::shared_ptr<PricingEngine>& engine) {
127
        engine_ = engine;
×
128
        return *this;
×
129
    }
130

131
    MakeYoYInflationCapFloor&
132
    MakeYoYInflationCapFloor::withStrike(Rate strike) {
88✔
133
        QL_REQUIRE(nominalTermStructure_.empty(), "ATM strike already given");
88✔
134
        strike_ = strike;
88✔
135
        return *this;
88✔
136
    }
137

138
    MakeYoYInflationCapFloor&
UNCOV
139
    MakeYoYInflationCapFloor::withAtmStrike(
×
140
                      const Handle<YieldTermStructure>& nominalTermStructure) {
UNCOV
141
        QL_REQUIRE(strike_ == Null<Rate>(), "explicit strike already given");
×
142
        nominalTermStructure_ = nominalTermStructure;
UNCOV
143
        return *this;
×
144
    }
145

146
    MakeYoYInflationCapFloor&
UNCOV
147
    MakeYoYInflationCapFloor::withForwardStart(Period forwardStart) {
×
148
        forwardStart_ = forwardStart;
×
UNCOV
149
        return *this;
×
150
    }
151

152
}
153

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

© 2025 Coveralls, Inc