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

lballabio / QuantLib / 15995313367

01 Jul 2025 09:24AM UTC coverage: 73.816%. Remained the same
15995313367

push

github

web-flow
Optionlet frequency optional param support in `OptionletStripper`  (#2253)

10 of 11 new or added lines in 3 files covered. (90.91%)

2 existing lines in 1 file now uncovered.

56511 of 76557 relevant lines covered (73.82%)

8807317.87 hits per line

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

96.25
/ql/termstructures/volatility/optionlet/optionletstripper.cpp
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2

3
/*
4
 Copyright (C) 2007 Ferdinando Ametrano
5
 Copyright (C) 2007 Giorgio Facchinetti
6
 Copyright (C) 2015 Peter Caspers
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/indexes/iborindex.hpp>
23
#include <ql/termstructures/volatility/optionlet/optionletstripper.hpp>
24
#include <utility>
25

26
using std::vector;
27

28
namespace QuantLib {
29

30
    OptionletStripper::OptionletStripper(
15✔
31
        const ext::shared_ptr<CapFloorTermVolSurface>& termVolSurface,
32
        ext::shared_ptr<IborIndex> iborIndex,
33
        Handle<YieldTermStructure> discount,
34
        const VolatilityType type,
35
        const Real displacement,
36
        ext::optional<Period> optionletFrequency
NEW
37
    )
×
38
    : termVolSurface_(termVolSurface), iborIndex_(std::move(iborIndex)),
15✔
39
      discount_(std::move(discount)), nStrikes_(termVolSurface->strikes().size()),
15✔
40
      volatilityType_(type), displacement_(displacement), 
15✔
41
      optionletFrequency_(optionletFrequency) {
30✔
42

43
        if (volatilityType_ == Normal) {
15✔
44
            QL_REQUIRE(displacement_ == 0.0,
3✔
45
                       "non-null displacement is not allowed with Normal model");
46
        }
47

48
        if (ext::dynamic_pointer_cast<OvernightIndex>(iborIndex_)) {
30✔
49
            QL_REQUIRE(optionletFrequency_, 
1✔
50
                       "an optionlet frequency is required when using an overnight index");
51
        }
52

53
        registerWith(termVolSurface);
15✔
54
        registerWith(iborIndex_);
15✔
55
        registerWith(discount_);
15✔
56
        registerWith(Settings::instance().evaluationDate());
30✔
57

58
        Period indexTenor = optionletFrequency_ ? *optionletFrequency_ : iborIndex_->tenor();
15✔
59
        Period maxCapFloorTenor = termVolSurface->optionTenors().back();
15✔
60

61
        // optionlet tenors and capFloor lengths
62
        optionletTenors_.push_back(indexTenor);
15✔
63
        capFloorLengths_.push_back(optionletTenors_.back()+indexTenor);
30✔
64
        QL_REQUIRE(maxCapFloorTenor>=capFloorLengths_.back(),
15✔
65
                   "too short (" << maxCapFloorTenor <<
66
                   ") capfloor term vol termVolSurface");
67
        Period nextCapFloorLength = capFloorLengths_.back()+indexTenor;
15✔
68
        while (nextCapFloorLength<=maxCapFloorTenor) {
725✔
69
            optionletTenors_.push_back(capFloorLengths_.back());
710✔
70
            capFloorLengths_.push_back(nextCapFloorLength);
710✔
71
            nextCapFloorLength += indexTenor;
710✔
72
        }
73
        nOptionletTenors_ = optionletTenors_.size();
15✔
74
        
75
        optionletVolatilities_ =
76
            vector<vector<Volatility> >(nOptionletTenors_, 
30✔
77
                                        vector<Volatility>(nStrikes_));
15✔
78
        optionletStrikes_ = vector<vector<Rate> >(nOptionletTenors_,
30✔
79
                                                  termVolSurface->strikes());
15✔
80
        optionletDates_ = vector<Date>(nOptionletTenors_);
15✔
81
        optionletTimes_ = vector<Time>(nOptionletTenors_);
15✔
82
        atmOptionletRate_ = vector<Rate>(nOptionletTenors_);
15✔
83
        optionletPaymentDates_ = vector<Date>(nOptionletTenors_);
15✔
84
        optionletAccrualPeriods_ = vector<Time>(nOptionletTenors_);
15✔
85
    }
15✔
86

87
    const vector<Rate>& OptionletStripper::optionletStrikes(Size i) const {
2,078✔
88
        calculate();
2,078✔
89
        QL_REQUIRE(i<optionletStrikes_.size(),
2,078✔
90
                   "index (" << i <<
91
                   ") must be less than optionletStrikes size (" <<
92
                   optionletStrikes_.size() << ")");
93
        return optionletStrikes_[i];
2,078✔
94
    }   
95

96
    const vector<Volatility>&
97
    OptionletStripper::optionletVolatilities(Size i) const {
1,838✔
98
        calculate();
1,838✔
99
        QL_REQUIRE(i<optionletVolatilities_.size(),
1,838✔
100
                   "index (" << i <<
101
                   ") must be less than optionletVolatilities size (" <<
102
                   optionletVolatilities_.size() << ")");
103
        return optionletVolatilities_[i];
1,838✔
104
    }   
105

106
    const vector<Period>& OptionletStripper::optionletFixingTenors() const {
×
107
        return optionletTenors_;
×
108
    }
109

110
    const vector<Date>& OptionletStripper::optionletFixingDates() const {
112✔
111
        calculate();
112✔
112
        return optionletDates_;
112✔
113
    }
114
      
115
    const vector<Time>& OptionletStripper::optionletFixingTimes() const {
16,780✔
116
        calculate();
16,780✔
117
        return optionletTimes_;
16,780✔
118
    }
119
     
120
    Size OptionletStripper::optionletMaturities() const {
42✔
121
        return optionletTenors_.size();
42✔
122
    }
123

124
    const vector<Date>& OptionletStripper::optionletPaymentDates() const {
2✔
125
        calculate();
2✔
126
        return optionletPaymentDates_;
2✔
127
    }  
128

129
    const vector<Time>& OptionletStripper::optionletAccrualPeriods() const {
2✔
130
        calculate();
2✔
131
        return optionletAccrualPeriods_;
2✔
132
    }
133

134
    const vector<Rate>& OptionletStripper::atmOptionletRates() const {
2✔
135
        calculate();
2✔
136
        return atmOptionletRate_;
2✔
137
    }
138
    
139

140
    DayCounter OptionletStripper::dayCounter() const {
42✔
141
        return termVolSurface_->dayCounter();
42✔
142
    }
143

144
    Calendar OptionletStripper::calendar() const {
42✔
145
        return termVolSurface_->calendar();
42✔
146
    }
147

148
    Natural OptionletStripper::settlementDays() const {
42✔
149
        return termVolSurface_->settlementDays();
42✔
150
    }
151

152
    BusinessDayConvention OptionletStripper::businessDayConvention() const {
42✔
153
        return termVolSurface_->businessDayConvention();
42✔
154
    }
155

156
    ext::shared_ptr<CapFloorTermVolSurface>
157
    OptionletStripper::termVolSurface() const {
4✔
158
        return termVolSurface_;
4✔
159
    }
160

161
    ext::shared_ptr<IborIndex> OptionletStripper::iborIndex() const {
28✔
162
        return iborIndex_;
28✔
163
    }
164

165
    Real OptionletStripper::displacement() const {
52✔
166
        return displacement_;
52✔
167
    }
168

169
    VolatilityType OptionletStripper::volatilityType() const {
55✔
170
        return volatilityType_;
55✔
171
    }
172

173
    ext::optional<Period> OptionletStripper::optionletFrequency() const {
2✔
174
        return optionletFrequency_;
2✔
175
    }
176

177
}
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