Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
iborindexfixingoverride.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2023 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/iborindexfixingoverride.hpp
20 \brief ibor index wrapper with fixings
21 \ingroup indexes
22*/
23
24#pragma once
25
26#include <ql/indexes/iborindex.hpp>
27
28namespace QuantExt {
29
30//! wrapper for ibor index wit individiual trade level fixings
31class IborIndexWithFixingOverride : public QuantLib::IborIndex {
32public:
33 IborIndexWithFixingOverride(const QuantLib::ext::shared_ptr<QuantLib::IborIndex>& index,
34 const std::map<QuantLib::Date, double>& fixingOverrides)
35 : IborIndexWithFixingOverride(index->familyName(), index->tenor(), index->fixingDays(), index->currency(),
36 index->fixingCalendar(), index->businessDayConvention(), index->endOfMonth(),
37 index->dayCounter(), index->forwardingTermStructure(), fixingOverrides) {}
38
39 IborIndexWithFixingOverride(const std::string& familyName, const QuantLib::Period& tenor,
40 QuantLib::Natural settlementDays, const QuantLib::Currency& currency,
41 const QuantLib::Calendar& fixingCalendar, QuantLib::BusinessDayConvention convention,
42 bool endOfMonth, const QuantLib::DayCounter& dayCounter,
43 QuantLib::Handle<QuantLib::YieldTermStructure> h,
44 const std::map<QuantLib::Date, double>& fixingOverrides)
45 : QuantLib::IborIndex(familyName, tenor, settlementDays, currency, fixingCalendar, convention, endOfMonth,
46 dayCounter, h),
47 fixingOverrides_(fixingOverrides) {}
48 //! \name InterestRateIndex interface
49 //@{
50
51 QuantLib::ext::shared_ptr<QuantLib::IborIndex>
52 clone(const QuantLib::Handle<QuantLib::YieldTermStructure>& forwarding) const override {
53 return ext::make_shared<IborIndexWithFixingOverride>(familyName(), tenor(), fixingDays(), currency(),
54 fixingCalendar(), businessDayConvention(), endOfMonth(),
55 dayCounter(), forwarding, fixingOverrides_);
56 }
57 // @}
58protected:
59 QuantLib::Rate pastFixing(const QuantLib::Date& fixingDate) const override {
60 auto histFixing = fixingOverrides_.find(fixingDate);
61 if (histFixing != fixingOverrides_.end()) {
62 return histFixing->second;
63 } else {
64 return QuantLib::IborIndex::pastFixing(fixingDate);
65 }
66 }
67
68private:
69 std::map<QuantLib::Date, double> fixingOverrides_;
70};
71
72class OvernightIndexWithFixingOverride : public QuantLib::OvernightIndex {
73public:
74 OvernightIndexWithFixingOverride(const QuantLib::ext::shared_ptr<QuantLib::OvernightIndex>& index,
75 const std::map<QuantLib::Date, double>& fixingOverrides)
76 : OvernightIndexWithFixingOverride(index->familyName(), index->fixingDays(), index->currency(),
77 index->fixingCalendar(), index->dayCounter(),
78 index->forwardingTermStructure(), fixingOverrides) {}
79
80 OvernightIndexWithFixingOverride(const std::string& familyName, QuantLib::Natural settlementDays,
81 const QuantLib::Currency& currency, const QuantLib::Calendar& fixingCalendar,
82 const QuantLib::DayCounter& dayCounter,
83 const QuantLib::Handle<QuantLib::YieldTermStructure>& h,
84 const std::map<QuantLib::Date, double>& fixingOverrides)
85 : QuantLib::OvernightIndex(familyName, settlementDays, currency, fixingCalendar, dayCounter, h),
86 fixingOverrides_(fixingOverrides) {}
87
88 QuantLib::ext::shared_ptr<QuantLib::IborIndex>
89 clone(const QuantLib::Handle<QuantLib::YieldTermStructure>& forwarding) const override {
90 return ext::make_shared<OvernightIndexWithFixingOverride>(
91 familyName(), fixingDays(), currency(), fixingCalendar(), dayCounter(), forwarding, fixingOverrides_);
92 }
93
94protected:
95 QuantLib::Rate pastFixing(const QuantLib::Date& fixingDate) const override {
96 auto histFixing = fixingOverrides_.find(fixingDate);
97 if (histFixing != fixingOverrides_.end()) {
98 return histFixing->second;
99 } else {
100 return QuantLib::IborIndex::pastFixing(fixingDate);
101 }
102 }
103
104private:
105 std::map<QuantLib::Date, double> fixingOverrides_;
106};
107} // namespace QuantExt
wrapper for ibor index wit individiual trade level fixings
QuantLib::ext::shared_ptr< QuantLib::IborIndex > clone(const QuantLib::Handle< QuantLib::YieldTermStructure > &forwarding) const override
std::map< QuantLib::Date, double > fixingOverrides_
IborIndexWithFixingOverride(const QuantLib::ext::shared_ptr< QuantLib::IborIndex > &index, const std::map< QuantLib::Date, double > &fixingOverrides)
IborIndexWithFixingOverride(const std::string &familyName, const QuantLib::Period &tenor, QuantLib::Natural settlementDays, const QuantLib::Currency &currency, const QuantLib::Calendar &fixingCalendar, QuantLib::BusinessDayConvention convention, bool endOfMonth, const QuantLib::DayCounter &dayCounter, QuantLib::Handle< QuantLib::YieldTermStructure > h, const std::map< QuantLib::Date, double > &fixingOverrides)
QuantLib::Rate pastFixing(const QuantLib::Date &fixingDate) const override
QuantLib::ext::shared_ptr< QuantLib::IborIndex > clone(const QuantLib::Handle< QuantLib::YieldTermStructure > &forwarding) const override
OvernightIndexWithFixingOverride(const std::string &familyName, QuantLib::Natural settlementDays, const QuantLib::Currency &currency, const QuantLib::Calendar &fixingCalendar, const QuantLib::DayCounter &dayCounter, const QuantLib::Handle< QuantLib::YieldTermStructure > &h, const std::map< QuantLib::Date, double > &fixingOverrides)
OvernightIndexWithFixingOverride(const QuantLib::ext::shared_ptr< QuantLib::OvernightIndex > &index, const std::map< QuantLib::Date, double > &fixingOverrides)
std::map< QuantLib::Date, double > fixingOverrides_
QuantLib::Rate pastFixing(const QuantLib::Date &fixingDate) const override