QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
overnightindexedswap.cpp
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) 2009 Roland Lichters
5 Copyright (C) 2009 Ferdinando Ametrano
6 Copyright (C) 2017 Joseph Jeisman
7 Copyright (C) 2017 Fabrice Lecuyer
8
9 This file is part of QuantLib, a free-software/open-source library
10 for financial quantitative analysts and developers - http://quantlib.org/
11
12 QuantLib is free software: you can redistribute it and/or modify it
13 under the terms of the QuantLib license. You should have received a
14 copy of the license along with this program; if not, please email
15 <quantlib-dev@lists.sf.net>. The license is also available online at
16 <http://quantlib.org/license.shtml>.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the license for more details.
21*/
22
26#include <utility>
27
28namespace QuantLib {
29
31 Real nominal,
32 const Schedule& schedule,
33 Rate fixedRate,
34 DayCounter fixedDC,
35 const ext::shared_ptr<OvernightIndex>& overnightIndex,
36 Spread spread,
37 Integer paymentLag,
38 BusinessDayConvention paymentAdjustment,
39 const Calendar& paymentCalendar,
40 bool telescopicValueDates,
41 RateAveraging::Type averagingMethod,
42 Natural lookbackDays,
43 Natural lockoutDays,
44 bool applyObservationShift)
46 std::vector<Real>(1, nominal),
47 schedule,
48 fixedRate,
49 std::move(fixedDC),
50 overnightIndex,
51 spread,
52 paymentLag,
53 paymentAdjustment,
54 paymentCalendar,
55 telescopicValueDates,
56 averagingMethod,
57 lookbackDays,
58 lockoutDays,
59 applyObservationShift) {}
60
62 const std::vector<Real>& nominals,
63 const Schedule& schedule,
64 Rate fixedRate,
65 DayCounter fixedDC,
66 const ext::shared_ptr<OvernightIndex>& overnightIndex,
67 Spread spread,
68 Integer paymentLag,
69 BusinessDayConvention paymentAdjustment,
70 const Calendar& paymentCalendar,
71 bool telescopicValueDates,
72 RateAveraging::Type averagingMethod,
73 Natural lookbackDays,
74 Natural lockoutDays,
75 bool applyObservationShift)
77 nominals,
78 schedule,
79 fixedRate,
80 std::move(fixedDC),
81 nominals,
82 schedule,
83 overnightIndex,
84 spread,
85 paymentLag,
86 paymentAdjustment,
87 paymentCalendar,
88 telescopicValueDates,
89 averagingMethod,
90 lookbackDays,
91 lockoutDays,
92 applyObservationShift) {}
93
95 Real nominal,
96 Schedule fixedSchedule,
97 Rate fixedRate,
98 DayCounter fixedDC,
99 Schedule overnightSchedule,
100 const ext::shared_ptr<OvernightIndex>& overnightIndex,
101 Spread spread,
102 Integer paymentLag,
103 BusinessDayConvention paymentAdjustment,
104 const Calendar& paymentCalendar,
105 bool telescopicValueDates,
106 RateAveraging::Type averagingMethod,
107 Natural lookbackDays,
108 Natural lockoutDays,
109 bool applyObservationShift)
111 std::vector<Real>(1, nominal),
112 std::move(fixedSchedule),
113 fixedRate,
114 std::move(fixedDC),
115 std::vector<Real>(1, nominal),
116 std::move(overnightSchedule),
117 overnightIndex,
118 spread,
119 paymentLag,
120 paymentAdjustment,
121 paymentCalendar,
122 telescopicValueDates,
123 averagingMethod,
124 lookbackDays,
125 lockoutDays,
126 applyObservationShift) {}
127
129 std::vector<Real> fixedNominals,
130 Schedule fixedSchedule,
131 Rate fixedRate,
132 DayCounter fixedDC,
133 const std::vector<Real>& overnightNominals,
134 Schedule overnightSchedule,
135 const ext::shared_ptr<OvernightIndex>& overnightIndex,
136 Spread spread,
137 Integer paymentLag,
138 BusinessDayConvention paymentAdjustment,
139 const Calendar& paymentCalendar,
140 bool telescopicValueDates,
141 RateAveraging::Type averagingMethod,
142 Natural lookbackDays,
143 Natural lockoutDays,
144 bool applyObservationShift)
145 : FixedVsFloatingSwap(type, std::move(fixedNominals), std::move(fixedSchedule), fixedRate, std::move(fixedDC),
146 overnightNominals, std::move(overnightSchedule), overnightIndex,
147 spread, DayCounter(), ext::nullopt, paymentLag, paymentCalendar),
148 overnightIndex_(overnightIndex), averagingMethod_(averagingMethod),
149 lookbackDays_(lookbackDays), lockoutDays_(lockoutDays),
150 applyObservationShift_(applyObservationShift) {
151 legs_[1] =
155 .withTelescopicValueDates(telescopicValueDates)
156 .withPaymentLag(paymentLag)
157 .withPaymentAdjustment(paymentAdjustment)
158 .withPaymentCalendar(paymentCalendar.empty() ?
159 floatingSchedule().calendar() :
160 paymentCalendar)
165 for (const auto& c : legs_[1])
166 registerWith(c);
167 }
168
170 const Leg& floatingCoupons = floatingLeg();
171 Size n = floatingCoupons.size();
172
173 args->floatingResetDates = args->floatingPayDates = args->floatingFixingDates = std::vector<Date>(n);
174 args->floatingAccrualTimes = std::vector<Time>(n);
175 args->floatingSpreads = std::vector<Spread>(n);
176 args->floatingCoupons = args->floatingNominals = std::vector<Real>(n);
177
178 for (Size i=0; i<n; ++i) {
179 auto coupon = ext::dynamic_pointer_cast<OvernightIndexedCoupon>(floatingCoupons[i]);
180
181 args->floatingResetDates[i] = coupon->accrualStartDate();
182 args->floatingPayDates[i] = coupon->date();
183 args->floatingNominals[i] = coupon->nominal();
184
185 args->floatingFixingDates[i] = coupon->fixingDate();
186 args->floatingAccrualTimes[i] = coupon->accrualPeriod();
187 args->floatingSpreads[i] = coupon->spread();
188 try {
189 args->floatingCoupons[i] = coupon->amount();
190 } catch (Error&) {
191 args->floatingCoupons[i] = Null<Real>();
192 }
193 }
194 }
195
196}
calendar class
Definition: calendar.hpp:61
bool empty() const
Returns whether or not the calendar is initialized.
Definition: calendar.hpp:208
day counter class
Definition: daycounter.hpp:44
Base error class.
Definition: errors.hpp:39
Arguments for simple swap calculation
const Schedule & floatingSchedule() const
template class providing a null value for a given type.
Definition: null.hpp:59
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:226
Overnight indexed swap: fix vs compounded overnight rate.
ext::shared_ptr< OvernightIndex > overnightIndex_
void setupFloatingArguments(arguments *args) const override
const std::vector< Real > & overnightNominals() const
OvernightIndexedSwap(Type type, Real nominal, const Schedule &schedule, Rate fixedRate, DayCounter fixedDC, const ext::shared_ptr< OvernightIndex > &overnightIndex, Spread spread=0.0, Integer paymentLag=0, BusinessDayConvention paymentAdjustment=Following, const Calendar &paymentCalendar=Calendar(), bool telescopicValueDates=false, RateAveraging::Type averagingMethod=RateAveraging::Compound, Natural lookbackDays=Null< Natural >(), Natural lockoutDays=0, bool applyObservationShift=false)
helper class building a sequence of overnight coupons
OvernightLeg & withObservationShift(bool applyObservationShift=true)
OvernightLeg & withPaymentCalendar(const Calendar &)
OvernightLeg & withTelescopicValueDates(bool telescopicValueDates)
OvernightLeg & withPaymentAdjustment(BusinessDayConvention)
OvernightLeg & withNotionals(Real notional)
OvernightLeg & withAveragingMethod(RateAveraging::Type averagingMethod)
OvernightLeg & withLockoutDays(Natural lockoutDays)
OvernightLeg & withSpreads(Spread spread)
OvernightLeg & withPaymentLag(Integer lag)
OvernightLeg & withLookbackDays(Natural lookbackDays)
Payment schedule.
Definition: schedule.hpp:40
std::vector< Leg > legs_
Definition: swap.hpp:133
Coupon paying a fixed annual rate.
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
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
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:37
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78
STL namespace.
coupon paying the compounded daily overnight rate
Overnight index swap paying compounded overnight vs. fixed.