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

lballabio / QuantLib / 23006928006

12 Mar 2026 02:27PM UTC coverage: 74.274% (+0.03%) from 74.242%
23006928006

Pull #2474

github

web-flow
Merge 65a6878ed into 0a02cced0
Pull Request #2474: Add MultipleResetsSwap instrument and rate helper

137 of 186 new or added lines in 3 files covered. (73.66%)

86 existing lines in 5 files now uncovered.

57898 of 77952 relevant lines covered (74.27%)

8738073.7 hits per line

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

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

3
/*
4
 Copyright (C) 2026 Zain Mughal
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/multipleresetscoupon.hpp>
21
#include <ql/instruments/multipleresetsswap.hpp>
22
#include <utility>
23

24
namespace QuantLib {
25

26
    namespace {
27

28
        Schedule buildCouponSchedule(const Schedule& fullResetSchedule, Size resetsPerCoupon) {
14✔
29
            Size n = (fullResetSchedule.size() - 1) / resetsPerCoupon;
14✔
30
            std::vector<Date> dates(n + 1);
14✔
31
            for (Size i = 0; i <= n; ++i)
84✔
32
                dates[i] = fullResetSchedule[i * resetsPerCoupon];
70✔
33
            return Schedule(dates);
28✔
34
        }
35

36
    }
37

38
    MultipleResetsSwap::MultipleResetsSwap(
14✔
39
        Type type, Real nominal,
40
        Schedule fixedSchedule, Rate fixedRate, DayCounter fixedDayCount,
41
        Schedule fullResetSchedule,
42
        const ext::shared_ptr<IborIndex>& iborIndex, Size resetsPerCoupon,
43
        Spread spread, RateAveraging::Type averagingMethod,
44
        ext::optional<BusinessDayConvention> paymentConvention,
45
        Integer paymentLag, const Calendar& paymentCalendar)
14✔
46
    : FixedVsFloatingSwap(type,
47
          std::vector<Real>(fixedSchedule.size() - 1, nominal),
14✔
48
          fixedSchedule, fixedRate, std::move(fixedDayCount),
49
          std::vector<Real>((fullResetSchedule.size() - 1) / resetsPerCoupon, nominal),
14✔
50
          buildCouponSchedule(fullResetSchedule, resetsPerCoupon),
28✔
51
          iborIndex, spread, iborIndex->dayCounter(),
14✔
52
          paymentConvention, paymentLag, paymentCalendar),
53
      fullResetSchedule_(std::move(fullResetSchedule)),
14✔
54
      resetsPerCoupon_(resetsPerCoupon),
14✔
55
      averagingMethod_(averagingMethod) {
70✔
56

57
        QL_REQUIRE((fullResetSchedule_.size() - 1) % resetsPerCoupon_ == 0,
14✔
58
                   "number of reset periods (" << fullResetSchedule_.size() - 1
59
                   << ") is not a multiple of resetsPerCoupon ("
60
                   << resetsPerCoupon_ << ")");
61

62
        legs_[1] = MultipleResetsLeg(fullResetSchedule_, this->iborIndex(), resetsPerCoupon_)
28✔
63
            .withNotionals(floatingNominals())
14✔
64
            .withRateSpreads(spread)
14✔
65
            .withAveragingMethod(averagingMethod_)
14✔
66
            .withPaymentAdjustment(this->paymentConvention())
14✔
67
            .withPaymentLag(paymentLag)
14✔
68
            .withPaymentCalendar(paymentCalendar.empty() ?
28✔
69
                                 fullResetSchedule_.calendar() : paymentCalendar);
28✔
70

71
        for (auto& cf : legs_[1])
70✔
72
            registerWith(cf);
112✔
73
    }
14✔
74

NEW
75
    void MultipleResetsSwap::setupFloatingArguments(arguments* args) const {
×
76
        const Leg& leg = floatingLeg();
77
        Size n = leg.size();
NEW
78
        args->floatingResetDates = args->floatingPayDates = std::vector<Date>(n);
×
NEW
79
        args->floatingFixingDates = std::vector<Date>(n);
×
NEW
80
        args->floatingNominals = std::vector<Real>(n);
×
NEW
81
        args->floatingAccrualTimes = std::vector<Time>(n);
×
NEW
82
        args->floatingSpreads = std::vector<Spread>(n);
×
NEW
83
        args->floatingCoupons = std::vector<Real>(n);
×
NEW
84
        for (Size i = 0; i < n; ++i) {
×
NEW
85
            auto coupon = ext::dynamic_pointer_cast<MultipleResetsCoupon>(leg[i]);
×
NEW
86
            args->floatingResetDates[i] = coupon->accrualStartDate();
×
NEW
87
            args->floatingPayDates[i] = coupon->date();
×
NEW
88
            args->floatingFixingDates[i] = coupon->fixingDate();
×
NEW
89
            args->floatingNominals[i] = coupon->nominal();
×
NEW
90
            args->floatingAccrualTimes[i] = coupon->accrualPeriod();
×
NEW
91
            args->floatingSpreads[i] = coupon->spread();
×
92
            try {
NEW
93
                args->floatingCoupons[i] = coupon->amount();
×
NEW
94
            } catch (Error&) {
×
NEW
95
                args->floatingCoupons[i] = Null<Real>();
×
NEW
96
            }
×
97
        }
NEW
98
    }
×
99

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