QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
overnightindexedswap.cpp
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
23#include <ql/cashflows/fixedratecoupon.hpp>
24#include <ql/cashflows/overnightindexedcoupon.hpp>
25#include <ql/instruments/overnightindexedswap.hpp>
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 Natural 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 Natural 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 const Schedule& fixedSchedule,
85 Rate fixedRate,
86 DayCounter fixedDC,
87 const Schedule& overnightSchedule,
88 const ext::shared_ptr<OvernightIndex>& overnightIndex,
89 Spread spread,
90 Natural paymentLag,
91 BusinessDayConvention paymentAdjustment,
92 const Calendar& paymentCalendar,
93 bool telescopicValueDates,
94 RateAveraging::Type averagingMethod)
96 std::vector<Real>(1, nominal),
97 fixedSchedule,
98 fixedRate,
99 std::move(fixedDC),
100 std::vector<Real>(1, nominal),
101 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 const Schedule& overnightSchedule,
117 const ext::shared_ptr<OvernightIndex>& overnightIndex,
118 Spread spread,
119 Natural 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, overnightSchedule, overnightIndex,
126 spread, DayCounter(), ext::nullopt, paymentLag, paymentCalendar),
127 overnightIndex_(overnightIndex), averagingMethod_(averagingMethod) {
128
129 legs_[1] =
133 .withTelescopicValueDates(telescopicValueDates)
134 .withPaymentLag(paymentLag)
135 .withPaymentAdjustment(paymentAdjustment)
136 .withPaymentCalendar(paymentCalendar.empty() ?
138 paymentCalendar)
140 }
141
143 const Leg& floatingCoupons = floatingLeg();
144 Size n = floatingCoupons.size();
145
146 args->floatingResetDates = args->floatingPayDates = args->floatingFixingDates = std::vector<Date>(n);
147 args->floatingAccrualTimes = std::vector<Time>(n);
148 args->floatingSpreads = std::vector<Spread>(n);
149 args->floatingCoupons = args->floatingNominals = std::vector<Real>(n);
150
151 for (Size i=0; i<n; ++i) {
152 auto coupon = ext::dynamic_pointer_cast<OvernightIndexedCoupon>(floatingCoupons[i]);
153
154 args->floatingResetDates[i] = coupon->accrualStartDate();
155 args->floatingPayDates[i] = coupon->date();
156 args->floatingNominals[i] = coupon->nominal();
157
158 args->floatingFixingDates[i] = coupon->fixingDate();
159 args->floatingAccrualTimes[i] = coupon->accrualPeriod();
160 args->floatingSpreads[i] = coupon->spread();
161 try {
162 args->floatingCoupons[i] = coupon->amount();
163 } catch (Error&) {
164 args->floatingCoupons[i] = Null<Real>();
165 }
166 }
167 }
168
169}
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
template class providing a null value for a given type.
Definition: null.hpp:76
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
const Schedule & overnightSchedule() const
OvernightIndexedSwap(Type type, Real nominal, const Schedule &schedule, Rate fixedRate, DayCounter fixedDC, const ext::shared_ptr< OvernightIndex > &overnightIndex, Spread spread=0.0, Natural paymentLag=0, BusinessDayConvention paymentAdjustment=Following, const Calendar &paymentCalendar=Calendar(), bool telescopicValueDates=false, RateAveraging::Type averagingMethod=RateAveraging::Compound)
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(Natural lag)
Payment schedule.
Definition: schedule.hpp:40
const Calendar & calendar() const
Definition: schedule.hpp:176
std::vector< Leg > legs_
Definition: swap.hpp:133
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
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.