Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
fallbackovernightindex.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
30FallbackOvernightIndex::FallbackOvernightIndex(const QuantLib::ext::shared_ptr<OvernightIndex> originalIndex,
31 const QuantLib::ext::shared_ptr<OvernightIndex> rfrIndex, const Real spread,
32 const Date& switchDate, const bool useRfrCurve)
33 : FallbackOvernightIndex(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<OvernightFallbackCurve>(
39 originalIndex, rfrIndex, spread, switchDate))
40 : originalIndex->forwardingTermStructure()) {}
41
42FallbackOvernightIndex::FallbackOvernightIndex(const QuantLib::ext::shared_ptr<OvernightIndex> originalIndex,
43 const QuantLib::ext::shared_ptr<OvernightIndex> rfrIndex, const Real spread,
44 const Date& switchDate, const Handle<YieldTermStructure>& forwardingCurve)
45 : OvernightIndex(originalIndex->familyName(), originalIndex->fixingDays(),
46 originalIndex->currency(), originalIndex->fixingCalendar(),
47 originalIndex->dayCounter(), forwardingCurve),
48 originalIndex_(originalIndex), rfrIndex_(rfrIndex), spread_(spread), switchDate_(switchDate),
49 useRfrCurve_(false) {
50 registerWith(originalIndex);
51 registerWith(rfrIndex);
52 registerWith(forwardingCurve);
53}
54
55void FallbackOvernightIndex::addFixing(const Date& fixingDate, Real fixing, bool forceOverwrite) {
56 if (fixingDate < switchDate_) {
57 IborIndex::addFixing(fixingDate, fixing, forceOverwrite);
58 } else {
59 QL_FAIL("Can not add fixing value "
60 << fixing << " for fixing date " << fixingDate << " to fall back ibor index '" << name()
61 << "' fixing history, since fixing date is after switch date (" << switchDate_ << ")");
62 }
63}
64
65Real FallbackOvernightIndex::fixing(const Date& fixingDate, bool forecastTodaysFixing) const {
66 Date today = Settings::instance().evaluationDate();
67 if (today < switchDate_ || fixingDate < switchDate_) {
68 return originalIndex_->fixing(fixingDate, forecastTodaysFixing);
69 }
70 if (fixingDate > today) {
71 return IborIndex::forecastFixing(fixingDate);
72 } else {
73 return rfrIndex_->fixing(fixingDate) + spread_;
74 }
75}
76
77Rate FallbackOvernightIndex::pastFixing(const Date& fixingDate) const {
78 Date today = Settings::instance().evaluationDate();
79 if (today < switchDate_) {
80 return originalIndex_->pastFixing(fixingDate);
81 }
82 return fixing(fixingDate);
83}
84
85QuantLib::ext::shared_ptr<IborIndex> FallbackOvernightIndex::clone(const Handle<YieldTermStructure>& forwarding) const {
86 return QuantLib::ext::make_shared<FallbackOvernightIndex>(originalIndex_, rfrIndex_, spread_, switchDate_, forwarding);
87}
88
89Rate FallbackOvernightIndex::forecastFixing(const Date& valueDate, const Date& endDate, Time t) const {
90 Date today = Settings::instance().evaluationDate();
91 Handle<YieldTermStructure> curve =
92 today < switchDate_ ? originalIndex_->forwardingTermStructure() : forwardingTermStructure();
93 QL_REQUIRE(!curve.empty(), "FallbackOvernightIndex: null term structure set for " << name() << ", today=" << today
94 << ", switchDate=" << switchDate_);
95 DiscountFactor disc1 = curve->discount(valueDate);
96 DiscountFactor disc2 = curve->discount(endDate);
97 return (disc1 / disc2 - 1.0) / t;
98}
99
100QuantLib::ext::shared_ptr<OvernightIndex> FallbackOvernightIndex::originalIndex() const { return originalIndex_; }
101
102QuantLib::ext::shared_ptr<OvernightIndex> FallbackOvernightIndex::rfrIndex() const { return rfrIndex_; }
103
105
106const Date& FallbackOvernightIndex::switchDate() const { return switchDate_; }
107
109
110} // namespace QuantExt
FallbackOvernightIndex(const QuantLib::ext::shared_ptr< OvernightIndex > originalIndex, const QuantLib::ext::shared_ptr< OvernightIndex > rfrIndex, const Real spread, const Date &switchDate, const bool useRfrCurve)
Rate forecastFixing(const Date &valueDate, const Date &endDate, Time t) const override
QuantLib::ext::shared_ptr< OvernightIndex > originalIndex() const
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
QuantLib::ext::shared_ptr< OvernightIndex > rfrIndex() const
QuantLib::ext::shared_ptr< OvernightIndex > originalIndex_
Real fixing(const Date &fixingDate, bool forecastTodaysFixing=false) const override
wrapper class for overnight index managing the fallback rules
SimpleQuote & spread_