QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
swapindex.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2006, 2009 Ferdinando Ametrano
3 Copyright (C) 2006, 2007, 2009 StatPro Italia srl
4
5 This file is part of QuantLib, a free-software/open-source library
6 for financial quantitative analysts and developers - http://quantlib.org/
7
8 QuantLib is free software: you can redistribute it and/or modify it
9 under the terms of the QuantLib license. You should have received a
10 copy of the license along with this program; if not, please email
11 <quantlib-dev@lists.sf.net>. The license is also available online at
12 <http://quantlib.org/license.shtml>.
13
14
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */
18
23#include <ql/time/schedule.hpp>
24#include <sstream>
25#include <utility>
26
27namespace QuantLib {
28
29 SwapIndex::SwapIndex(const std::string& familyName,
30 const Period& tenor,
31 Natural settlementDays,
32 const Currency& currency,
33 const Calendar& fixingCalendar,
34 const Period& fixedLegTenor,
35 BusinessDayConvention fixedLegConvention,
36 const DayCounter& fixedLegDayCounter,
37 ext::shared_ptr<IborIndex> iborIndex)
39 familyName, tenor, settlementDays, currency, fixingCalendar, fixedLegDayCounter),
40 tenor_(tenor), iborIndex_(std::move(iborIndex)), fixedLegTenor_(fixedLegTenor),
41 fixedLegConvention_(fixedLegConvention), exogenousDiscount_(false) {
43 }
44
45 SwapIndex::SwapIndex(const std::string& familyName,
46 const Period& tenor,
47 Natural settlementDays,
48 const Currency& currency,
49 const Calendar& fixingCalendar,
50 const Period& fixedLegTenor,
51 BusinessDayConvention fixedLegConvention,
52 const DayCounter& fixedLegDayCounter,
53 ext::shared_ptr<IborIndex> iborIndex,
56 familyName, tenor, settlementDays, currency, fixingCalendar, fixedLegDayCounter),
57 tenor_(tenor), iborIndex_(std::move(iborIndex)), fixedLegTenor_(fixedLegTenor),
58 fixedLegConvention_(fixedLegConvention), exogenousDiscount_(true),
59 discount_(std::move(discount)) {
62 }
63
65 return iborIndex_->forwardingTermStructure();
66 }
67
69 return discount_; // empty if not exogenous
70 }
71
72 Rate SwapIndex::forecastFixing(const Date& fixingDate) const {
73 return underlyingSwap(fixingDate)->fairRate();
74 }
75
76 ext::shared_ptr<VanillaSwap>
77 SwapIndex::underlyingSwap(const Date& fixingDate) const {
78
79 QL_REQUIRE(fixingDate!=Date(), "null fixing date");
80
81 // caching mechanism
83 Rate fixedRate = 0.0;
93 else
102 }
103 return lastSwap_;
104 }
105
106 Date SwapIndex::maturityDate(const Date& valueDate) const {
107 Date fixDate = fixingDate(valueDate);
108 return underlyingSwap(fixDate)->maturityDate();
109 }
110
111 ext::shared_ptr<SwapIndex>
113
115 return ext::make_shared<SwapIndex>(familyName(),
116 tenor(),
117 fixingDays(),
118 currency(),
122 dayCounter(),
123 iborIndex_->clone(forwarding),
124 discount_);
125 else
126 return ext::make_shared<SwapIndex>(familyName(),
127 tenor(),
128 fixingDays(),
129 currency(),
133 dayCounter(),
134 iborIndex_->clone(forwarding));
135 }
136
137 ext::shared_ptr<SwapIndex>
139 const Handle<YieldTermStructure>& discounting) const {
140 return ext::make_shared<SwapIndex>(familyName(),
141 tenor(),
142 fixingDays(),
143 currency(),
147 dayCounter(),
148 iborIndex_->clone(forwarding),
149 discounting);
150 }
151
152 ext::shared_ptr<SwapIndex>
153 SwapIndex::clone(const Period& tenor) const {
154
156 return ext::make_shared<SwapIndex>(familyName(),
157 tenor,
158 fixingDays(),
159 currency(),
163 dayCounter(),
164 iborIndex(),
166 else
167 return ext::make_shared<SwapIndex>(familyName(),
168 tenor,
169 fixingDays(),
170 currency(),
174 dayCounter(),
175 iborIndex());
176
177 }
178
180 const std::string& familyName,
181 const Period& tenor,
182 Natural settlementDays,
183 const Currency& currency,
184 const ext::shared_ptr<OvernightIndex>& overnightIndex,
185 bool telescopicValueDates,
186 RateAveraging::Type averagingMethod)
187 : SwapIndex(familyName,
188 tenor,
189 settlementDays,
190 currency,
191 overnightIndex->fixingCalendar(),
192 1 * Years,
194 overnightIndex->dayCounter(),
195 overnightIndex),
196 overnightIndex_(overnightIndex),
197 telescopicValueDates_(telescopicValueDates),
198 averagingMethod_(averagingMethod) {}
199
200
201 ext::shared_ptr<OvernightIndexedSwap>
203
204 QL_REQUIRE(fixingDate!=Date(), "null fixing date");
205
206 // caching mechanism
208 Rate fixedRate = 0.0;
215 }
216 return lastSwap_;
217 }
218
219}
calendar class
Definition: calendar.hpp:61
Currency specification
Definition: currency.hpp:36
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Shared handle to an observable.
Definition: handle.hpp:41
base class for interest rate indexes
const DayCounter & dayCounter() const
Calendar fixingCalendar() const override
returns the calendar defining valid fixing dates
const Currency & currency() const
virtual Date valueDate(const Date &fixingDate) const
Date fixingDate(const Date &valueDate) const
std::string familyName() const
helper class
Definition: makeois.hpp:39
MakeOIS & withFixedLegDayCount(const DayCounter &dc)
Definition: makeois.cpp:269
MakeOIS & withEffectiveDate(const Date &)
Definition: makeois.cpp:187
MakeOIS & withAveragingMethod(RateAveraging::Type averagingMethod)
Definition: makeois.cpp:329
MakeOIS & withTelescopicValueDates(bool telescopicValueDates)
Definition: makeois.cpp:324
MakeVanillaSwap & withEffectiveDate(const Date &)
MakeVanillaSwap & withFixedLegConvention(BusinessDayConvention bdc)
MakeVanillaSwap & withFixedLegTerminationDateConvention(BusinessDayConvention bdc)
MakeVanillaSwap & withFixedLegCalendar(const Calendar &cal)
MakeVanillaSwap & withDiscountingTermStructure(const Handle< YieldTermStructure > &discountCurve)
MakeVanillaSwap & withFixedLegDayCount(const DayCounter &dc)
MakeVanillaSwap & withFixedLegTenor(const Period &t)
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
ext::shared_ptr< OvernightIndex > overnightIndex_
Definition: swapindex.hpp:129
ext::shared_ptr< OvernightIndexedSwap > lastSwap_
Definition: swapindex.hpp:134
ext::shared_ptr< OvernightIndexedSwap > underlyingSwap(const Date &fixingDate) const
Definition: swapindex.cpp:202
RateAveraging::Type averagingMethod_
Definition: swapindex.hpp:131
OvernightIndexedSwapIndex(const std::string &familyName, const Period &tenor, Natural settlementDays, const Currency &currency, const ext::shared_ptr< OvernightIndex > &overnightIndex, bool telescopicValueDates=false, RateAveraging::Type averagingMethod=RateAveraging::Compound)
Definition: swapindex.cpp:179
base class for swap-rate indexes
Definition: swapindex.hpp:41
virtual ext::shared_ptr< SwapIndex > clone(const Handle< YieldTermStructure > &forwarding) const
returns a copy of itself linked to a different forwarding curve
Definition: swapindex.cpp:112
Handle< YieldTermStructure > discount_
Definition: swapindex.hpp:100
ext::shared_ptr< VanillaSwap > underlyingSwap(const Date &fixingDate) const
Definition: swapindex.cpp:77
Handle< YieldTermStructure > forwardingTermStructure() const
Definition: swapindex.cpp:64
BusinessDayConvention fixedLegConvention() const
Definition: swapindex.hpp:140
ext::shared_ptr< VanillaSwap > lastSwap_
Definition: swapindex.hpp:103
ext::shared_ptr< IborIndex > iborIndex_
Definition: swapindex.hpp:96
Date maturityDate(const Date &valueDate) const override
Definition: swapindex.cpp:106
BusinessDayConvention fixedLegConvention_
Definition: swapindex.hpp:98
ext::shared_ptr< IborIndex > iborIndex() const
Definition: swapindex.hpp:70
SwapIndex(const std::string &familyName, const Period &tenor, Natural settlementDays, const Currency &currency, const Calendar &fixingCalendar, const Period &fixedLegTenor, BusinessDayConvention fixedLegConvention, const DayCounter &fixedLegDayCounter, ext::shared_ptr< IborIndex > iborIndex)
Definition: swapindex.cpp:29
Period fixedLegTenor() const
Definition: swapindex.hpp:68
Handle< YieldTermStructure > discountingTermStructure() const
Definition: swapindex.cpp:68
Rate forecastFixing(const Date &fixingDate) const override
It can be overridden to implement particular conventions.
Definition: swapindex.cpp:72
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
BusinessDayConvention
Business Day conventions.
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Rate
interest rates
Definition: types.hpp:70
base class for Inter-Bank-Offered-Rate indexes
Helper class to instantiate overnight indexed swaps.
Helper class to instantiate standard market swaps.
Definition: any.hpp:35
STL namespace.
date schedule
swap-rate indexes