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

lballabio / QuantLib / 18902330216

29 Oct 2025 08:56AM UTC coverage: 74.321% (+0.4%) from 73.914%
18902330216

Pull #2344

github

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

100 of 104 new or added lines in 8 files covered. (96.15%)

216 existing lines in 13 files now uncovered.

57073 of 76793 relevant lines covered (74.32%)

8779123.65 hits per line

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

85.11
/ql/experimental/inflation/yoycapfloortermpricesurface.cpp
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2

3
/*
4
 Copyright (C) 2009 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/experimental/inflation/yoycapfloortermpricesurface.hpp>
21
#include <utility>
22

23
namespace QuantLib {
24

25
    YoYCapFloorTermPriceSurface::YoYCapFloorTermPriceSurface(
2✔
26
        Natural fixingDays,
27
        const Period& lag,
28
        const ext::shared_ptr<YoYInflationIndex>& yii,
29
        CPI::InterpolationType interpolation,
30
        Handle<YieldTermStructure> nominal,
31
        const DayCounter& dc,
32
        const Calendar& cal,
33
        const BusinessDayConvention& bdc,
34
        const std::vector<Rate>& cStrikes,
35
        const std::vector<Rate>& fStrikes,
36
        const std::vector<Period>& cfMaturities,
37
        const Matrix& cPrice,
38
        const Matrix& fPrice)
×
39
    : TermStructure(0, cal, dc),
40
      fixingDays_(fixingDays), bdc_(bdc), yoyIndex_(yii), observationLag_(lag), nominalTS_(std::move(nominal)),
2✔
41
      cStrikes_(cStrikes), fStrikes_(fStrikes), cfMaturities_(cfMaturities), cPrice_(cPrice),
2✔
42
      fPrice_(fPrice), indexIsInterpolated_(detail::CPI::isInterpolated(interpolation, yoyIndex_)) {
8✔
43

44
        // data consistency checking, enough data?
45
        QL_REQUIRE(fStrikes_.size() > 1, "not enough floor strikes");
2✔
46
        QL_REQUIRE(cStrikes_.size() > 1, "not enough cap strikes");
2✔
47
        QL_REQUIRE(cfMaturities_.size() > 1, "not enough maturities");
2✔
48
        QL_REQUIRE(fStrikes_.size() == fPrice.rows(),
2✔
49
                   "floor strikes vs floor price rows not equal");
50
        QL_REQUIRE(cStrikes_.size() == cPrice.rows(),
2✔
51
                   "cap strikes vs cap price rows not equal");
52
        QL_REQUIRE(cfMaturities_.size() == fPrice.columns(),
2✔
53
                   "maturities vs floor price columns not equal");
54
        QL_REQUIRE(cfMaturities_.size() == cPrice.columns(),
2✔
55
                   "maturities vs cap price columns not equal");
56

57
        // data has correct properties (positive, monotonic)?
58
        for(Size j = 0; j <cfMaturities_.size(); j++) {
16✔
59
            QL_REQUIRE( cfMaturities[j] > Period(0,Days), "non-positive maturities");
14✔
60
            if(j>0) {
14✔
61
                QL_REQUIRE( cfMaturities[j] > cfMaturities[j-1],
12✔
62
                            "non-increasing maturities");
63
            }
64
            for(Size i = 0; i <fPrice_.rows(); i++) {
98✔
65
                QL_REQUIRE( fPrice_[i][j] > 0.0,
84✔
66
                            "non-positive floor price: " << fPrice_[i][j] );
67
                if(i>0) {
84✔
68
                    QL_REQUIRE( fPrice_[i][j] >= fPrice_[i-1][j],
70✔
69
                                "non-increasing floor prices");
70
                }
71
            }
72
            for(Size i = 0; i <cPrice_.rows(); i++) {
98✔
73
                QL_REQUIRE( cPrice_[i][j] > 0.0,
84✔
74
                            "non-positive cap price: " << cPrice_[i][j] );
75
                if(i>0) {
84✔
76
                    QL_REQUIRE( cPrice_[i][j] <= cPrice_[i-1][j],
70✔
77
                                "non-decreasing cap prices");
78
                }
79
            }
80
        }
81

82

83
        // Get the set of strikes, noting that repeats, overlaps are
84
        // expected between caps and floors but that no overlap in the
85
        // output is allowed so no repeats or overlaps are used
86
        cfStrikes_ = std::vector<Rate>();
2✔
87
        for(Size i = 0; i <fStrikes_.size(); i++)
14✔
88
            cfStrikes_.push_back( fStrikes[i] );
12✔
89
        Real eps = 0.0000001;
90
        Rate maxFstrike = fStrikes_.back();
2✔
91
        for(Size i = 0; i < cStrikes_.size(); i++) {
14✔
92
            Rate k = cStrikes[i];
12✔
93
            if (k > maxFstrike + eps) cfStrikes_.push_back(k);
12✔
94
        }
95

96
        // final consistency checking
97
        QL_REQUIRE(cfStrikes_.size() > 2, "overall not enough strikes");
2✔
98
        for (Size i = 1; i < cfStrikes_.size(); i++)
22✔
99
            QL_REQUIRE( cfStrikes_[i] > cfStrikes_[i-1],
20✔
100
                        "cfStrikes not increasing");
101
    }
2✔
102

103
    Date YoYCapFloorTermPriceSurface::yoyOptionDateFromTenor(const Period& p) const
264✔
104
    {
105
        return referenceDate() + p;
264✔
106
    }
107

UNCOV
108
    Real YoYCapFloorTermPriceSurface::price(const Period &d, const Rate k) const {
×
UNCOV
109
        return price(yoyOptionDateFromTenor(d), k);
×
110
    }
111

112
    Real YoYCapFloorTermPriceSurface::capPrice(const Period &d, const Rate k) const {
40✔
113
        return capPrice(yoyOptionDateFromTenor(d), k);
40✔
114
    }
115

116
    Real YoYCapFloorTermPriceSurface::floorPrice(const Period &d, const Rate k) const {
48✔
117
        return floorPrice(yoyOptionDateFromTenor(d), k);
48✔
118
    }
119

UNCOV
120
    Rate YoYCapFloorTermPriceSurface::atmYoYSwapRate(const Period &d,
×
121
                        bool extrapolate) const {
UNCOV
122
        return atmYoYSwapRate(yoyOptionDateFromTenor(d), extrapolate);
×
123
    }
124

125
    Rate YoYCapFloorTermPriceSurface::atmYoYRate(const Period &d,
×
126
                                                 const Period& obsLag,
127
                    bool extrapolate) const {
UNCOV
128
        return atmYoYRate(yoyOptionDateFromTenor(d), obsLag, extrapolate);
×
129
    }
130

131
}
132

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