QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
floatfloatswap.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2013 Peter Caspers
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20/*! \file floatfloatswap.hpp
21 \brief swap exchanging capped floored Libor or CMS coupons with quite
22 general specification. If no payment convention is given, the
23 respective leg schedule convention is used. The interest rate
24 indices should be linked to valid forwarding and in case of
25 swap indices discounting curves
26*/
27
28#ifndef quantlib_floatfloat_swap_hpp
29#define quantlib_floatfloat_swap_hpp
30
34#include <ql/time/schedule.hpp>
35#include <ql/optional.hpp>
36
37namespace QuantLib {
38
39 class InterestRateIndex;
40
41 //! float float swap
42
43 class FloatFloatSwap : public Swap {
44 public:
45 class arguments;
46 class results;
47 class engine;
53 ext::shared_ptr<InterestRateIndex> index1,
56 ext::shared_ptr<InterestRateIndex> index2,
58 bool intermediateCapitalExchange = false,
59 bool finalCapitalExchange = false,
60 Real gearing1 = 1.0,
61 Real spread1 = 0.0,
64 Real gearing2 = 1.0,
65 Real spread2 = 0.0,
68 const ext::optional<BusinessDayConvention>& paymentConvention1 = ext::nullopt,
69 const ext::optional<BusinessDayConvention>& paymentConvention2 = ext::nullopt);
70
73 std::vector<Real> nominal1,
74 std::vector<Real> nominal2,
76 ext::shared_ptr<InterestRateIndex> index1,
79 ext::shared_ptr<InterestRateIndex> index2,
81 bool intermediateCapitalExchange = false,
82 bool finalCapitalExchange = false,
83 std::vector<Real> gearing1 = std::vector<Real>(),
84 std::vector<Real> spread1 = std::vector<Real>(),
85 std::vector<Real> cappedRate1 = std::vector<Real>(),
86 std::vector<Real> flooredRate1 = std::vector<Real>(),
87 std::vector<Real> gearing2 = std::vector<Real>(),
88 std::vector<Real> spread2 = std::vector<Real>(),
89 std::vector<Real> cappedRate2 = std::vector<Real>(),
90 std::vector<Real> flooredRate2 = std::vector<Real>(),
91 const ext::optional<BusinessDayConvention>& paymentConvention1 = ext::nullopt,
92 const ext::optional<BusinessDayConvention>& paymentConvention2 = ext::nullopt);
93
94 //! \name Inspectors
95 //@{
96 Swap::Type type() const;
97 const std::vector<Real> &nominal1() const;
98 const std::vector<Real> &nominal2() const;
99
100 const Schedule &schedule1() const;
101 const Schedule &schedule2() const;
102
103 const ext::shared_ptr<InterestRateIndex> &index1() const;
104 const ext::shared_ptr<InterestRateIndex> &index2() const;
105
106 std::vector<Real> spread1() const;
107 std::vector<Real> spread2() const;
108
109 std::vector<Real> gearing1() const;
110 std::vector<Real> gearing2() const;
111
112 std::vector<Rate> cappedRate1() const;
113 std::vector<Rate> flooredRate1() const;
114 std::vector<Rate> cappedRate2() const;
115 std::vector<Rate> flooredRate2() const;
116
117 const DayCounter &dayCount1() const;
118 const DayCounter &dayCount2() const;
119
122
123 const Leg &leg1() const;
124 const Leg &leg2() const;
125 //@}
126
127 //! \name Results
128 //@{
129 //@}
130 // other
131 void setupArguments(PricingEngine::arguments* args) const override;
132 void fetchResults(const PricingEngine::results*) const override;
133
134 private:
135 void init(ext::optional<BusinessDayConvention> paymentConvention1,
136 ext::optional<BusinessDayConvention> paymentConvention2);
137 void setupExpired() const override;
139 std::vector<Real> nominal1_, nominal2_;
141 ext::shared_ptr<InterestRateIndex> index1_, index2_;
142 std::vector<Real> gearing1_, gearing2_, spread1_, spread2_;
149 };
150
151 //! %Arguments for float float swap calculation
153 public:
154 arguments() = default;
156 std::vector<Real> nominal1, nominal2;
157
160
164
165 std::vector<Real> leg1Coupons, leg2Coupons;
167
168 ext::shared_ptr<InterestRateIndex> index1, index2;
169
171
172 void validate() const override;
173 };
174
175 //! %Results from float float swap calculation
177 public:
178 void reset() override;
179 };
180
182 : public GenericEngine<FloatFloatSwap::arguments,
183 FloatFloatSwap::results> {};
184
185 // inline definitions
186
187 inline Swap::Type FloatFloatSwap::type() const { return type_; }
188
189 inline const std::vector<Real> &FloatFloatSwap::nominal1() const {
190 return nominal1_;
191 }
192
193 inline const std::vector<Real> &FloatFloatSwap::nominal2() const {
194 return nominal2_;
195 }
196
197 inline const Schedule &FloatFloatSwap::schedule1() const {
198 return schedule1_;
199 }
200
201 inline const Schedule &FloatFloatSwap::schedule2() const {
202 return schedule2_;
203 }
204
205 inline const ext::shared_ptr<InterestRateIndex> &
207 return index1_;
208 }
209
210 inline const ext::shared_ptr<InterestRateIndex> &
212 return index2_;
213 }
214
215 inline std::vector<Real> FloatFloatSwap::spread1() const { return spread1_; }
216
217 inline std::vector<Real> FloatFloatSwap::spread2() const { return spread2_; }
218
219 inline std::vector<Real> FloatFloatSwap::gearing1() const { return gearing1_; }
220
221 inline std::vector<Real> FloatFloatSwap::gearing2() const { return gearing2_; }
222
223 inline std::vector<Real> FloatFloatSwap::cappedRate1() const { return cappedRate1_; }
224
225 inline std::vector<Real> FloatFloatSwap::cappedRate2() const { return cappedRate2_; }
226
227 inline std::vector<Real> FloatFloatSwap::flooredRate1() const { return flooredRate1_; }
228
229 inline std::vector<Real> FloatFloatSwap::flooredRate2() const { return flooredRate2_; }
230
231 inline const DayCounter &FloatFloatSwap::dayCount1() const {
232 return dayCount1_;
233 }
234
235 inline const DayCounter &FloatFloatSwap::dayCount2() const {
236 return dayCount2_;
237 }
238
240 return paymentConvention1_;
241 }
242
244 return paymentConvention2_;
245 }
246
247 inline const Leg &FloatFloatSwap::leg1() const { return legs_[0]; }
248
249 inline const Leg &FloatFloatSwap::leg2() const { return legs_[1]; }
250}
251
252#endif
day counter class
Definition: daycounter.hpp:44
Arguments for float float swap calculation
ext::shared_ptr< InterestRateIndex > index1
ext::shared_ptr< InterestRateIndex > index2
Results from float float swap calculation
std::vector< Real > cappedRate2_
std::vector< Real > flooredRate2_
std::vector< Real > gearing2_
const DayCounter & dayCount2() const
const ext::shared_ptr< InterestRateIndex > & index1() const
const ext::shared_ptr< InterestRateIndex > & index2() const
std::vector< Real > gearing2() const
const Leg & leg2() const
const Leg & leg1() const
std::vector< Rate > flooredRate2() const
const std::vector< Real > & nominal2() const
std::vector< Real > nominal1_
const Schedule & schedule1() const
std::vector< Real > spread1_
std::vector< Real > cappedRate1_
std::vector< Real > spread2() const
BusinessDayConvention paymentConvention2() const
std::vector< Real > spread2_
const bool intermediateCapitalExchange_
Swap::Type type() const
std::vector< Real > nominal2_
std::vector< Real > gearing1_
std::vector< bool > isRedemptionFlow1_
std::vector< Real > spread1() const
BusinessDayConvention paymentConvention2_
void setupArguments(PricingEngine::arguments *args) const override
const std::vector< Real > & nominal1() const
BusinessDayConvention paymentConvention1_
std::vector< Real > flooredRate1_
const DayCounter & dayCount1() const
std::vector< Rate > flooredRate1() const
const Schedule & schedule2() const
ext::shared_ptr< InterestRateIndex > index1_
void init(ext::optional< BusinessDayConvention > paymentConvention1, ext::optional< BusinessDayConvention > paymentConvention2)
void setupExpired() const override
ext::shared_ptr< InterestRateIndex > index2_
void fetchResults(const PricingEngine::results *) const override
std::vector< Rate > cappedRate1() const
std::vector< Real > gearing1() const
std::vector< Rate > cappedRate2() const
BusinessDayConvention paymentConvention1() const
std::vector< bool > isRedemptionFlow2_
template base class for option pricing engines
template class providing a null value for a given type.
Definition: null.hpp:76
Payment schedule.
Definition: schedule.hpp:40
Interest rate swap.
Definition: swap.hpp:41
std::vector< Leg > legs_
Definition: swap.hpp:133
day counter class
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
const boost::none_t & nullopt
Definition: optional.cpp:27
Definition: any.hpp:35
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78
Maps optional to either the boost or std implementation.
date schedule
Interest rate swap.
Simple fixed-rate vs Libor swap.