Coverage Report

Created: 2026-06-23 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/experimental/coupons/swapspreadindex.cpp
Line
Count
Source
1
/*
2
 Copyright (C) 2014 Peter Caspers
3
4
 This file is part of QuantLib, a free-software/open-source library
5
 for financial quantitative analysts and developers - http://quantlib.org/
6
7
 QuantLib is free software: you can redistribute it and/or modify it
8
 under the terms of the QuantLib license.  You should have received a
9
 copy of the license along with this program; if not, please email
10
 <quantlib-dev@lists.sf.net>. The license is also available online at
11
 <https://www.quantlib.org/license.shtml>.
12
13
14
 This program is distributed in the hope that it will be useful, but
15
 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
 or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */
17
18
#include <ql/experimental/coupons/swapspreadindex.hpp>
19
#include <iomanip>
20
#include <sstream>
21
#include <utility>
22
23
namespace QuantLib {
24
25
    SwapSpreadIndex::SwapSpreadIndex(const std::string& familyName,
26
                                     const ext::shared_ptr<SwapIndex>& swapIndex1,
27
                                     ext::shared_ptr<SwapIndex> swapIndex2,
28
                                     const Real gearing1,
29
                                     const Real gearing2)
30
0
    : InterestRateIndex(familyName,
31
0
                        swapIndex1->tenor(), // does not make sense, but we have to provide one
32
0
                        swapIndex1->fixingDays(),
33
0
                        swapIndex1->currency(),
34
0
                        swapIndex1->fixingCalendar(),
35
0
                        swapIndex1->dayCounter()),
36
0
      swapIndex1_(swapIndex1), swapIndex2_(std::move(swapIndex2)), gearing1_(gearing1),
37
0
      gearing2_(gearing2) {
38
39
0
        registerWith(swapIndex1_);
40
0
        registerWith(swapIndex2_);
41
42
0
        std::ostringstream name;
43
0
        name << std::setprecision(4) << std::fixed << swapIndex1_->name() << "("
44
0
             << gearing1 << ") + " << swapIndex2_->name() << "(" << gearing2
45
0
             << ")";
46
0
        name_ = name.str();
47
48
0
        QL_REQUIRE(swapIndex1_->fixingDays() == swapIndex2_->fixingDays(),
49
0
                   "index1 fixing days ("
50
0
                       << swapIndex1_->fixingDays() << ")"
51
0
                       << "must be equal to index2 fixing days ("
52
0
                       << swapIndex2_->fixingDays() << ")");
53
54
0
        QL_REQUIRE(swapIndex1_->fixingCalendar() ==
55
0
                       swapIndex2_->fixingCalendar(),
56
0
                   "index1 fixingCalendar ("
57
0
                       << swapIndex1_->fixingCalendar() << ")"
58
0
                       << "must be equal to index2 fixingCalendar ("
59
0
                       << swapIndex2_->fixingCalendar() << ")");
60
61
0
        QL_REQUIRE(swapIndex1_->currency() == swapIndex2_->currency(),
62
0
                   "index1 currency (" << swapIndex1_->currency() << ")"
63
0
                                       << "must be equal to index2 currency ("
64
0
                                       << swapIndex2_->currency() << ")");
65
66
0
        QL_REQUIRE(swapIndex1_->dayCounter() == swapIndex2_->dayCounter(),
67
0
                   "index1 dayCounter ("
68
0
                       << swapIndex1_->dayCounter() << ")"
69
0
                       << "must be equal to index2 dayCounter ("
70
0
                       << swapIndex2_->dayCounter() << ")");
71
72
0
        QL_REQUIRE(swapIndex1_->fixedLegTenor() == swapIndex2_->fixedLegTenor(),
73
0
                   "index1 fixedLegTenor ("
74
0
                       << swapIndex1_->fixedLegTenor() << ")"
75
0
                       << "must be equal to index2 fixedLegTenor ("
76
0
                       << swapIndex2_->fixedLegTenor());
77
78
0
        QL_REQUIRE(swapIndex1_->fixedLegConvention() ==
79
0
                       swapIndex2_->fixedLegConvention(),
80
0
                   "index1 fixedLegConvention ("
81
0
                       << swapIndex1_->fixedLegConvention() << ")"
82
0
                       << "must be equal to index2 fixedLegConvention ("
83
0
                       << swapIndex2_->fixedLegConvention());
84
0
    }
85
}