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

lballabio / QuantLib / 22825095276

08 Mar 2026 04:28PM UTC coverage: 74.241% (-0.001%) from 74.242%
22825095276

Pull #2474

github

web-flow
Merge 6644ae412 into 81d819d28
Pull Request #2474: Add MultipleResetsSwap instrument and rate helper

135 of 191 new or added lines in 4 files covered. (70.68%)

67 existing lines in 1 file now uncovered.

57889 of 77974 relevant lines covered (74.24%)

8711976.92 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) {
12✔
29
            Size n = (fullResetSchedule.size() - 1) / resetsPerCoupon;
12✔
30
            std::vector<Date> dates(n + 1);
12✔
31
            for (Size i = 0; i <= n; ++i)
72✔
32
                dates[i] = fullResetSchedule[i * resetsPerCoupon];
60✔
33
            return Schedule(dates);
24✔
34
        }
35

36
    }
37

38
    MultipleResetsSwap::MultipleResetsSwap(
12✔
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)
12✔
46
    : FixedVsFloatingSwap(type,
47
          std::vector<Real>(fixedSchedule.size() - 1, nominal),
12✔
48
          fixedSchedule, fixedRate, std::move(fixedDayCount),
49
          std::vector<Real>((fullResetSchedule.size() - 1) / resetsPerCoupon, nominal),
12✔
50
          buildCouponSchedule(fullResetSchedule, resetsPerCoupon),
24✔
51
          iborIndex, spread, iborIndex->dayCounter(),
12✔
52
          paymentConvention, paymentLag, paymentCalendar),
53
      fullResetSchedule_(std::move(fullResetSchedule)),
12✔
54
      resetsPerCoupon_(resetsPerCoupon),
12✔
55
      averagingMethod_(averagingMethod) {
60✔
56

57
        QL_REQUIRE((fullResetSchedule_.size() - 1) % resetsPerCoupon_ == 0,
12✔
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_)
24✔
63
            .withNotionals(floatingNominals())
12✔
64
            .withRateSpreads(spread)
12✔
65
            .withAveragingMethod(averagingMethod_)
12✔
66
            .withPaymentAdjustment(this->paymentConvention())
12✔
67
            .withPaymentLag(paymentLag)
12✔
68
            .withPaymentCalendar(paymentCalendar.empty() ?
24✔
69
                                 fullResetSchedule_.calendar() : paymentCalendar);
24✔
70

71
        for (auto& cf : legs_[1])
60✔
72
            registerWith(cf);
96✔
73
    }
12✔
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