195 {
196 ext::shared_ptr<OvernightIndex> index = ext::dynamic_pointer_cast<OvernightIndex>(
coupon_->index());
197
200
201 Size n = dt.size();
202 Size i = 0;
204 << ") must be less than number of fixings in period (" << n
205 << ")");
207
208 Real compoundFactor = 1.0, compoundFactorWithoutSpread = 1.0;
209
210
211 Date today = Settings::instance().evaluationDate();
212 while (i < n && fixingDates[std::min(i, nCutoff)] < today) {
213
214 Rate pastFixing = index->pastFixing(fixingDates[std::min(i, nCutoff)]);
215 QL_REQUIRE(pastFixing != Null<Real>(),
216 "Missing " << index->name() << " fixing for " << fixingDates[std::min(i, nCutoff)]);
218 compoundFactorWithoutSpread *= (1.0 + pastFixing * dt[i]);
219 pastFixing +=
coupon_->spread();
220 }
221 compoundFactor *= (1.0 + pastFixing * dt[i]);
222 ++i;
223 }
224
225
226 if (i < n && fixingDates[std::min(i, nCutoff)] == today) {
227
228 try {
229 Rate pastFixing = index->pastFixing(fixingDates[std::min(i, nCutoff)]);
230 if (pastFixing != Null<Real>()) {
232 compoundFactorWithoutSpread *= (1.0 + pastFixing * dt[i]);
233 pastFixing +=
coupon_->spread();
234 }
235 compoundFactor *= (1.0 + pastFixing * dt[i]);
236 ++i;
237 } else {
238 ;
239 }
240 } catch (Error&) {
241 ;
242 }
243 }
244
245
246
248 if (i < n) {
249 Handle<YieldTermStructure> curve = index->forwardingTermStructure();
250 QL_REQUIRE(!curve.empty(), "null term structure set to this instance of " << index->name());
251
252
253 DiscountFactor startDiscount = curve->discount(dates[i]);
254 DiscountFactor endDiscount = curve->discount(dates[std::max(nCutoff, i)]);
255
256
257 if (nCutoff < n) {
258
259 DiscountFactor discountCutoffDate = curve->discount(dates[nCutoff] + 1) / curve->discount(dates[nCutoff]);
260
261 endDiscount *= std::pow(discountCutoffDate, dates[n] - dates[nCutoff]);
262 }
263
264 compoundFactor *= startDiscount / endDiscount;
265
267 compoundFactorWithoutSpread *= startDiscount / endDiscount;
268
269
270 Real tau = index->dayCounter().yearFraction(dates[i], dates.back()) / (dates.back() - dates[i]);
271
272 compoundFactor *= std::pow(1.0 + tau *
coupon_->spread(),
static_cast<int>(dates.back() - dates[i]));
273 }
274 }
275
276 Rate tau = index->dayCounter().yearFraction(dates.front(), dates.back());
277 Rate rate = (compoundFactor - 1.0) / tau;
283 } else {
286 }
287}
Natural rateCutoff() const
rate cutoff
bool includeSpread() const
include spread in compounding?
const std::vector< Date > & valueDates() const
value dates for the rates to be compounded
const std::vector< Time > & dt() const
accrual (compounding) periods
const std::vector< Date > & fixingDates() const
fixing dates for the rates to be compounded
Real effectiveIndexFixing_