Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
fallbackiborindex.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file qle/indexes/fallbackiborindex.hpp
20 \brief wrapper class for ibor index managing the fallback rules
21 \ingroup indexes
22*/
23
25
27
28namespace QuantExt {
29
30FallbackIborIndex::FallbackIborIndex(const QuantLib::ext::shared_ptr<IborIndex> originalIndex,
31 const QuantLib::ext::shared_ptr<OvernightIndex> rfrIndex, const Real spread,
32 const Date& switchDate, const bool useRfrCurve)
33 : FallbackIborIndex(originalIndex,
34 useRfrCurve ? rfrIndex
35 : QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(
36 rfrIndex->clone(originalIndex->forwardingTermStructure())),
37 spread, switchDate,
38 useRfrCurve ? Handle<YieldTermStructure>(QuantLib::ext::make_shared<IborFallbackCurve>(
39 originalIndex, rfrIndex, spread, switchDate))
40 : originalIndex->forwardingTermStructure()) {}
41
42FallbackIborIndex::FallbackIborIndex(const QuantLib::ext::shared_ptr<IborIndex> originalIndex,
43 const QuantLib::ext::shared_ptr<OvernightIndex> rfrIndex, const Real spread,
44 const Date& switchDate, const Handle<YieldTermStructure>& forwardingCurve)
45 : IborIndex(originalIndex->familyName(), originalIndex->tenor(), originalIndex->fixingDays(),
46 originalIndex->currency(), originalIndex->fixingCalendar(), originalIndex->businessDayConvention(),
47 originalIndex->endOfMonth(), originalIndex->dayCounter(), forwardingCurve),
48 originalIndex_(originalIndex), rfrIndex_(rfrIndex), spread_(spread), switchDate_(switchDate) {
49 registerWith(originalIndex);
50 registerWith(rfrIndex);
51 registerWith(forwardingCurve);
52}
53
54void FallbackIborIndex::addFixing(const Date& fixingDate, Real fixing, bool forceOverwrite) {
55 if (fixingDate < switchDate_) {
56 IborIndex::addFixing(fixingDate, fixing, forceOverwrite);
57 } else {
58 QL_FAIL("Can not add fixing value "
59 << fixing << " for fixing date " << fixingDate << " to fall back ibor index '" << name()
60 << "' fixing history, since fixing date is after switch date (" << switchDate_ << ")");
61 }
62}
63
64QuantLib::ext::shared_ptr<OvernightIndexedCoupon> FallbackIborIndex::onCoupon(const Date& iborFixingDate,
65 const bool telescopicValueDates) const {
66 QL_REQUIRE(iborFixingDate >= switchDate_, "FallbackIborIndex: onCoupon for ibor fixing date "
67 << iborFixingDate << " requested, which is before switch date "
68 << switchDate_ << " for index '" << name() << "'");
69 Date valueDate = originalIndex_->valueDate(iborFixingDate);
70 Date maturityDate = originalIndex_->maturityDate(valueDate);
71 return QuantLib::ext::make_shared<OvernightIndexedCoupon>(maturityDate, 1.0, valueDate, maturityDate, rfrIndex_, 1.0, 0.0,
72 Date(), Date(), DayCounter(), telescopicValueDates, false,
73 2 * Days, 0, Null<Size>());
74}
75
76Real FallbackIborIndex::fixing(const Date& fixingDate, bool forecastTodaysFixing) const {
77 Date today = Settings::instance().evaluationDate();
78 if (today < switchDate_ || fixingDate < switchDate_) {
79 return originalIndex_->fixing(fixingDate, forecastTodaysFixing);
80 }
81 if (fixingDate > today) {
82 return IborIndex::forecastFixing(fixingDate);
83 } else {
84 if (QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(originalIndex_))
85 return rfrIndex_->fixing(fixingDate) + spread_;
86 else
87 return onCoupon(fixingDate, true)->rate() + spread_;
88 }
89}
90
91Rate FallbackIborIndex::pastFixing(const Date& fixingDate) const {
92 Date today = Settings::instance().evaluationDate();
93 if (today < switchDate_) {
94 return originalIndex_->pastFixing(fixingDate);
95 }
96 return fixing(fixingDate);
97}
98
99QuantLib::ext::shared_ptr<IborIndex> FallbackIborIndex::clone(const Handle<YieldTermStructure>& forwarding) const {
100 return QuantLib::ext::make_shared<FallbackIborIndex>(originalIndex_, rfrIndex_, spread_, switchDate_, forwarding);
101}
102
103Rate FallbackIborIndex::forecastFixing(const Date& valueDate, const Date& endDate, Time t) const {
104 Date today = Settings::instance().evaluationDate();
105 Handle<YieldTermStructure> curve =
106 today < switchDate_ ? originalIndex_->forwardingTermStructure() : forwardingTermStructure();
107 QL_REQUIRE(!curve.empty(), "FallbackIborIndex: null term structure set for " << name() << ", today=" << today
108 << ", switchDate=" << switchDate_);
109 DiscountFactor disc1 = curve->discount(valueDate);
110 DiscountFactor disc2 = curve->discount(endDate);
111 return (disc1 / disc2 - 1.0) / t;
112}
113
114QuantLib::ext::shared_ptr<IborIndex> FallbackIborIndex::originalIndex() const { return originalIndex_; }
115
116QuantLib::ext::shared_ptr<OvernightIndex> FallbackIborIndex::rfrIndex() const { return rfrIndex_; }
117
118Real FallbackIborIndex::spread() const { return spread_; }
119
120const Date& FallbackIborIndex::switchDate() const { return switchDate_; }
121
122} // namespace QuantExt
Rate forecastFixing(const Date &valueDate, const Date &endDate, Time t) const override
QuantLib::ext::shared_ptr< IborIndex > originalIndex_
QuantLib::ext::shared_ptr< OvernightIndex > rfrIndex_
Rate pastFixing(const Date &fixingDate) const override
QuantLib::ext::shared_ptr< IborIndex > clone(const Handle< YieldTermStructure > &forwarding) const override
void addFixing(const Date &fixingDate, Real fixing, bool forceOverwrite=false) override
FallbackIborIndex(const QuantLib::ext::shared_ptr< IborIndex > originalIndex, const QuantLib::ext::shared_ptr< OvernightIndex > rfrIndex, const Real spread, const Date &switchDate, const bool useRfrCurve)
QuantLib::ext::shared_ptr< OvernightIndexedCoupon > onCoupon(const Date &iborFixingDate, const bool telescopicValueDates=false) const
QuantLib::ext::shared_ptr< OvernightIndex > rfrIndex() const
const Date & switchDate() const
QuantLib::ext::shared_ptr< IborIndex > originalIndex() const
Real fixing(const Date &fixingDate, bool forecastTodaysFixing=false) const override
wrapper class for ibor index managing the fallback rules
projection curve for ibor fallback indices
SimpleQuote & spread_