QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
nonstandardswap.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, 2016 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 nonstandardswap.hpp
21 \brief vanilla swap but possibly with period dependent nominal and strike
22*/
23
24#ifndef quantlib_nonstandard_swap_hpp
25#define quantlib_nonstandard_swap_hpp
26
30#include <ql/time/schedule.hpp>
31#include <ql/optional.hpp>
32
33namespace QuantLib {
34
35 class IborIndex;
36 class SwapIndex;
37
38 //! nonstandard swap
39
40 class NonstandardSwap : public Swap {
41 public:
42 class arguments;
43 class results;
44 class engine;
45 explicit NonstandardSwap(const FixedVsFloatingSwap &fromVanilla);
47 std::vector<Real> fixedNominal,
48 const std::vector<Real>& floatingNominal,
50 std::vector<Real> fixedRate,
53 ext::shared_ptr<IborIndex> iborIndex,
57 bool intermediateCapitalExchange = false,
58 bool finalCapitalExchange = false,
59 ext::optional<BusinessDayConvention> paymentConvention = ext::nullopt);
61 std::vector<Real> fixedNominal,
62 std::vector<Real> floatingNominal,
64 std::vector<Real> fixedRate,
67 ext::shared_ptr<IborIndex> iborIndex,
68 std::vector<Real> gearing,
69 std::vector<Spread> spread,
71 bool intermediateCapitalExchange = false,
72 bool finalCapitalExchange = false,
73 ext::optional<BusinessDayConvention> paymentConvention = ext::nullopt);
74 //! \name Inspectors
75 //@{
76 Swap::Type type() const;
77 const std::vector<Real> &fixedNominal() const;
78 const std::vector<Real> &floatingNominal() const;
79
80 const Schedule &fixedSchedule() const;
81 const std::vector<Real> &fixedRate() const;
82 const DayCounter &fixedDayCount() const;
83
84 const Schedule &floatingSchedule() const;
85 const ext::shared_ptr<IborIndex> &iborIndex() const;
86 Spread spread() const;
87 Real gearing() const;
88 const std::vector<Spread>& spreads() const;
89 const std::vector<Real>& gearings() const;
90 const DayCounter &floatingDayCount() const;
91
93
94 const Leg &fixedLeg() const;
95 const Leg &floatingLeg() const;
96 //@}
97
98 //! \name Results
99 //@{
100 //@}
101 // other
102 void setupArguments(PricingEngine::arguments* args) const override;
103 void fetchResults(const PricingEngine::results*) const override;
104
105 private:
106 void init();
107 void setupExpired() const override;
109 std::vector<Real> fixedNominal_, floatingNominal_;
111 std::vector<Real> fixedRate_;
114 ext::shared_ptr<IborIndex> iborIndex_;
115 std::vector<Spread> spread_;
116 std::vector<Real> gearing_;
122 // results
123 };
124
125 //! %Arguments for nonstandard swap calculation
127 public:
128 arguments() = default;
130 std::vector<Real> fixedNominal, floatingNominal;
131
132 std::vector<Date> fixedResetDates;
133 std::vector<Date> fixedPayDates;
134 std::vector<Time> floatingAccrualTimes;
135 std::vector<Date> floatingResetDates;
136 std::vector<Date> floatingFixingDates;
137 std::vector<Date> floatingPayDates;
138
139 std::vector<Real> fixedCoupons;
140 std::vector<Real> fixedRate;
141 std::vector<Spread> floatingSpreads;
142 std::vector<Real> floatingGearings;
143 std::vector<Real> floatingCoupons;
144
145 ext::shared_ptr<IborIndex> iborIndex;
146
147 std::vector<bool> fixedIsRedemptionFlow;
148 std::vector<bool> floatingIsRedemptionFlow;
149
150 void validate() const override;
151 };
152
153 //! %Results from nonstandard swap calculation
155 public:
156 void reset() override;
157 };
158
160 : public GenericEngine<NonstandardSwap::arguments,
161 NonstandardSwap::results> {};
162
163 // inline definitions
164
165 inline Swap::Type NonstandardSwap::type() const { return type_; }
166
167 inline const std::vector<Real> &NonstandardSwap::fixedNominal() const {
168 return fixedNominal_;
169 }
170
171 inline const std::vector<Real> &NonstandardSwap::floatingNominal() const {
172 return floatingNominal_;
173 }
174
176 return fixedSchedule_;
177 }
178
179 inline const std::vector<Real> &NonstandardSwap::fixedRate() const {
180 return fixedRate_;
181 }
182
184 return fixedDayCount_;
185 }
186
188 return floatingSchedule_;
189 }
190
191 inline const ext::shared_ptr<IborIndex> &
193 return iborIndex_;
194 }
195
198 "spread is a vector, use spreads inspector instead");
199 return spread_.front();
200 }
201
204 "gearing is a vector, use gearings inspector instead");
205 return gearing_.front();
206 }
207
208 inline const std::vector<Spread> &NonstandardSwap::spreads() const {
209 return spread_;
210 }
211
212 inline const std::vector<Real> &NonstandardSwap::gearings() const {
213 return gearing_;
214 }
215
217 return floatingDayCount_;
218 }
219
221 return paymentConvention_;
222 }
223
224 inline const Leg &NonstandardSwap::fixedLeg() const { return legs_[0]; }
225
226 inline const Leg &NonstandardSwap::floatingLeg() const { return legs_[1]; }
227}
228
229#endif
day counter class
Definition: daycounter.hpp:44
template base class for option pricing engines
Arguments for nonstandard swap calculation
ext::shared_ptr< IborIndex > iborIndex
Results from nonstandard swap calculation
std::vector< Real > gearing_
const std::vector< Real > & fixedNominal() const
std::vector< Real > fixedRate_
const DayCounter & fixedDayCount() const
BusinessDayConvention paymentConvention() const
std::vector< Real > fixedNominal_
const Schedule & fixedSchedule() const
const Leg & floatingLeg() const
std::vector< Real > floatingNominal_
const Schedule & floatingSchedule() const
ext::shared_ptr< IborIndex > iborIndex_
const std::vector< Real > & fixedRate() const
const std::vector< Real > & gearings() const
std::vector< Spread > spread_
const ext::shared_ptr< IborIndex > & iborIndex() const
const std::vector< Spread > & spreads() const
const DayCounter & floatingDayCount() const
void setupArguments(PricingEngine::arguments *args) const override
BusinessDayConvention paymentConvention_
const Leg & fixedLeg() const
void setupExpired() const override
void fetchResults(const PricingEngine::results *) const override
const std::vector< Real > & floatingNominal() const
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
Fixed-rate vs floating-rate swap.
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
Real Spread
spreads on interest rates
Definition: types.hpp:74
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.