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

lballabio / QuantLib / 29513377275

16 Jul 2026 03:55PM UTC coverage: 74.954%. Remained the same
29513377275

push

github

web-flow
Deprecate `ext::any`, `ext::optional` and friends (#2660)

27 of 38 new or added lines in 27 files covered. (71.05%)

59555 of 79455 relevant lines covered (74.95%)

8618938.55 hits per line

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

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

3
/*
4
 Copyright (C) 2007, 2008, 2014 Ferdinando Ametrano
5
 Copyright (C) 2007 Giorgio Facchinetti
6

7
 This file is part of QuantLib, a free-software/open-source library
8
 for financial quantitative analysts and developers - http://quantlib.org/
9

10
 QuantLib is free software: you can redistribute it and/or modify it
11
 under the terms of the QuantLib license.  You should have received a
12
 copy of the license along with this program; if not, please email
13
 <quantlib-dev@lists.sf.net>. The license is also available online at
14
 <https://www.quantlib.org/license.shtml>.
15

16
 This program is distributed in the hope that it will be useful, but WITHOUT
17
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
 FOR A PARTICULAR PURPOSE.  See the license for more details.
19
*/
20

21
#include <ql/cashflows/cashflows.hpp>
22
#include <ql/exercise.hpp>
23
#include <ql/indexes/swapindex.hpp>
24
#include <ql/instruments/makeois.hpp>
25
#include <ql/instruments/makeswaption.hpp>
26
#include <ql/instruments/makevanillaswap.hpp>
27
#include <ql/pricingengines/swap/discountingswapengine.hpp>
28
#include <ql/optional.hpp>
29
#include <ql/settings.hpp>
30
#include <utility>
31

32
namespace QuantLib {
33

34
    MakeSwaption::MakeSwaption(ext::shared_ptr<SwapIndex> swapIndex,
106✔
35
                               const Period& optionTenor,
36
                               Rate strike)
106✔
37
    : swapIndex_(std::move(swapIndex)), delivery_(Settlement::Physical),
106✔
38
      settlementMethod_(Settlement::PhysicalOTC), optionTenor_(optionTenor),
106✔
39
      optionConvention_(ModifiedFollowing), strike_(strike),
212✔
40
      underlyingType_(Swap::Payer), nominal_(1.0) {}
106✔
41

42
    MakeSwaption::MakeSwaption(ext::shared_ptr<SwapIndex> swapIndex,
1✔
43
                               const Date& fixingDate,
44
                               Rate strike)
1✔
45
    : swapIndex_(std::move(swapIndex)), delivery_(Settlement::Physical),
1✔
46
      settlementMethod_(Settlement::PhysicalOTC), optionConvention_(ModifiedFollowing),
1✔
47
      fixingDate_(fixingDate), strike_(strike), underlyingType_(Swap::Payer) {}
1✔
48

49
    MakeSwaption::operator Swaption() const {
107✔
50
        ext::shared_ptr<Swaption> swaption = *this;
107✔
51
        return *swaption;
214✔
52
    }
53

54
    MakeSwaption::operator ext::shared_ptr<Swaption>() const {
107✔
55

56
        const Calendar& calendar = exerciseCalendar_.empty()
57
            ? swapIndex_->fixingCalendar()
105✔
58
            : exerciseCalendar_;
212✔
59
        Date refDate = Settings::instance().evaluationDate();
107✔
60
        // if the evaluation date is not a business day
61
        // then move to the next business day
62
        refDate = calendar.adjust(refDate);
107✔
63
        if (fixingDate_ == Date())
107✔
64
            fixingDate_ = calendar.advance(refDate, optionTenor_,
106✔
65
                                           optionConvention_);
106✔
66
        if (exerciseDate_ == Date()) {
107✔
67
            exercise_ = ext::shared_ptr<Exercise>(new
212✔
68
                EuropeanExercise(fixingDate_));
212✔
69
        } else {
70
            QL_REQUIRE(exerciseDate_ <= fixingDate_,
1✔
71
                       "exercise date (" << exerciseDate_ << ") must be less "
72
                       "than or equal to fixing date (" << fixingDate_ << ")");
73
            exercise_ = ext::shared_ptr<Exercise>(new
2✔
74
                EuropeanExercise(exerciseDate_));
2✔
75
        }
76

77
        Rate usedStrike;
78
        ext::shared_ptr<OvernightIndexedSwapIndex> OIswap_index = ext::dynamic_pointer_cast<OvernightIndexedSwapIndex>(swapIndex_);
107✔
79
        if (strike_ == Null<Rate>()) {
107✔
80
            // ATM on curve(s) attached to index
81
            QL_REQUIRE(!swapIndex_->forwardingTermStructure().empty(),
208✔
82
                       "null term structure set to this instance of " <<
83
                       swapIndex_->name());
84
            if (OIswap_index) {
104✔
85
                auto temp = OIswap_index->underlyingSwap(fixingDate_);
×
86
                temp->setPricingEngine(
×
87
                    ext::make_shared<DiscountingSwapEngine>(
×
88
                        swapIndex_->exogenousDiscount()
×
89
                        ? swapIndex_->discountingTermStructure()
×
90
                        : swapIndex_->forwardingTermStructure(),
91
                        false
×
92
                    )
93
                );
94
                usedStrike = temp->fairRate();
×
95
            } else {
96
                auto temp = swapIndex_->underlyingSwap(fixingDate_);
104✔
97
                temp->setPricingEngine(
312✔
98
                    ext::make_shared<DiscountingSwapEngine>(
208✔
99
                        swapIndex_->exogenousDiscount()
104✔
100
                        ? swapIndex_->discountingTermStructure()
104✔
101
                        : swapIndex_->forwardingTermStructure(),
102
                        false
104✔
103
                    )
104
                );
105
                usedStrike = temp->fairRate();
104✔
106
            }
107
        } else {
108
            usedStrike = strike_;
109
        }
110

111
        BusinessDayConvention bdc = swapIndex_->fixedLegConvention();
107✔
112
        if (OIswap_index) {
107✔
113
            underlyingSwap_ =
114
                (ext::shared_ptr<OvernightIndexedSwap>)(
×
115
                    MakeOIS(swapIndex_->tenor(),
×
116
                            OIswap_index->overnightIndex(), usedStrike)
×
117
                    .withEffectiveDate(swapIndex_->valueDate(fixingDate_))
×
118
                    .withPaymentCalendar(swapIndex_->fixingCalendar())
×
119
                    .withFixedLegDayCount(swapIndex_->dayCounter())
×
120
                    .withPaymentAdjustment(bdc)
×
121
                    .withFixedLegConvention(bdc)
×
122
                    .withFixedLegTerminationDateConvention(bdc)
×
123
                    .withType(underlyingType_)
×
124
                    .withNominal(nominal_)
×
125
                    );
×
126
        } else {
127
            underlyingSwap_ =
128
                (ext::shared_ptr<VanillaSwap>)(
107✔
129
                    MakeVanillaSwap(swapIndex_->tenor(),
214✔
130
                                    swapIndex_->iborIndex(), usedStrike)
214✔
131
                    .withEffectiveDate(swapIndex_->valueDate(fixingDate_))
107✔
132
                    .withFixedLegCalendar(swapIndex_->fixingCalendar())
214✔
133
                    .withFixedLegDayCount(swapIndex_->dayCounter())
107✔
134
                    .withFixedLegTenor(swapIndex_->fixedLegTenor())
214✔
135
                    .withFixedLegConvention(bdc)
107✔
136
                    .withFixedLegTerminationDateConvention(bdc)
107✔
137
                    .withType(underlyingType_)
107✔
138
                    .withNominal(nominal_)
107✔
139
                    .withIndexedCoupons(useIndexedCoupons_)
107✔
140
                    );
107✔
141
        }
142
        ext::shared_ptr<Swaption> swaption = ext::make_shared<Swaption>(
143
            underlyingSwap_, exercise_, delivery_, settlementMethod_);
107✔
144
        swaption->setPricingEngine(engine_);
107✔
145
        return swaption;
107✔
146
    }
147

148
    MakeSwaption& MakeSwaption::withSettlementType(Settlement::Type delivery) {
×
149
        delivery_ = delivery;
×
150
        return *this;
×
151
    }
152

153
    MakeSwaption& MakeSwaption::withSettlementMethod(
×
154
        Settlement::Method settlementMethod) {
155
        settlementMethod_ = settlementMethod;
×
156
        return *this;
×
157
    }
158

159
    MakeSwaption&
160
    MakeSwaption::withOptionConvention(BusinessDayConvention bdc) {
×
161
        optionConvention_ = bdc;
×
162
        return *this;
×
163
    }
164

165
    MakeSwaption& MakeSwaption::withExerciseDate(const Date& date) {
1✔
166
        exerciseDate_ = date;
1✔
167
        return *this;
1✔
168
    }
169

170
    MakeSwaption& MakeSwaption::withExerciseCalendar(const Calendar& cal) {
2✔
171
        exerciseCalendar_ = cal;
172
        return *this;
2✔
173
    }
174

175
    MakeSwaption& MakeSwaption::withUnderlyingType(const Swap::Type type) {
×
176
        underlyingType_ = type;
×
177
        return *this;
×
178
    }
179

180
    MakeSwaption& MakeSwaption::withPricingEngine(
96✔
181
                             const ext::shared_ptr<PricingEngine>& engine) {
182
        engine_ = engine;
96✔
183
        return *this;
96✔
184
    }
185

186
    MakeSwaption& MakeSwaption::withNominal(Real n) {
×
187
        nominal_ = n;
×
188
        return *this;
×
189
    }
190

NEW
191
    MakeSwaption& MakeSwaption::withIndexedCoupons(const std::optional<bool>& b) {
×
192
        useIndexedCoupons_ = b;
×
193
        return *this;
×
194
    }
195

196
    MakeSwaption& MakeSwaption::withAtParCoupons(bool b) {
×
197
        useIndexedCoupons_ = !b;
×
198
        return *this;
×
199
    }
200

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