Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
currencyswap.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 qle/instruments/currencyswap.hpp
20 \brief Interest rate swap with extended interface
21
22 \ingroup instruments
23*/
24
25#ifndef quantext_currencyswap_hpp
26#define quantext_currencyswap_hpp
27
28#include <ql/cashflows/cashflows.hpp>
29#include <ql/currencies/europe.hpp>
30#include <ql/currency.hpp>
31#include <ql/indexes/iborindex.hpp>
32#include <ql/instruments/swap.hpp>
33#include <ql/money.hpp>
34#include <ql/time/daycounter.hpp>
35#include <ql/time/schedule.hpp>
36
37namespace QuantExt {
38using namespace QuantLib;
39
40//! %Currency Interest Rate Swap
41/*!
42 This instrument generalizes the QuantLib Swap instrument in that
43 it allows multiple legs with different currencies (one per leg)
44
45 \ingroup instruments
46*/
47class CurrencySwap : public Instrument {
48public:
49 class arguments;
50 class results;
51 class engine;
52 //! \name Constructors
53 //@{
54 /*! Multi leg constructor. */
55 CurrencySwap(const std::vector<Leg>& legs, const std::vector<bool>& payer, const std::vector<Currency>& currency,
56 const bool isPhysicallySettled = true, const bool isResettable = false);
57 //@}
58 //! \name LazyObject interface
59 //@{
60 void alwaysForwardNotifications() override;
61 //@}
62 //! \name Observable interface
63 //@{
64 void deepUpdate() override;
65 //@}
66 //! \name Instrument interface
67 //@{
68 bool isExpired() const override;
69 void setupArguments(PricingEngine::arguments*) const override;
70 void fetchResults(const PricingEngine::results*) const override;
71 //@}
72 //! \name Additional interface
73 //@{
74 Date startDate() const;
75 Date maturityDate() const;
76 Real legBPS(Size j) const {
77 QL_REQUIRE(j < legs_.size(), "leg# " << j << " doesn't exist!");
78 calculate();
79 return legBPS_[j];
80 }
81 Real legNPV(Size j) const {
82 QL_REQUIRE(j < legs_.size(), "leg #" << j << " doesn't exist!");
83 calculate();
84 return legNPV_[j];
85 }
86 Real inCcyLegBPS(Size j) const {
87 QL_REQUIRE(j < legs_.size(), "leg# " << j << " doesn't exist!");
88 calculate();
89 return inCcyLegBPS_[j];
90 }
91 Real inCcyLegNPV(Size j) const {
92 QL_REQUIRE(j < legs_.size(), "leg #" << j << " doesn't exist!");
93 calculate();
94 return inCcyLegNPV_[j];
95 }
96 DiscountFactor startDiscounts(Size j) const {
97 QL_REQUIRE(j < legs_.size(), "leg #" << j << " doesn't exist!");
98 calculate();
99 return startDiscounts_[j];
100 }
101 DiscountFactor endDiscounts(Size j) const {
102 QL_REQUIRE(j < legs_.size(), "leg #" << j << " doesn't exist!");
103 calculate();
104 return endDiscounts_[j];
105 }
106 DiscountFactor npvDateDiscount() const {
107 calculate();
108 return npvDateDiscount_;
109 }
110 const Leg& leg(Size j) const {
111 QL_REQUIRE(j < legs_.size(), "leg #" << j << " doesn't exist!");
112 return legs_[j];
113 }
114 const Currency& legCurrency(Size j) const {
115 QL_REQUIRE(j < legs_.size(), "leg #" << j << " doesn't exist!");
116 return currency_[j];
117 }
118 std::vector<Leg> legs() { return legs_; }
119 std::vector<Currency> currencies() { return currency_; }
120 //@}
121protected:
122 //! \name Constructors
123 //@{
124 /*! This constructor can be used by derived classes that will
125 build their legs themselves.
126 */
127 CurrencySwap(Size legs);
128 //! \name Instrument interface
129 //@{
130 void setupExpired() const override;
131 //@}
132 // data members
133 std::vector<Leg> legs_;
134 std::vector<Real> payer_;
135 std::vector<Currency> currency_;
137 mutable std::vector<Real> legNPV_, inCcyLegNPV_;
138 mutable std::vector<Real> legBPS_, inCcyLegBPS_;
139 mutable std::vector<DiscountFactor> startDiscounts_, endDiscounts_;
140 mutable DiscountFactor npvDateDiscount_;
141};
142
143//! \ingroup instruments
145public:
146 std::vector<Leg> legs;
147 std::vector<Real> payer;
148 std::vector<Currency> currency;
151 void validate() const override;
152};
153
154//! \ingroup instruments
156public:
157 std::vector<Real> legNPV, inCcyLegNPV;
158 std::vector<Real> legBPS, inCcyLegBPS;
159 std::vector<DiscountFactor> startDiscounts, endDiscounts;
160 DiscountFactor npvDateDiscount;
161 void reset() override;
162};
163
164//! \ingroup instruments
165class CurrencySwap::engine : public GenericEngine<CurrencySwap::arguments, CurrencySwap::results> {};
166
167//! Vanilla cross currency interest rate swap
168/*! Specialised CurrencySwap: Two currencies, fixed vs. floating,
169 constant notionals, rate and spread.
170
171 \ingroup instruments{
172*/
174public:
175 VanillaCrossCurrencySwap(bool payFixed, Currency fixedCcy, Real fixedNominal, const Schedule& fixedSchedule,
176 Rate fixedRate, const DayCounter& fixedDayCount, Currency floatCcy, Real floatNominal,
177 const Schedule& floatSchedule, const QuantLib::ext::shared_ptr<IborIndex>& iborIndex,
178 Rate floatSpread, boost::optional<BusinessDayConvention> paymentConvention = boost::none,
179 const bool isPhysicallySettled = true, const bool isResettable = false);
180};
181
182//! Cross currency swap
183/*! Specialised CurrencySwap: Two currencies, variable notionals,
184 rates and spreads; flavours fix/float, fix/fix, float/float
185
186 \ingroup instruments
187*/
189public:
190 // fixed/floating
191 CrossCurrencySwap(bool payFixed, Currency fixedCcy, std::vector<Real> fixedNominals, const Schedule& fixedSchedule,
192 std::vector<Rate> fixedRates, const DayCounter& fixedDayCount, Currency floatCcy,
193 std::vector<Real> floatNominals, const Schedule& floatSchedule,
194 const QuantLib::ext::shared_ptr<IborIndex>& iborIndex, std::vector<Rate> floatSpreads,
195 boost::optional<BusinessDayConvention> paymentConvention = boost::none,
196 const bool isPhysicallySettled = true, const bool isResettable = false);
197
198 // fixed/fixed
199 CrossCurrencySwap(bool pay1, Currency ccy1, std::vector<Real> nominals1, const Schedule& schedule1,
200 std::vector<Rate> fixedRates1, const DayCounter& fixedDayCount1, Currency ccy2,
201 std::vector<Real> nominals2, const Schedule& schedule2, std::vector<Rate> fixedRates2,
202 const DayCounter& fixedDayCount2,
203 boost::optional<BusinessDayConvention> paymentConvention = boost::none,
204 const bool isPhysicallySettled = true, const bool isResettable = false);
205
206 // floating/floating
207 CrossCurrencySwap(bool pay1, Currency ccy1, std::vector<Real> nominals1, const Schedule& schedule1,
208 const QuantLib::ext::shared_ptr<IborIndex>& iborIndex1, std::vector<Rate> spreads1, Currency ccy2,
209 std::vector<Real> nominals2, const Schedule& schedule2,
210 const QuantLib::ext::shared_ptr<IborIndex>& iborIndex2, std::vector<Rate> spreads2,
211 boost::optional<BusinessDayConvention> paymentConvention = boost::none,
212 const bool isPhysicallySettled = true, const bool isResettable = false);
213};
214} // namespace QuantExt
215
216#endif
Cross currency swap.
CrossCurrencySwap(bool pay1, Currency ccy1, std::vector< Real > nominals1, const Schedule &schedule1, std::vector< Rate > fixedRates1, const DayCounter &fixedDayCount1, Currency ccy2, std::vector< Real > nominals2, const Schedule &schedule2, std::vector< Rate > fixedRates2, const DayCounter &fixedDayCount2, boost::optional< BusinessDayConvention > paymentConvention=boost::none, const bool isPhysicallySettled=true, const bool isResettable=false)
std::vector< Currency > currency
void validate() const override
std::vector< DiscountFactor > endDiscounts
std::vector< DiscountFactor > startDiscounts
std::vector< Real > inCcyLegNPV
std::vector< Real > inCcyLegBPS
Currency Interest Rate Swap
DiscountFactor endDiscounts(Size j) const
DiscountFactor npvDateDiscount_
std::vector< Real > inCcyLegNPV_
std::vector< Currency > currencies()
std::vector< Currency > currency_
void setupArguments(PricingEngine::arguments *) const override
bool isExpired() const override
Real inCcyLegNPV(Size j) const
Real legBPS(Size j) const
void deepUpdate() override
std::vector< Leg > legs_
std::vector< Real > inCcyLegBPS_
std::vector< Real > legNPV_
const Leg & leg(Size j) const
DiscountFactor npvDateDiscount() const
std::vector< Real > legBPS_
std::vector< DiscountFactor > startDiscounts_
Real legNPV(Size j) const
Real inCcyLegBPS(Size j) const
std::vector< Leg > legs()
void setupExpired() const override
DiscountFactor startDiscounts(Size j) const
void fetchResults(const PricingEngine::results *) const override
std::vector< DiscountFactor > endDiscounts_
void alwaysForwardNotifications() override
std::vector< Real > payer_
const Currency & legCurrency(Size j) const
Vanilla cross currency interest rate swap.