Coverage Report

Created: 2026-06-23 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/instruments/constnotionalcrosscurrencybasisswap.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2016 Quaternion Risk Management Ltd
5
 Copyright (C) 2025 Paolo D'Elia
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
/*! \file constnotionalcrosscurrencybasisswap.hpp
22
    \brief Cross-currency basis swap
23
*/
24
25
#ifndef quantlib_cross_currency_basis_swap_hpp
26
#define quantlib_cross_currency_basis_swap_hpp
27
28
#include <ql/indexes/iborindex.hpp>
29
#include <ql/cashflows/rateaveraging.hpp>
30
#include <ql/time/schedule.hpp>
31
#include <ql/instruments/constnotionalcrosscurrencyswap.hpp>
32
33
namespace QuantLib {
34
35
//! Cross-currency basis swap
36
/*! The first leg holds the pay currency cashflows and second leg holds
37
    the receive currency cashflows.
38
39
    \ingroup instruments
40
*/
41
class ConstNotionalCrossCurrencyBasisSwap : public ConstNotionalCrossCurrencySwap {
42
  public:
43
    class arguments;
44
    class results;
45
46
    //! \name Constructors
47
    //@{
48
    /*!
49
        \brief Constructs a cross-currency basis swap.
50
51
        First leg holds the pay currency cashflows and the second leg holds the receive currency cashflows.
52
        
53
        \param payNominal         Notional amount for the pay leg.
54
        \param payCurrency        Currency of the pay leg.
55
        \param paySchedule        Payment schedule for the pay leg.
56
        \param payIndex           Floating rate index for the pay leg.
57
        \param paySpread          Spread over the floating rate for the pay leg.
58
        \param payGearing         Gearing factor for the pay leg.
59
        \param recNominal         Notional amount for the receive leg.
60
        \param recCurrency        Currency of the receive leg.
61
        \param recSchedule        Payment schedule for the receive leg.
62
        \param recIndex           Floating rate index for the receive leg.
63
        \param recSpread          Spread over the floating rate for the receive leg.
64
        \param recGearing         Gearing factor for the receive leg.
65
        \param payPaymentLag      Payment lag in days for the pay leg if overnight (default: 0).
66
        \param recPaymentLag      Payment lag in days for the receive leg if overnight (default: 0).
67
        \param payCompoundSpread  Whether to compound the spread daily for the pay leg if overnight (default: false).
68
        \param payLookbackDays    Lookback days for the pay leg if overnight (default: null).
69
        \param payObservationShift  Whether the observation shift is applied for the pay leg if overnight (default: false).
70
        \param payLockoutDays     Lockout period (in business days) for the pay leg if overnight (default: 0).
71
        \param payAveragingMethod   Averaging method for the pay leg if overnight (default: compounding).
72
        \param recCompoundSpread  Whether to compound the spread daily for the receive leg if overnight (default: false).
73
        \param recLookbackDays    Lookback days for the receive leg if overnight (default: null).
74
        \param recObservationShift  Whether the observation shift is applied for the receive leg if overnight (default: false).
75
        \param recLockoutDays     Lockout period (in business days) for the receive leg if overnight (default: 0).
76
        \param recAveragingMethod   Averaging method for the receive leg if overnight (default: compounding).
77
        \param telescopicValueDates Flag indicating whether telescopic value dates are used if overnight (default: false).
78
    */
79
    ConstNotionalCrossCurrencyBasisSwap(
80
        Real payNominal, Currency  payCurrency, Schedule  paySchedule,
81
        const ext::shared_ptr<IborIndex>& payIndex, Spread paySpread, Real payGearing, Real recNominal,
82
        Currency  recCurrency, Schedule  recSchedule, const ext::shared_ptr<IborIndex>& recIndex,
83
        Spread recSpread, Real recGearing, Integer payPaymentLag = 0, Integer recPaymentLag = 0,
84
        bool payCompoundSpread = false, Natural payLookbackDays = Null<Natural>(), bool payObservationShift = false,
85
        Natural payLockoutDays = 0, RateAveraging::Type payAveragingMethod = RateAveraging::Compound,
86
        bool recCompoundSpread = false, Natural recLookbackDays = Null<Natural>(), bool recObservationShift = false,
87
        Natural recLockoutDays = 0, RateAveraging::Type recAveragingMethod = RateAveraging::Compound,
88
        bool telescopicValueDates = false);
89
    //@}
90
    //! \name Instrument interface
91
    //@{
92
    void setupArguments(PricingEngine::arguments* args) const override;
93
    void fetchResults(const PricingEngine::results*) const override;
94
    //@}
95
    //! \name Inspectors
96
    //@{
97
0
    Real payNominal() const { return payNominal_; }
98
0
    const Currency& payCurrency() const { return payCurrency_; }
99
0
    const Schedule& paySchedule() const { return paySchedule_; }
100
0
    const ext::shared_ptr<IborIndex>& payIndex() const { return payIndex_; }
101
0
    Spread paySpread() const { return paySpread_; }
102
0
    Real payGearing() const { return payGearing_; }
103
104
0
    Real recNominal() const { return recNominal_; }
105
0
    const Currency& recCurrency() const { return recCurrency_; }
106
0
    const Schedule& recSchedule() const { return recSchedule_; }
107
0
    const ext::shared_ptr<IborIndex>& recIndex() const { return recIndex_; }
108
0
    Spread recSpread() const { return recSpread_; }
109
0
    Real recGearing() const { return recGearing_; }
110
    //@}
111
112
    //! \name Additional interface
113
    //@{
114
0
    Spread fairPaySpread() const {
115
0
        calculate();
116
0
        QL_REQUIRE(fairPaySpread_ != Null<Real>(), "Fair pay spread is not available");
117
0
        return fairPaySpread_;
118
0
    }
119
0
    Spread fairRecSpread() const {
120
0
        calculate();
121
0
        QL_REQUIRE(fairRecSpread_ != Null<Real>(), "Fair pay spread is not available");
122
0
        return fairRecSpread_;
123
0
    }
124
    //@}
125
126
  protected:
127
    //! \name Instrument interface
128
    //@{
129
    void setupExpired() const override;
130
    //@}
131
132
  private:
133
    void initialize();
134
135
    Real payNominal_;
136
    Currency payCurrency_;
137
    Schedule paySchedule_;
138
    ext::shared_ptr<IborIndex> payIndex_;
139
    Spread paySpread_;
140
    Real payGearing_;
141
142
    Real recNominal_;
143
    Currency recCurrency_;
144
    Schedule recSchedule_;
145
    ext::shared_ptr<IborIndex> recIndex_;
146
    Spread recSpread_;
147
    Real recGearing_;
148
149
    Integer payPaymentLag_;
150
    Integer recPaymentLag_;
151
152
    // OIS only
153
    bool payCompoundSpread_;
154
    Natural payLookbackDays_;
155
    bool payObservationShift_;
156
    Natural payLockoutDays_;
157
    RateAveraging::Type payAveragingMethod_;
158
    bool recCompoundSpread_;
159
    Natural recLookbackDays_;
160
    bool recObservationShift_;
161
    Natural recLockoutDays_;
162
    RateAveraging::Type recAveragingMethod_;
163
    bool telescopicValueDates_;
164
165
    mutable Spread fairPaySpread_;
166
    mutable Spread fairRecSpread_;
167
};
168
169
170
class ConstNotionalCrossCurrencyBasisSwap::arguments : public ConstNotionalCrossCurrencySwap::arguments {
171
  public:
172
    Spread paySpread;
173
    Spread recSpread;
174
    void validate() const override;
175
};
176
177
178
class ConstNotionalCrossCurrencyBasisSwap::results : public ConstNotionalCrossCurrencySwap::results {
179
  public:
180
    Spread fairPaySpread;
181
    Spread fairRecSpread;
182
    void reset() override;
183
};
184
185
}
186
187
#endif