QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
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)
43 std::vector<Real>(1, nominal),
44 schedule,
45 fixedRate,
46 std::move(fixedDC),
47 overnightIndex,
48 spread,
49 paymentLag,
50 paymentAdjustment,
51 paymentCalendar,
52 telescopicValueDates,
53 averagingMethod) {}
54
56 const std::vector<Real>& nominals,
57 const Schedule& schedule,
58 Rate fixedRate,
59 DayCounter fixedDC,
60 const ext::shared_ptr<OvernightIndex>& overnightIndex,
61 Spread spread,
62 Integer paymentLag,
63 BusinessDayConvention paymentAdjustment,
64 const Calendar& paymentCalendar,
65 bool telescopicValueDates,
66 RateAveraging::Type averagingMethod)
68 nominals,
69 schedule,
70 fixedRate,
71 std::move(fixedDC),
72 nominals,
73 schedule,
74 overnightIndex,
75 spread,
76 paymentLag,
77 paymentAdjustment,
78 paymentCalendar,
79 telescopicValueDates,
80 averagingMethod) {}
81
83 Real nominal,
84 Schedule fixedSchedule,
85 Rate fixedRate,
86 DayCounter fixedDC,
87 Schedule overnightSchedule,
88 const ext::shared_ptr<OvernightIndex>& overnightIndex,
89 Spread spread,
90 Integer paymentLag,
91 BusinessDayConvention paymentAdjustment,
92 const Calendar& paymentCalendar,
93 bool telescopicValueDates,
94 RateAveraging::Type averagingMethod)
96 std::vector<Real>(1, nominal),
97 std::move(fixedSchedule),
98 fixedRate,
99 std::move(fixedDC),
100 std::vector<Real>(1, nominal),
101 std::move(overnightSchedule),
102 overnightIndex,
103 spread,
104 paymentLag,
105 paymentAdjustment,
106 paymentCalendar,
107 telescopicValueDates,
108 averagingMethod) {}
109
111 std::vector<Real> fixedNominals,
112 Schedule fixedSchedule,
113 Rate fixedRate,
114 DayCounter fixedDC,
115 const std::vector<Real>& overnightNominals,
116 Schedule overnightSchedule,
117 const ext::shared_ptr<OvernightIndex>& overnightIndex,
118 Spread spread,
119 Integer paymentLag,
120 BusinessDayConvention paymentAdjustment,
121 const Calendar& paymentCalendar,
122 bool telescopicValueDates,
123 RateAveraging::Type averagingMethod)
124 : FixedVsFloatingSwap(type, std::move(fixedNominals), std::move(fixedSchedule), fixedRate, std::move(fixedDC),
125 overnightNominals, std::move(overnightSchedule), overnightIndex,
126 spread, DayCounter(), ext::nullopt, paymentLag, paymentCalendar),
127 overnightIndex_(overnightIndex), averagingMethod_(averagingMethod) {
128 legs_[1] =
132 .withTelescopicValueDates(telescopicValueDates)
133 .withPaymentLag(paymentLag)
134 .withPaymentAdjustment(paymentAdjustment)
135 .withPaymentCalendar(paymentCalendar.empty() ?
136 floatingSchedule().calendar() :
137 paymentCalendar)
139 for (const auto& c : legs_[1])
140 registerWith(c);
141 }
142
144 const Leg& floatingCoupons = floatingLeg();
145 Size n = floatingCoupons.size();
146
147 args->floatingResetDates = args->floatingPayDates = args->floatingFixingDates = std::vector<Date>(n);
148 args->floatingAccrualTimes = std::vector<Time>(n);
149 args->floatingSpreads = std::vector<Spread>(n);
150 args->floatingCoupons = args->floatingNominals = std::vector<Real>(n);
151
152 for (Size i=0; i<n; ++i) {
153 auto coupon = ext::dynamic_pointer_cast<OvernightIndexedCoupon>(floatingCoupons[i]);
154
155 args->floatingResetDates[i] = coupon->accrualStartDate();
156 args->floatingPayDates[i] = coupon->date();
157 args->floatingNominals[i] = coupon->nominal();
158
159 args->floatingFixingDates[i] = coupon->fixingDate();
160 args->floatingAccrualTimes[i] = coupon->accrualPeriod();
161 args->floatingSpreads[i] = coupon->spread();
162 try {
163 args->floatingCoupons[i] = coupon->amount();
164 } catch (Error&) {
165 args->floatingCoupons[i] = Null<Real>();
166 }
167 }
168 }
169
170}
calendar class
Definition: calendar.hpp:61
bool empty() const
Returns whether or not the calendar is initialized.
Definition: calendar.hpp:202
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:76
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
Overnight indexed swap: fix vs compounded overnight rate.
ext::shared_ptr< OvernightIndex > overnightIndex_
void setupFloatingArguments(arguments *args) const override
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)
const std::vector< Real > & overnightNominals() const
helper class building a sequence of overnight coupons
OvernightLeg & withPaymentCalendar(const Calendar &)
OvernightLeg & withTelescopicValueDates(bool telescopicValueDates)
OvernightLeg & withPaymentAdjustment(BusinessDayConvention)
OvernightLeg & withNotionals(Real notional)
OvernightLeg & withAveragingMethod(RateAveraging::Type averagingMethod)
OvernightLeg & withSpreads(Spread spread)
OvernightLeg & withPaymentLag(Integer lag)
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
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:35
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.