Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
tenorbasisswap.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file tenorbasisswap.hpp
20 \brief Single currency tenor basis swap instrument
21
22 \ingroup instruments
23*/
24
25#ifndef quantext_tenor_basis_swap_hpp
26#define quantext_tenor_basis_swap_hpp
27
28#include <ql/indexes/iborindex.hpp>
29#include <ql/instruments/swap.hpp>
30
32
33namespace QuantExt {
34using namespace QuantLib;
35//! Single currency tenor basis swap
36/*! \ingroup instruments
37 */
38class TenorBasisSwap : public Swap {
39public:
40 class results;
41 class engine;
42 //! \name Constructors
43 //@{
44 //! Constructor with conventions deduced from the indices
45 TenorBasisSwap(const Date& effectiveDate, Real nominal, const Period& swapTenor,
46 const QuantLib::ext::shared_ptr<IborIndex>& payIndex, Spread paySpread, const Period& payFrequency,
47 const QuantLib::ext::shared_ptr<IborIndex>& recIndex, Spread recSpread, const Period& recFrequency,
48 DateGeneration::Rule rule = DateGeneration::Backward, bool includeSpread = false,
49 bool spreadOnRec = true,
51 const bool telescopicValueDates = false);
52 //! Constructor using Schedules with a full interface
53 TenorBasisSwap(Real nominal, const Schedule& paySchedule, const QuantLib::ext::shared_ptr<IborIndex>& payIndex,
54 Spread paySpread, const Schedule& recSchedule, const QuantLib::ext::shared_ptr<IborIndex>& recIndex,
55 Spread recSpread, bool includeSpread = false, bool spreadOnRec = true,
57 const bool telescopicValueDates = false);
58 TenorBasisSwap(const std::vector<Real>& nominals, const Schedule& paySchedule, const QuantLib::ext::shared_ptr<IborIndex>& payIndex,
59 Spread paySpread, const Schedule& recSchedule, const QuantLib::ext::shared_ptr<IborIndex>& recIndex,
60 Spread recSpread, bool includeSpread = false, bool spreadOnRec = true,
62 const bool telescopicValueDates = false);
63
64 //@}
65 //! \name Inspectors
66 //@{
67 Real nominal() const;
68 const std::vector<Real>& nominals() const { return nominals_; }
69
70 const Schedule& paySchedule() const;
71 const QuantLib::ext::shared_ptr<IborIndex>& payIndex() const;
72 Spread paySpread() const;
73 const Leg& payLeg() const;
74
75 const Schedule& recSchedule() const;
76 const QuantLib::ext::shared_ptr<IborIndex>& recIndex() const;
77 Spread recSpread() const;
78 const Leg& recLeg() const;
79 const Period& recFrequency() const;
80 const Period& payFrequency() const;
81
82 bool includeSpread() const;
83 bool spreadOnRec() const { return spreadOnRec_; }
85 //@}
86 //! \name Results
87 //@{
88 Real payLegBPS() const;
89 Real payLegNPV() const;
90 Rate fairPayLegSpread() const;
91
92 Real recLegBPS() const;
93 Real recLegNPV() const;
94 Spread fairRecLegSpread() const;
95 //@}
96 void fetchResults(const PricingEngine::results*) const override;
97
98private:
99 void initializeLegs();
100 void setupExpired() const override;
101
102 std::vector<Real> nominals_;
103
104 Schedule paySchedule_;
105 QuantLib::ext::shared_ptr<IborIndex> payIndex_;
108
109 Schedule recSchedule_;
110 QuantLib::ext::shared_ptr<IborIndex> recIndex_;
113
118
120
121 mutable std::vector<Spread> fairSpread_;
122
125};
126
127//! %Results from tenor basis swap calculation
128//! \ingroup instruments
130public:
131 std::vector<Spread> fairSpread;
132 void reset() override;
133};
134
135//! \ingroup instruments
136class TenorBasisSwap::engine : public GenericEngine<Swap::arguments, TenorBasisSwap::results> {};
137
138// Inline definitions
139inline Real TenorBasisSwap::nominal() const {
140 QL_REQUIRE(nominals_.size() == 1, "varying nominals");
141 return nominals_[0];
142}
143inline const Schedule& TenorBasisSwap::paySchedule() const { return paySchedule_; }
144
145inline const QuantLib::ext::shared_ptr<IborIndex>& TenorBasisSwap::payIndex() const { return payIndex_; }
146
147inline Spread TenorBasisSwap::paySpread() const { return paySpread_; }
148
149inline const Leg& TenorBasisSwap::payLeg() const { return legs_[idxPay_]; }
150
151inline const Schedule& TenorBasisSwap::recSchedule() const { return recSchedule_; }
152
153inline const QuantLib::ext::shared_ptr<IborIndex>& TenorBasisSwap::recIndex() const { return recIndex_; }
154
155inline Spread TenorBasisSwap::recSpread() const { return recSpread_; }
156
157inline const Period& TenorBasisSwap::recFrequency() const { return recFrequency_; }
158
159inline const Period& TenorBasisSwap::payFrequency() const { return payFrequency_; }
160
161inline bool TenorBasisSwap::includeSpread() const { return includeSpread_; }
162
164
165inline const Leg& TenorBasisSwap::recLeg() const { return legs_[idxRec_]; }
166} // namespace QuantExt
167
168#endif
Single currency tenor basis swap.
QuantLib::ext::shared_ptr< IborIndex > payIndex_
const QuantLib::ext::shared_ptr< IborIndex > & recIndex() const
QuantLib::ext::shared_ptr< IborIndex > recIndex_
const Leg & payLeg() const
const Period & payFrequency() const
const Period & recFrequency() const
const Schedule & recSchedule() const
std::vector< Spread > fairSpread_
Spread fairRecLegSpread() const
QuantExt::SubPeriodsCoupon1::Type type() const
const Schedule & paySchedule() const
const std::vector< Real > & nominals() const
const Leg & recLeg() const
const QuantLib::ext::shared_ptr< IborIndex > & payIndex() const
void setupExpired() const override
void fetchResults(const PricingEngine::results *) const override
QuantExt::SubPeriodsCoupon1::Type type_
std::vector< Real > nominals_
Coupon with a number of sub-periods.