Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
flexiswap.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 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/flexiswap.hpp
20 \brief Flexi-Swap instrument with global notional bounds
21*/
22
23#pragma once
24
25#include <ql/cashflow.hpp>
26#include <ql/instruments/swap.hpp>
27#include <ql/instruments/vanillaswap.hpp>
28#include <ql/position.hpp>
29#include <ql/pricingengine.hpp>
30
31namespace QuantExt {
32using QuantLib::BusinessDayConvention;
33using QuantLib::Date;
34using QuantLib::DayCounter;
35using QuantLib::IborIndex;
36using QuantLib::Leg;
37using QuantLib::Real;
38using QuantLib::Schedule;
39using QuantLib::Size;
40using QuantLib::Time;
41using QuantLib::VanillaSwap;
42
43//! Flexi-Swap with global notional bounds
44/*! The given non-standard swap defines the upper bound for the notionals, which must be non-increasing and consistent
45 across the legs. Furthermore it is assumed that that floating leg's frequency divides the fixed leg's frequency. The
46 notional in the Flexi-Swap can be adjusted on each fixing date corresponding to a whole fixed leg period to any
47 value between the given lower bound and the original amount. The vector of lower bounds must therefore have
48 the same size as the fixed leg vector in the non-standard swap. For periods with a fixing date on or before the
49 evaluation date, is is assumed that the non-standard swap's notional is the relevant one, i.e. the lower bound is
50 ignored for such periods.
51
52 notionalCanBeDecreased marks fixed rate periods in which the notional can actually be decreased; defaults
53 to true,true,...,true if not given, i.e. the notional can be decreased in each
54 period.
55*/
56
57class FlexiSwap : public QuantLib::Swap {
58public:
59 class arguments;
60 class results;
61 class engine;
62 FlexiSwap(const VanillaSwap::Type type, const std::vector<Real>& fixedNominal,
63 const std::vector<Real>& floatingNominal, const Schedule& fixedSchedule,
64 const std::vector<Real>& fixedRate, const DayCounter& fixedDayCount, const Schedule& floatingSchedule,
65 const QuantLib::ext::shared_ptr<IborIndex>& iborIndex, const std::vector<Real>& gearing,
66 const std::vector<Real>& spread, const std::vector<Real>& cappedRate,
67 const std::vector<Real>& flooredRate, const DayCounter& floatingDayCount,
68 const std::vector<Real>& lowerNotionalBound, const QuantLib::Position::Type optionPosition,
69 const std::vector<bool>& notionalCanBeDecreased = std::vector<bool>(),
70 boost::optional<BusinessDayConvention> paymentConvention = boost::none);
71
72 //! \name Inspectors
73 //@{
74 VanillaSwap::Type type() const { return type_; }
75 const std::vector<Real>& fixedNominal() const { return fixedNominal_; }
76 const std::vector<Real>& floatingNominal() const { return floatingNominal_; }
77
78 const Schedule& fixedSchedule() const { return fixedSchedule_; }
79 const std::vector<Real>& fixedRate() const { return fixedRate_; }
80 const DayCounter& fixedDayCount() const { return fixedDayCount_; }
81
82 const Schedule& floatingSchedule() const { return floatingSchedule_; }
83 const QuantLib::ext::shared_ptr<IborIndex>& iborIndex() const { return iborIndex_; }
84 const std::vector<Real>& gearing() const { return gearing_; }
85 const std::vector<Real>& spread() const { return spread_; }
86 const std::vector<Real>& cappedRate() const { return cappedRate_; }
87 const std::vector<Real>& flooredRate() const { return flooredRate_; }
88 const DayCounter& floatingDayCount() const { return floatingDayCount_; }
89
90 const std::vector<Real>& lowerNotionalBound() const { return lowerNotionalBound_; }
91 const QuantLib::Position::Type optionPosition() const { return optionPosition_; }
92 const std::vector<bool>& notionalCanBeDecreased() const { return notionalCanBeDecreased_; }
93
94 BusinessDayConvention paymentConvention() const { return paymentConvention_; }
95
96 const Leg& fixedLeg() const { return legs_[0]; }
97 const Leg& floatingLeg() const { return legs_[1]; }
98 //@}
99
100 Real underlyingValue() const;
101
102private:
103 const VanillaSwap::Type type_;
104 const std::vector<Real> fixedNominal_, floatingNominal_;
105 const Schedule fixedSchedule_;
106 const std::vector<Real> fixedRate_;
107 const DayCounter fixedDayCount_;
108 const Schedule floatingSchedule_;
109 const QuantLib::ext::shared_ptr<IborIndex> iborIndex_;
110 const std::vector<Real> gearing_;
111 const std::vector<Real> spread_;
112 const std::vector<Real> cappedRate_;
113 const std::vector<Real> flooredRate_;
114 const DayCounter floatingDayCount_;
115 const std::vector<Real> lowerNotionalBound_;
116 const QuantLib::Position::Type optionPosition_;
117 const std::vector<bool> notionalCanBeDecreased_;
118 BusinessDayConvention paymentConvention_;
119
121 void setupExpired() const override;
122 void fetchResults(const QuantLib::PricingEngine::results*) const override;
123
124 mutable Real underlyingValue_; // result
125};
126
127//! %Arguments for Flexi-Swap
129public:
130 arguments() : type(VanillaSwap::Receiver) {}
131 VanillaSwap::Type type;
132 std::vector<Real> fixedNominal, floatingNominal;
133
134 std::vector<Date> fixedResetDates;
135 std::vector<Date> fixedPayDates;
136 std::vector<Time> floatingAccrualTimes;
137 std::vector<Date> floatingResetDates;
138 std::vector<Date> floatingFixingDates;
139 std::vector<Date> floatingPayDates;
140
141 std::vector<Real> fixedCoupons;
142 std::vector<Real> fixedRate;
143 std::vector<Real> floatingGearings;
144 std::vector<Real> floatingSpreads;
145 std::vector<Real> cappedRate;
146 std::vector<Real> flooredRate;
147 std::vector<Real> floatingCoupons;
148
149 QuantLib::ext::shared_ptr<IborIndex> iborIndex;
150
151 std::vector<Real> lowerNotionalBound;
152 QuantLib::Position::Type optionPosition;
153 std::vector<bool> notionalCanBeDecreased;
154
155 void validate() const override;
156};
157
158//! %Results for Flexi-Swap
160public:
162 void reset() override;
163};
164
165//! Base class for Flexi-Swap engines
166class FlexiSwap::engine : public QuantLib::GenericEngine<FlexiSwap::arguments, FlexiSwap::results> {};
167
168} // namespace QuantExt
Arguments for Flexi-Swap
Definition: flexiswap.hpp:128
std::vector< Real > cappedRate
Definition: flexiswap.hpp:145
std::vector< Date > floatingResetDates
Definition: flexiswap.hpp:137
QuantLib::ext::shared_ptr< IborIndex > iborIndex
Definition: flexiswap.hpp:149
std::vector< Real > floatingGearings
Definition: flexiswap.hpp:143
std::vector< Real > floatingSpreads
Definition: flexiswap.hpp:144
std::vector< Date > floatingFixingDates
Definition: flexiswap.hpp:138
std::vector< Real > flooredRate
Definition: flexiswap.hpp:146
std::vector< Date > fixedPayDates
Definition: flexiswap.hpp:135
std::vector< Real > fixedNominal
Definition: flexiswap.hpp:132
std::vector< Date > fixedResetDates
Definition: flexiswap.hpp:134
std::vector< Real > floatingNominal
Definition: flexiswap.hpp:132
QuantLib::Position::Type optionPosition
Definition: flexiswap.hpp:152
void validate() const override
Definition: flexiswap.cpp:219
std::vector< Real > floatingCoupons
Definition: flexiswap.hpp:147
std::vector< bool > notionalCanBeDecreased
Definition: flexiswap.hpp:153
std::vector< Real > lowerNotionalBound
Definition: flexiswap.hpp:151
std::vector< Real > fixedRate
Definition: flexiswap.hpp:142
std::vector< Time > floatingAccrualTimes
Definition: flexiswap.hpp:136
std::vector< Real > fixedCoupons
Definition: flexiswap.hpp:141
std::vector< Date > floatingPayDates
Definition: flexiswap.hpp:139
Base class for Flexi-Swap engines.
Definition: flexiswap.hpp:166
Results for Flexi-Swap
Definition: flexiswap.hpp:159
Flexi-Swap with global notional bounds.
Definition: flexiswap.hpp:57
void fetchResults(const QuantLib::PricingEngine::results *) const override
Definition: flexiswap.cpp:206
const std::vector< bool > & notionalCanBeDecreased() const
Definition: flexiswap.hpp:92
const std::vector< Real > & fixedNominal() const
Definition: flexiswap.hpp:75
const std::vector< Real > fixedRate_
Definition: flexiswap.hpp:106
const std::vector< Real > & flooredRate() const
Definition: flexiswap.hpp:87
const DayCounter & fixedDayCount() const
Definition: flexiswap.hpp:80
const std::vector< Real > & gearing() const
Definition: flexiswap.hpp:84
BusinessDayConvention paymentConvention() const
Definition: flexiswap.hpp:94
const Schedule & fixedSchedule() const
Definition: flexiswap.hpp:78
const Schedule fixedSchedule_
Definition: flexiswap.hpp:105
const std::vector< Real > lowerNotionalBound_
Definition: flexiswap.hpp:115
const Leg & floatingLeg() const
Definition: flexiswap.hpp:97
Real underlyingValue() const
Definition: flexiswap.cpp:195
const std::vector< Real > & lowerNotionalBound() const
Definition: flexiswap.hpp:90
const std::vector< Real > cappedRate_
Definition: flexiswap.hpp:112
const std::vector< Real > fixedNominal_
Definition: flexiswap.hpp:104
const Schedule & floatingSchedule() const
Definition: flexiswap.hpp:82
VanillaSwap::Type type() const
Definition: flexiswap.hpp:74
const QuantLib::ext::shared_ptr< IborIndex > & iborIndex() const
Definition: flexiswap.hpp:83
const std::vector< Real > & fixedRate() const
Definition: flexiswap.hpp:79
const QuantLib::Position::Type optionPosition_
Definition: flexiswap.hpp:116
const DayCounter fixedDayCount_
Definition: flexiswap.hpp:107
const std::vector< bool > notionalCanBeDecreased_
Definition: flexiswap.hpp:117
const std::vector< Real > flooredRate_
Definition: flexiswap.hpp:113
const Schedule floatingSchedule_
Definition: flexiswap.hpp:108
const std::vector< Real > & spread() const
Definition: flexiswap.hpp:85
const DayCounter & floatingDayCount() const
Definition: flexiswap.hpp:88
BusinessDayConvention paymentConvention_
Definition: flexiswap.hpp:118
const VanillaSwap::Type type_
Definition: flexiswap.hpp:103
const Leg & fixedLeg() const
Definition: flexiswap.hpp:96
void setupExpired() const override
Definition: flexiswap.cpp:201
const std::vector< Real > gearing_
Definition: flexiswap.hpp:110
void setupArguments(QuantLib::PricingEngine::arguments *) const override
Definition: flexiswap.cpp:134
const DayCounter floatingDayCount_
Definition: flexiswap.hpp:114
const std::vector< Real > & cappedRate() const
Definition: flexiswap.hpp:86
const std::vector< Real > floatingNominal_
Definition: flexiswap.hpp:104
const QuantLib::Position::Type optionPosition() const
Definition: flexiswap.hpp:91
const QuantLib::ext::shared_ptr< IborIndex > iborIndex_
Definition: flexiswap.hpp:109
const std::vector< Real > spread_
Definition: flexiswap.hpp:111
const std::vector< Real > & floatingNominal() const
Definition: flexiswap.hpp:76