QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fixedvsfloatingswap.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) 2000, 2001, 2002, 2003 RiskMap srl
5 Copyright (C) 2003, 2004, 2005, 2006, 2007 StatPro Italia srl
6 Copyright (C) 2006, 2008 Ferdinando Ametrano
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22/*! \file fixedvsfloatingswap.hpp
23 \brief Fixed-rate vs floating-rate swap
24*/
25
26#ifndef quantlib_fixed_vs_floating_swap_hpp
27#define quantlib_fixed_vs_floating_swap_hpp
28
31#include <ql/time/schedule.hpp>
32#include <ql/optional.hpp>
33
34namespace QuantLib {
35
36 class IborIndex;
37
38 //! Fixed vs floating swap
39 /*! \ingroup instruments
40
41 If no payment convention is passed, the convention of the
42 floating-rate schedule is used.
43
44 \warning if <tt>Settings::includeReferenceDateCashFlows()</tt>
45 is set to <tt>true</tt>, payments occurring at the
46 settlement date of the swap might be included in the
47 NPV and therefore affect the fair-rate and
48 fair-spread calculation. This might not be what you
49 want.
50 */
51 class FixedVsFloatingSwap : public Swap {
52 public:
53 class arguments;
54 class results;
55 class engine;
57 std::vector<Real> fixedNominals,
61 std::vector<Real> floatingNominals,
63 ext::shared_ptr<IborIndex> iborIndex,
66 ext::optional<BusinessDayConvention> paymentConvention = ext::nullopt,
67 Integer paymentLag = 0,
68 const Calendar& paymentCalendar = Calendar());
69 //! \name Inspectors
70 //@{
71 Type type() const;
72
73 /*! This throws if the nominal is not constant across coupons. */
74 Real nominal() const;
75 /*! This throws if the nominals are not the same for the two legs. */
76 const std::vector<Real>& nominals() const;
77
78 const std::vector<Real>& fixedNominals() const;
79 const Schedule& fixedSchedule() const;
80 Rate fixedRate() const;
81 const DayCounter& fixedDayCount() const;
82
83 const std::vector<Real>& floatingNominals() const;
84 const Schedule& floatingSchedule() const;
85 const ext::shared_ptr<IborIndex>& iborIndex() const;
86 Spread spread() const;
87 const DayCounter& floatingDayCount() const;
88
90
91 const Leg& fixedLeg() const;
92 const Leg& floatingLeg() const;
93 //@}
94
95 //! \name Results
96 //@{
97 Real fixedLegBPS() const;
98 Real fixedLegNPV() const;
99 Rate fairRate() const;
100
101 Real floatingLegBPS() const;
102 Real floatingLegNPV() const;
103 Spread fairSpread() const;
104 //@}
105 // other
106 void setupArguments(PricingEngine::arguments* args) const override;
107 void fetchResults(const PricingEngine::results*) const override;
108
109 private:
110 void setupExpired() const override;
111 virtual void setupFloatingArguments(arguments* args) const = 0;
113 std::vector<Real> fixedNominals_;
117 std::vector<Real> floatingNominals_;
119 ext::shared_ptr<IborIndex> iborIndex_;
123 // results
126
128 };
129
130
131 //! %Arguments for simple swap calculation
133 public:
137
138 std::vector<Real> fixedNominals;
139 std::vector<Date> fixedResetDates;
140 std::vector<Date> fixedPayDates;
141 std::vector<Real> floatingNominals;
142 std::vector<Time> floatingAccrualTimes;
143 std::vector<Date> floatingResetDates;
144 std::vector<Date> floatingFixingDates;
145 std::vector<Date> floatingPayDates;
146
147 std::vector<Real> fixedCoupons;
148 std::vector<Spread> floatingSpreads;
149 std::vector<Real> floatingCoupons;
150 void validate() const override;
151 };
152
153 //! %Results from simple swap calculation
155 public:
158 void reset() override;
159 };
160
161 class FixedVsFloatingSwap::engine : public GenericEngine<FixedVsFloatingSwap::arguments,
162 FixedVsFloatingSwap::results> {};
163
164
165 // inline definitions
166
168 return type_;
169 }
170
172 QL_REQUIRE(constantNominals_, "nominal is not constant");
173 return fixedNominals_[0];
174 }
175
176 inline const std::vector<Real>& FixedVsFloatingSwap::nominals() const {
177 QL_REQUIRE(sameNominals_, "different nominals on fixed and floating leg");
178 return fixedNominals_;
179 }
180
181 inline const std::vector<Real>& FixedVsFloatingSwap::fixedNominals() const {
182 return fixedNominals_;
183 }
184
186 return fixedSchedule_;
187 }
188
190 return fixedRate_;
191 }
192
194 return fixedDayCount_;
195 }
196
197 inline const std::vector<Real>& FixedVsFloatingSwap::floatingNominals() const {
198 return floatingNominals_;
199 }
200
202 return floatingSchedule_;
203 }
204
205 inline const ext::shared_ptr<IborIndex>& FixedVsFloatingSwap::iborIndex() const {
206 return iborIndex_;
207 }
208
210 return spread_;
211 }
212
214 return floatingDayCount_;
215 }
216
218 return paymentConvention_;
219 }
220
221 inline const Leg& FixedVsFloatingSwap::fixedLeg() const {
222 return legs_[0];
223 }
224
225 inline const Leg& FixedVsFloatingSwap::floatingLeg() const {
226 return legs_[1];
227 }
228
229}
230
231#endif
calendar class
Definition: calendar.hpp:61
day counter class
Definition: daycounter.hpp:44
Arguments for simple swap calculation
Results from simple swap calculation
const DayCounter & fixedDayCount() const
const std::vector< Real > & fixedNominals() const
BusinessDayConvention paymentConvention() const
const Schedule & fixedSchedule() const
const Schedule & floatingSchedule() const
virtual void setupFloatingArguments(arguments *args) const =0
ext::shared_ptr< IborIndex > iborIndex_
const ext::shared_ptr< IborIndex > & iborIndex() const
const std::vector< Real > & nominals() const
const std::vector< Real > & floatingNominals() const
const DayCounter & floatingDayCount() const
void setupArguments(PricingEngine::arguments *args) const override
BusinessDayConvention paymentConvention_
void fetchResults(const PricingEngine::results *) const override
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
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
QL_INTEGER Integer
integer number
Definition: types.hpp:35
Real Spread
spreads on interest rates
Definition: types.hpp:74
Real Rate
interest rates
Definition: types.hpp:70
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.